หน้าเว็บ

วันพฤหัสบดีที่ 29 สิงหาคม พ.ศ. 2562

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/

     

    วันพฤหัสบดีที่ 22 สิงหาคม พ.ศ. 2562

    การลบ 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

    QNAP : Add harddisk จาก QNAP ไปใช้ DataStore ของ VMware

    QNAP : Add harddisk จาก QNAP ไปใช้ DataStore ของ VMware
    ให้เห็น 2 เครื่องใช้ร่วมกันได้
    Qnap .77
    Vm .66
    Vm .88

    Qnap
    - สร้าง Pool
    - สร้าง ISCSI
    ที่เครื่อง VMware
    Storage --> Adapters --> Config iSCSI
    *** Add Datastores *** ถ้าจะใช้แบบ Shared ข้อมูลกัน เห็นทั้งสองเครื่องเหมือนกัน Shared Datastores ร่วมกัน
    ต้อง Add ที่ Device ถ้า Add New Datastores เลยจะเห็นของใครของมัน

    Vm ก็จะใช้ Data ร่วมกัน ทั้ง 2 เครื่อง


    Extranet : ติดตั้ง Extranet ใน Ubuntu 18.04

    Extranet : ติดตั้ง Extranet ใน Ubuntu 18.04
    1. ติดตั้ง Ubuntu 18.04
    Set IP
    https://intranet.sci.com/blog.php?u=281&b=1716
    Update Upgrade ให้เรียบร้อย

    ต้องใช้ php5 เพราะมีใช้คำสั่งติดต่อกับ Axapta ใน Code ใช้ php7 ไม่ได้
    2. ติดตั้ง Apache2
    1. sudo apt-get install apache2


    3. ติดตั้ง php5.6
    sudo add-apt-repository ppa:ondrej/php
    sudo apt-get update
    sudo apt-get install -y php5.6

    1. php -v

    PHP 5.6.40-10+ubuntu18.04.1+deb.sury.org+1 (cli)
    Copyright (c) 1997-2016 The PHP Group
    Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

    1. sudo a2dismod mpm_event
    2. sudo a2enmod php5.6
    3. sudo service apache2 restart


    4. แก้ index.php ดู php version เพิ่ม
    1. phpinfo();


    5. ติดตั้ง mysql และ phpmyadmin
    1. sudo apt-get install mysql-server
    2. sudo apt-get install mysql-phpmyadmin


    6. mssql สำหรับติดต่อไป axapta server
    https://intranet.sci.com/blog.php?u=3&b=293
    ลงไม่ได้
    1. sudo apt-get install php5-mssql

    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    E: Unable to locate package php5-mssql


    ต้องใช้
    1. sudo apt-get install php5.6-sybase freetds-common libsybdb5
    2. /etc/init.d/apache2 restart


    https://gist.github.com/joecampo/acd1e5881aee08bd8959

    7. เปลี่ยนรหัส root ที่ login เข้า phpmyadmin
    https://intranet.sci.com/blog.php?u=281&b=1718

    8. phpmyadmin เข้าไม่ได้ มีตัวหนังสือสีแดงลงโปรแกรมที่จะใช้ไม่ครบ
    1. apt-get install php5.6-mbstring
    2. apt-get install php5.6-mysqli
    3. /etc/init.d/apache2 restart


    8. แก้ max upload php.ini upload database ไม่ผ่าน
    nano /etc/php/5.6/apache2/php.ini

    upload_max_filesize = 100m
    memory_limit = 256m

    1. /etc/init.d/apache2 restart


    10. สร้าง database sci_extranet และ import database ที่มี

    11. เปลี่ยนชื่อเครื่อง ตั้งชื่อเครื่องไม่ถูก
    https://linuxize.com/post/how-to-change ... ntu-18-04/

    12. เปิดใช้งานแบบ https
    12.1. สร้าง Cer
    https://intranet.sci.com/blog.php?u=281&b=1673
    https://intranet.sci.com/blog.php?u=3&b=970
    12.2. แก้ไฟล์ redirect port
    1. nano /etc/apache2/sites-enabled/000-default.conf

    <VirtualHost *:80>
    ServerName extranet.scivalve.com
    Redirect / https://extranet.scivalve.com/
    ServerAdmin suwit@scivalve.com
    </VirtualHost>

    <VirtualHost *:443>
    ServerName extranet.scivalve.com
    DocumentRoot /var/www/extranet
    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/extranet.scivalve.com.pem
    SSLCertificateKeyFile /etc/apache2/ssl/extranet.scivalve.com.key
    ServerAdmin suwit@scivalve.com
    <Directory /var/www/extranet/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    </Directory>
    </VirtualHost>

    <VirtualHost *:80>
    ServerName extranet.sci.com
    Redirect / https://extranet.sci.com/
    ServerAdmin suwit@scivalve.com
    </VirtualHost>

    <VirtualHost *:443>
    ServerName extranet.sci.com
    DocumentRoot /var/www/extranet
    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/extranet.sci.com.pem
    SSLCertificateKeyFile /etc/apache2/ssl/extranet.sci.com.key
    ServerAdmin suwit@scivalve.com
    <Directory /var/www/extranet/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    </Directory>
    </VirtualHost>


    13. exports cer
    https://intranet.sci.com/blog.php?u=281&b=1060
    ทำ cer ไป authen จาก server ไปเครื่องลูก
    https://intranet.sci.com/blog.php?u=281&b=1061

    ภาษาไทยที่ select มาจาก Axatpa ไม่แสดง ภาษาไทย อ่านไม่ออก
    แสดงเป็น ???????????????????

    แก้ php.ini
    1. nano /etc/php/5.6/apache2/php.ini

    แก้จาก
    mssql.charset = "ISO-8859-1"
    แก้เป็น
    mssql.charset = "tis620"

    แล้ว Restart apache
    1. /etc/init.d/apache2 restart

    VMware : VMware Tools Windows 2003 On ESXi 6.7

    VMware : VMware Tools Windows 2003 On ESXi 6.7 มีอาการ จอฟ้า จึงทดลองติดตั้ง VMware Tools

    VMware Tools
    VMware Tools 10.3.2 Release Notes

    These Notes clear stats that there is no iso or packages has been released for Windows 2003 or earlier OS. The list of the OS which support these latest VMware tools are below.

    Windows OS level prerequisites
    Windows Server 2016
    Windows 10
    Windows Server 2012 R2
    Windows 8.1
    Windows Server 2012
    Windows 8
    Windows Server 2008 R2 Service Pack 1 (SP1)
    Windows 7 SP1
    Windows Server 2008 Service Pack 2 (SP2)
    Windows Vista SP2
    Windows Server 2012 R2 with Microsoft update KB2919355
    Windows 8.1 with Microsoft update KB2919355

    ไม่มี Windows server 2003 ถูกตัดออก เนื่องจาก
    End of Support for Microsoft Windows Server 2003 as well as some other old traditional legacy EUC OS
    Microsoft Product Life Cycle
    https://support.microsoft.com/en-gb/lif ... 02003%20R2

    ต้องใช้ VMware Tools Version 10.0.12
    winPreVista.iso
    ติดตั้งได้
    แต่จะมีข้อความขึ้น
    VMware Tools is installed and supported, but a newer version is available on the host.
    The configured guest OS (Microsoft Windows Server 2003 (32-bit)) for this virtual machine does not match the guest that is currently running (Microsoft Windows Server 2003 Standard (32-bit)). You should specify the correct guest OS to allow for guest-specific optimizations.

    วันอังคารที่ 13 สิงหาคม พ.ศ. 2562

    Ubuntu : Ubuntu 18.04 Change Pasword root phpmyadmin

    Ubuntu : Ubuntu 18.04 Change Pasword root phpmyadmin

    User เริ่มต้น เป็น : phpmyadmin
    รหัสตั้งตอนลง pypmyadmin

    ต้องการใช้ user root หรือ sa
    1. sudo mysql
    2. SELECT user,authentication_string,plugin,host FROM mysql.user;
    ตั้งรหัสของ root ใหม่
    1. SET PASSWORD 'root'@'localhost'=PASSWORD('mynewpasword');

    ถ้า Error ไม่ผ่านใช้คำสั่ง
    1. ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mynewpassword';

    ตามด้วย
    1. FLUSH PRIVILEGES;
    สร้าง User ใหม่ sa
    1. mysql -u root -p
    2. CREATE USER 'NewUser'@'localhost' IDENTIFIED BY 'NewPassword';
    3. GRANT ALL PRIVILEGES ON *.* TO 'NewUser'@'localhost' WITH GRANT OPTION;
    4. exit

    https://linuxhint.com/install_phpmyadmin_ubuntu_1804/

    วันพฤหัสบดีที่ 8 สิงหาคม พ.ศ. 2562

    Ubuntu :: Ubuntu 18.04 Set IP

    Ubuntu :: Ubuntu 18.04 Set IP
    1. Set ตอนที่ลงไม่ได้ Save แล้วกลับไป Reset หาย หน้านี้
    2. ต้องต่อ Lan วง 0 เพื่อให้ได้รับ DHCP ถึงจะลงผ่าน แล้วค่อยไป เปลี่ยนให้ไปใช้ VM Network
    3. Set Ip ที่ ไฟล์
    1. nano /etc/netplan/50-cloud-init.yaml

    4. การ Set ห้ามใช้ Tab ให้ใช้ Space bar แทน แต่ละ : ต้องขนาดเท่ากัน ถึงจะผ่าน เช่น
    1. network:
    2.    version: 2
    3.    renderer: networkd
    4.    ethernets:
    5.       ens160:
    6.          addresses: [192.168.2.202/24]
    7.          gateway4: 192.168.2.2
    8.          nameservers:
    9.             addresses: [8.8.8.8,8.8.4.4,192.168.2.2]

    5. คำสั่ง นำไปใช้
    1. netplan apply