8/30/2019

Volumio : ติดตั้งใช้งาน Cronteb ใน Volumion V.2.5

Volumio : ติดตั้งใช้งาน Cronteb ใน Volumion V.2.5
ติดตั้ง
  1. apt-get update && apt-get install -y cron

ใช้งาน
crotab -e

https://forum.volumio.org/crontab-t4986.html

Volumio : Volumio button on off pi

Volumio : Volumio button on off pi
Code python :
https://porpramarn.blogspot.com/2019/08/raspberry-pi.html

Run แล้วจะ Error เนื่องจาก Volumio ยังไม่มี module RPI.GPIO
root@volumio:/home/volumio# python pishutdown.py
Traceback (most recent call last):
File "pishutdown.py", line 4, in <module>
import RPi.GPIO as GPIO
ImportError: No module named RPi.GPIO


ต้องติดตั้ง
https://forum.volumio.org/installing-rp ... t3544.html

ดู Version ด้วย เอา Version ล่าสุดมาลง หรือจะ Download .deb มาลงก็ได้
https://sourceforge.net/projects/raspbe ... an-wheezy/
ใช้ ดู Version ของ python ที่เครื่อง Volumio ด้วย
  1. phyton -version

ในตัวนี้ใช้
python-rpi.gpio_0.6.2~wheezy-1_armhf.deb

หรือ wget เอา
wget http://sourceforge.net/projects/raspberry-gpio-python/files/raspbian-wheezy/python-rpi.gpio_0.6.2~wheezy-1_armhf.deb

ติดตั้ง
  1. sudo dpkg -i python-rpi.gpio_0.6.2~wheezy-1_armhf.deb

root@volumio:/home/volumio# sudo dpkg -i python-rpi.gpio_0.6.2~wheezy-1_armhf.deb
Selecting previously unselected package python-rpi.gpio.
(Reading database ... 20535 files and directories currently installed.)
Preparing to unpack python-rpi.gpio_0.6.2~wheezy-1_armhf.deb ...
Unpacking python-rpi.gpio (0.6.2~wheezy-1) ...
Setting up python-rpi.gpio (0.6.2~wheezy-1) ...

Test Run คำสั่ง แล้วลอง กดปุ่ม
  1. python pishutdown.py

แล้วทำ Run เป็น Service ต่อ
https://porpramarn.blogspot.com/2019/08/raspberry-pi.html

ปุ่มเปิด/ปิด Raspberry Pi

ปุ่มเปิด/ปิด Raspberry Pi
1.ต่อ Switch แบบกดติดปล่อยดับที่ขา 5 (GPIO3) กับขา 6 (GND) หรือจะต่อที่ GPIO อื่นก็ได้ แต่ต้องต้องต่อตัวต้านทานเพิ่มด้วย เพื่อป้องกันความเสียหายกับบอร์ด (GPIO3 มีตัวต้านทานภายในอยู่แล้ว) ที่มา : https://learn.sparkfun.com/tutorials/pull-up-resistors
2.กรณีต่อที่ GPIO3 ต้องเขียน Code เปิดใช้งานตัวต้านทานภายในด้วย
  1. GPIO.setmode(GPIO.BOARD)
  2. GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP)

3.เขียน Code สำหรับควบคุมการเปิด/ปิด : pishutdown.py
  1. #!/usr/bin/python
  2. # shutdown/reboot(/power on) Raspberry Pi with pushbutton
  3.  
  4. import RPi.GPIO as GPIO
  5. from subprocess import call
  6. from datetime import datetime
  7. import time
  8.  
  9. # pushbutton connected to this GPIO pin, using pin 5 also has the benefit of
  10. # waking / powering up Raspberry Pi when button is pressed
  11. shutdownPin = 5
  12.  
  13. # if button pressed for at least this long then shut down. if less then reboot.
  14. shutdownMinSeconds = 3
  15.  
  16. # button debounce time in seconds
  17. debounceSeconds = 0.01
  18.  
  19. GPIO.setmode(GPIO.BOARD)
  20. GPIO.setup(shutdownPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  21.  
  22. buttonPressedTime = None
  23.  
  24. def buttonStateChanged(pin):
  25.     global buttonPressedTime
  26.  
  27.     if not (GPIO.input(pin)):
  28.         # button is down
  29.         if buttonPressedTime is None:
  30.             buttonPressedTime = datetime.now()
  31.     else:
  32.         # button is up
  33.         if buttonPressedTime is not None:
  34.             elapsed = (datetime.now() - buttonPressedTime).total_seconds()
  35.             buttonPressedTime = None
  36.             if elapsed >= shutdownMinSeconds:
  37.                 # button pressed for more than specified time, shutdown
  38.                 call(['shutdown', '-h', 'now'], shell=False)
  39.             elif elapsed >= debounceSeconds:
  40.                 # button pressed for a shorter time, reboot
  41.                 call(['shutdown', '-r', 'now'], shell=False)
  42.  
  43. # subscribe to button presses
  44. GPIO.add_event_detect(shutdownPin, GPIO.BOTH, callback=buttonStateChanged)
  45.  
  46. while True:
  47.     # sleep to reduce unnecessary CPU usage
  48.     time.sleep(5)

* กดสวิตช์ค้างน้อยกว่า 3 วินาที จะเป็นการ reset, มากกว่า 3 วินาทีจะเป็นการ Shutdown, ถ้า Shutdown ไปแล้วจ่ายไฟค้างไว้ กดสวิตช์จะเป็นการเปิด

4.ถ้าอยากเก็บ Log ดูการทำงาน เพิ่ม Code ดังนี้
  1. import logging
  2.  
  3. logger = logging.getLogger(__name__)
  4. logger.setLevel(logging.INFO)
  5.  
  6. # create a file handler
  7. handler = logging.FileHandler('pishutdown.log')
  8. handler.setLevel(logging.INFO)
  9.  
  10. # create a logging format
  11. formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
  12. handler.setFormatter(formatter)
  13.  
  14. # add the handlers to the logger
  15. logger.addHandler(handler)
  16.  
  17. logger.info('Shutdown/Restart')

5.เรียก script ให้ทำงาน
  1. sudo python pishutdown.py

6.กำหนดให้ script ทำงานเป็น Service : /etc/systemd/system/pishutdown.service
  1. [Service]
  2. ExecStart=/usr/bin/python /path_to_pishutdown/pishutdown.py
  3. WorkingDirectory=/path_to_pishutdown/
  4. Restart=always
  5. StandardOutput=syslog
  6. StandardError=syslog
  7. SyslogIdentifier=pishutdown
  8. User=root
  9. Group=root
  10.  
  11. [Install]
  12. WantedBy=multi-user.target

7.Enable service:
  1. sudo systemctl enable pishutdown.service

8.Run service (will be automatically started on next reboot):
  1. sudo systemctl start pishutdown.service

ที่มา : https://gilyes.com/pi-shutdown-button/

 

8/23/2019

การลบ Domain Controller Windows server 2003

การลบ Domain Controller Windows server 2003  กรณีทำผ่าน dcpromo ไม่ได้
1.ntdsutil
2.metada cleanup
3.connections
4.connect to server <servername>
5.quit
6.select operation target
7.list domains
8.select domain <number>
9.list sites
10.select site <number>
11.list servers in site
12.select server <number>
13.quit
14.remove selected server
15.quit
16.quit

จากนั้นลบ Domain Controller ออกจาก Active Directory Sites and Services และ Active Directory Users and Computers

เพิ่มเติม กรณี Server Master เสีย จะใช้ผ่าน GUI ไม่ได้ ERROR

เพิ่มเติม กรณี Server Master เสีย จะใช้ผ่าน GUI ไม่ได้ ERROR
เช่น DC01 เสีย ข้อมูลหายหมด
แก้ Config Server ต่าง ๆ ไปใช้ DC02 แทน
https://intranet.sci.com/blog.php?u=3&b=993

** สำคัญต้องลบ Master ที่เสียทิ้งก่อนไม่อย่างนั้นจะยึด RID ไม่ผ่าน **
ลบ Domain
https://intranet.sci.com/blog.php?u=3&b=67

ต้องยึดโดยใช้คำสั่ง NTDSUTIL
1. Start --> Run --> cmd เข้า Command Prompt
2. พิมพ์ ntdsutil แล้ว Enter
3. พิมพ์ roles แล้ว Enter เพื่อเข้าโหมด fsmo maintenance
4. พิมพ์ connect to server <ชื่อ Server เครื่องที่ยังเปิดอยู่ ที่เราจะยึด roles มาจากเครื่องต้นทาง>
  1. connect to server dc02.sci.com
แล้ว Enter
5. พิมพ์ quit แล้ว Enter
6. พิมพ์ seize <fsmo> master แล้วกด Enter
โดย fsmo เป็นชื่อของ Role ที่ต้องการจะยึด ซึ่งประกอบด้วย RID, Domain Naming , Schema
7. ตอบ Yes
ทำทีละ fsmo ทำต่อกันได้เลย
seize Schema master
seize Domain Naming master
seize RID master

ต้องไม่มี Error fail

Operations Masters ต้องผ่านทั้งหมด RID, PDC, Infrastructiure ต้องผ่าน เป็นชื่อ Server ตัวใหม่ที่ทำขึ้น


8. ทำผ่าน GUI ได้ ได้แก่ PDC Emulator และ Infrastructure Master (ตามข้อ 6. Blog บน)
เสร็จแล้ว Reboot เสร้จขั้นตอนการ ยึด Domain แบบ Command

ในหนังสือหน้า 293

ปัญหาที่พบ
1. proxy ติด ๆ หลุด ๆ ถามและใส่รหัสผ่านเดิม ๆ บ่อยครับ
2. Windows 10 อาการคล้ายหลุด Domain
เข้าเครื่อง datacenter จะถามให้ใส่รหัสผ่าน
เข้าเครื่องอื่น ที่ Join domain shared printer ไม่ได้ทำให้ print ไม่ออก
เข้า เปิด Drawing จาก Axapta ไม่ได้ เพราะยังไม่ได้ใส่รหัสเข้า ที่มี box ขึ้นมาถามก่อน
3. Join domain ใหม่ใช้งานได้ทั้งวันแต่ถ้ามีการ reboot หรือ login ใหม่ก็จะเข้าไม่ได้อีก

แก้ให้ใข้ชั่วคราว

เข้า datacenter หรือ axapta ให้ถามรหัส แล้วใส่รหัส เลือก Remember ไว้ จะได้ใช้ได้ทั้งวันจนกว่าจะ reboot หรือ login ใหม่

วิธีแก้ ต้องทำที่ Domain

https://blogs.msdn.microsoft.com/servergeeks/2014/07/12/dns-records-that-are-required-for-proper-functionality-of-active-directory/

โดยเข้าไปลบค่าที่ DNS ของ Domain

ที่เป็น Server เก่าเช่น server3 server4 DC01 ลบทิ้งให้หมด ไล่ดูทีละ Directory แตกเครื่องหมาย + ออกให้หมด
ลบให้เหลือ เฉพาะ Domain ที่ใช้งานจริง


proxy ติด ๆ หลุด ๆ ถามรหัสบ่อย ๆ ทั้งที่ใช้ตัวเติม
- ตรวจสอบ ไฟล์ hosts ที่ Fix ไว้
- Pi-hole ลอง ping ไป ชื่อ dc ตัวเดิมดูถ้า ping ติดแสดงว่า cash
แก้ hosts แก้ resoft.conf dns ให้ไปใช้ ip fireware เดิมใช้ 127.0.0.1