หน้าเว็บ

วันพุธที่ 27 มิถุนายน พ.ศ. 2561

Pfsense : Pfsense Create User VPN and CA User Certificates

Pfsense : Pfsense Create User VPN and CA User Certificates
1. เข้า Pfsense
สร้าง User เข้าไปที่ Menu System ---> User Manager
Add user ที่ต้องการ

2. สร้าง CA
กด Add ตรง User Certificates
เลือก Method เป็น Create an internal Certificate
ใส่ Common Name เป็นชื่อที่สร้างขึ้น เช่น seksan_k
กด Save จะได้ CA มาที่ชื่อ
ตั้งรหัส ให้เรียบร้อย แล้วกด Save

3. Export ชื่อและโปรแกรมเพื่อนำไปใช้งาน
ที่ Menu VPN ---> Open VPN ที่ Tab Client Export
เลื่อนมาด้านล่างจะพบชื่อที่สร้างขึ้น
เลือก Export โปรแกรมที่จะนำไปใช้งาน

Install Nextcloud on Ubuntu 18.04

Install Nextcloud on Ubuntu 18.04
1. Install Ubuntu 18.04 Server

2. Edit apt.conf
  1. nano /etc/apt/apt.conf

Insert this code
Acquire::http { Proxy "http://192.168.2.106:9999"; };

And
  1. apt-get update
  2. apt-get upgrade
  3. locale-gen en_US en_US.UTF-8 th_TH th_TH.UTF-8


3. Install software
  1. add-apt-repository ppa:ondrej/php

  1. apt-get update

  1. apt-get install php7.0 php7.0-mysql php7.0-curl php7.0-json php7.0-cgi libapache2-mod-php7.0 php7.0-mcrypt php7.0-xmlrpc php7.0-gd php7.0-mbstring php7.0  php7.0-common  php7.0-xmlrpc php7.0-soap  php7.0-xml php7.0-intl  php7.0-cli  php7.0-ldap php7.0-zip php7.0-readline php7.0-imap php7.0-tidy php7.0-recode php7.0-sq php7.0-intl php7.0-intl php7.0-mcrypt php-imagick php7.0-xml php7.0-zip


4. Download software Nextcloud https://download.nextcloud.com/server/releases/ Today version is 13.0.4
  1. wget https://download.nextcloud.com/server/releases/nextcloud-13.0.4.zip


5. Install unzip software
  1. apt-get install unzip

Unzip file.
  1. unzip  nextcloud-13.0.4.zip

Move file to www
  1. mv nextcloud /var/www/

Chown and Chmod
  1. chown -R www-data.www-data nextcloud
  2. chmod -R 775 nextcloud/


6. Edit root document apache.
  1. nano /etc/apache2/sites-available/000-default.conf

Edit
DocumentRoot /var/www/nextcloud

And
  1. a2enmod rewrite
  2. systemctl restart apache2


7. Create folder for save all DATA
  1. mkdir /DATA
  2. chown -R www-data.www-data /DATA/
  3. chmod -R 770 /DATA/


8. Test login to web
192.168.2.112 IP Or nextcloud.sci.com
Test login admin create user error
Error
Error while trying to create admin user: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory



9. Install and setting mariadb
  1. sudo apt-get install mariadb-server mariadb-client

  1. sudo systemctl start mariadb
  2. sudo systemctl enable mariadb


10. Config mariadb password
  1. sudo mysql_secure_installation

Enter
- Insert password db 2 time.
- and Y 5 time.
  1. mariadb

Create user and database.
  1. create user NEXTCLOUDUSER@localhost identified by 'PASSWORD';
  2. create database NEXTCLOUD_DB_NAME;
  3. grant all privileges on NEXTCLOUD_DB_NAME.* to NEXTCLOUDUSER@localhost identified by 'PASSWORD';
  4. flush privileges;
  5. exit;


8. Test login to web
192.168.2.112 IP Or nextcloud.sci.com
Insert admin user and password
Insert path Data on number 7.
Insert user password mariadb on number 10.
And click finish setup button.

Finish Show Login Admin NextCloud.

This way link.
https://www.linuxhelp.com/how-to-install-nextcloud-13-on-ubuntu-18-04/
https://www.techrepublic.com/article/how-to-install-nextcloud-13-on-ubuntu-18-04/
https://www.linuxbabe.com/ubuntu/install-nextcloud-ubuntu-18-04-nginx-lemp



Config Ldap เพื่อให้ใช้ชื่อจาก AD ได้
1. ติดตั้ง Ldap
  1. apt-get install php7.0-ldap
  1. /etc/init.d/apache2 restart

reboot เครื่อง Server ถ้าไม่ reboot LDAP user and group backend จะไม่สามารถ Enable ได้

2. เข้า User ที่เป็น Admin
เพื่อ Enable : LDAP user and group backend

3. Config Ldap ไปที่ Admin --> Setting --> LDAP/AD integration
4. Config


เพิ่มเติมเอาเฉพาะ User ที่เป็น Enable ใช้ค่านี้ที่ Ldap tap User
(&(|(objectclass=organizationalPerson))(|(memberof=CN=owncloud,OU=SCI,DC=SCI,DC=COM))(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))

https://intranet.sci.com/blog.php?u=3&b=1033

5. เข้า Admin --> User (รอสักพักถ้า Config ข้อ 4 ถูกต้องชื่อที่จะแสดงออกมา)

 Add Disk DATA
1. Add Disk On VMware
2. Formate และสร้าง Patition
https://intranet.sci.com/blog.php?u=281&b=1000
3. แก้ fstab mount Auto
https://intranet.sci.com/blog.php?u=3&b=632
4. เปลี่ยนชื่อ Folder /DATA เป็นชื่ออื่น
5. สร้าง Folder /DATA เปลี่ยน Owner และ สิทธ์ ให้เป็นเหมือน Folder เดิม
6. mount disk ใหม่ใส่ /DATA
7. move DATA จาก Folder เดิมไปใส่ Folder ใหม่
ไฟล์ .ocdata ต้องเอาไปด้วยไม่เอาไป จะ Error

เสร็จขั้นตอนการ Add Disk ใหม่

เปิดใช้งาน HTTPS
1. Run Command
  1. a2enmod ssl
  2. a2ensite default-ssl
  3. service apache2 reload
2. Edit File port 80 Redirect To HTTPS
  1. nano /etc/apache2/sites-available/000-default.conf
Edit
      #Redirect To HTTPS
ServerName nextcloud.sci.com
Redirect / https://nextcloud.sci.com/
ServerAdmin suwit@scivalve.com
3. Restart apache
  1. /etc/init.d/apache2 restart

เข้าใช้งาน ทั้งแบบ nextcloud.sci.com จะเข้าไปที่ https://nextcloud.sci.com

ให้เข้าจากข้างนอกได้ ด้วย .scivalve.com
ด้วยการ Forward Port
1. แก้ Host ข้างนอก DirectAdmin Login Page ด้วยสิทธิ์ Admin
เข้าไปที่ DNS Administration เลือก scivalve.com
เพิ่ม nextcloud A xxx.xxx.xxx.xxx (ip web server ที่ต้องการให้เข้า)
และ http://www.nextcloud A xxx.xxx.xxx.xx
(อันนี้ต้องรอจนกว่าข้างนอกจะรู้ว่า nextcloud.scivalve.com ใช้งานได้

2. แก้ Firewall Forward Port ที่ Pfsense
Firewall ---> NAT เพิ่ม ให้เข้าจาก IP ข้างนอก ไป 192.168.2.112:8880

ลองเข้าจากข้างนอกผ่าน Port 8880 ดู

3. Config App ที่ Smart phone ต้องใส่ https://netcloud.scivalve.com:8880
จะได้เข้าจากข้างนอกได้ เข้าจากข้างนอกก็เช่นกันต้องใช้ https://netcloud.scivalve.com:8880
แต่เข้าใน SCI สามารถ ใช้
https://netcloud.sci.com หรือ https://netcloud.scivalve.com ได้เลย

วันจันทร์ที่ 7 พฤษภาคม พ.ศ. 2561

MQTT : ส่งค่าจากเครื่อง Clients ไป MQTT Server

MQTT : ส่งค่าจากเครื่อง Clients ไป MQTT Server
1. ติดตั้ง
  1. apt install mosquitto-clients


2. ลองส่งข้อมูลไปที่ state_topic ที่ต้องการเช่น
  1. mosquitto_pub -h 192.168.2.200 -t "hass/speedtest" -m 210


3. Code ส่ง Python
  1.        import paho.mqtt.client as mqtt
  2.  
  3.         mqttc = mqtt.Client("python_pub")
  4.         mqttc.connect("192.168.2.200", 1883)
  5.         mqttc.publish("hass/speedtest", Value ที่จะส่งไป)
  6.         mqttc.loop(2) #timeout = 2s


ถ้ามี Error
  1. Traceback (most recent call last):
  2.   File "nettest.py", line 62, in <module>
  3.     test()
  4.   File "nettest.py", line 48, in test
  5.     import paho.mqtt.client as mqtt
  6. ImportError: No module named paho.mqtt.client


ต้อง Run คำสั่ง
  1. pip install paho-mqtt

วันพฤหัสบดีที่ 3 พฤษภาคม พ.ศ. 2561

ติดตั้ง Home Assistant

Home Assistant : https://home-assistant.io
เป็นระบบสำหรับควบคุมและติดตามการทำงานของอุปกรณ์ภายในบ้านได้หลากหลายชนิด

ขั้นตอนการติดตั้ง : https://home-assistant.io/docs/installation/raspberry-pi/
1.ติดตั้ง Ubuntu Server (16.04)
2.ติดตั้ง Python virtual environment
  1. sudo add-apt-repository ppa:deadsnakes/ppa
  2. sudo apt-get update
  3. sudo apt-get install python3.6
  4. sudo apt-get install -y python3.6-venv python3.6-dev

3.สร้าง User สำหรับ Setup และ Run ระบบ
  1. sudo useradd -rm homeassistant
  2. cd /srv
  3. sudo mkdir homeassistant
  4. sudo chown homeassistant:homeassistant homeassistant

4.สร้าง Virtual Environment
  1. sudo su -s /bin/bash homeassistant
  2. cd /srv/homeassistant
  3. python3.6 -m venv .
  4. source bin/activate

5.ติดตั้ง pacakage เพิ่ม
  1. python3.6 -m pip install wheel

6.ติดตั้ง Home Assistant
  1. pip3 install homeassistant

7.สั่งให้ระบบทำงาน
  1. hass

8.เรียกใช้งานที่ port 8123
  1. ้http://homeassistant:8123


ตั้งค่าให้ทำงานตอน start
: https://home-assistant.io/docs/autostart/systemd/
  1. [Unit]
  2. Description=Home Assistant
  3. After=network-online.target
  4.  
  5. [Service]
  6. Type=simple
  7. User=%i
  8. ExecStart=/srv/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant"
  9.  
  10. [Install]
  11. WantedBy=multi-user.target

  1. sudo systemctl --system daemon-reload
  2. sudo systemctl enable home-assistant@homeassistant //disable
  3. sudo systemctl start home-assistant@homeassistant // stop : restart : status

  1. sudo journalctl -f -u home-assistant@homeassistant


Upgrade :
  1. sudo systemctl stop home-assistant@homeassistant
  2. sudo su -s /bin/bash homeassistant
  3. cd /srv/homeassistant
  4. source bin/activate
  5. python3.6 -m pip install --upgrade homeassistant
  6. sudo systemctl start home-assistant@homeassistant

Line Notify

Line เปิดให้บริการที่ชื่อว่า Line Notify ซึ่งทำให้สามารถส่งข้อความหาบุคคลหรือกลุ่มได้
1.สมัครใช้บริการที่ https://notify-bot.line.me/my/
2.สร้าง Token โดยตั้งชื่อซึ่งจะใช้เป็นชื่อผู้ส่งข้อความ และเลือกบุคคลหรือกลุ่มที่ต้องการส่งข้อความถึง แล้วคลิก ออก Token
3.นำ Token ไปเขียน code สำหรับส่งข้อความ เช่น
  1. <?php
  2. define('LINE_API',"https://notify-api.line.me/api/notify");
  3.  
  4. $token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; //ใส่Token ที่copy เอาไว้
  5. //$str = "Hello"; //ข้อความที่ต้องการส่ง สูงสุด 1000 ตัวอักษร
  6. $str = $_GET["msg"];
  7.  
  8. $res = notify_message($str,$token);
  9. print_r($res);
  10. function notify_message($message,$token){
  11.  $queryData = array('message' => $message);
  12.  $queryData = http_build_query($queryData,'','&');
  13.  $headerOptions = array(
  14.          'http'=>array(
  15.             'method'=>'POST',
  16.             'header'=> "Content-Type: application/x-www-form-urlencoded\r\n"
  17.                       ."Authorization: Bearer ".$token."\r\n"
  18.                       ."Content-Length: ".strlen($queryData)."\r\n",
  19.             'content' => $queryData
  20.          ),
  21.  );
  22.  $context = stream_context_create($headerOptions);
  23.  $result = file_get_contents(LINE_API,FALSE,$context);
  24.  $res = json_decode($result);
  25.  return $res;
  26. }
  27. ?>

4.เพิ่ม Account ของ Line Notify เป็นสมาชิกในกลุ่มนั้น
5.เรียกใช้ code แล้วจะได้ json บอกผลลัพธ์มา

ตัวอย่างการใช้งาน :
6.แจ้งเตือนเมื่อมีการ login เข้า server (เพิ่ม code เข้าไปที่ .profile หรือ .bash_profile)
  1. curl -X POST -H 'Authorization: Bearer [xxxxxxxxxxxxxxxxxxx]' -F 'message=Somebody login to server' https://notify-api.line.me/api/notify

หรือ
  1. wget --no-check-certificate 'https://intranet.sci.com/sci/Line/notify.php?msg=Somebody%20login%20to%20Server'

หรือ
  1. curl --insecure 'https://intranet.sci.com/sci/Line/notify.php?msg=Somebody%20login%20to%20Server'

วันพุธที่ 2 พฤษภาคม พ.ศ. 2561

Ubuntu :: Ubuntu 10.04 Error Update

Ubuntu :: Ubuntu 10.04 Error Update
  1. apt-get update

show error
Err http://th.archive.ubuntu.com lucid/main Packages
404 Not Found
Err http://th.archive.ubuntu.com lucid/restricted Packages
404 Not Found
Err http://th.archive.ubuntu.com lucid/main Sources
404 Not Found
Err http://th.archive.ubuntu.com lucid/restricted Sources
404 Not Found
Err http://th.archive.ubuntu.com lucid/universe Packages
404 Not Found
Err http://th.archive.ubuntu.com lucid/universe Sources
404 Not Found
Err http://th.archive.ubuntu.com lucid/multiverse Packages
404 Not Found
Err http://th.archive.ubuntu.com lucid/multiverse Sources
404 Not Found


Err http://security.ubuntu.com lucid-security/main Packages
404 Not Found
Err http://security.ubuntu.com lucid-security/restricted Packages
404 Not Found
Err http://security.ubuntu.com lucid-security/main Sources
404 Not Found
Err http://security.ubuntu.com lucid-security/restricted Sources
404 Not Found
Err http://security.ubuntu.com lucid-security/universe Packages
404 Not Found
Err http://security.ubuntu.com lucid-security/universe Sources
404 Not Found
Err http://security.ubuntu.com lucid-security/multiverse Packages
404 Not Found
Err http://security.ubuntu.com lucid-security/multiverse Sources
404 Not Found
W: Failed to fetch http://th.archive.ubuntu.com/ubuntu/dis ... ackages.gz 404 Not Found

W: Failed to fetch http://th.archive.ubuntu.com/ubuntu/dis ... ackages.gz 404 Not Found

W: Failed to fetch http://th.archive.ubuntu.com/ubuntu/dis ... Sources.gz 404 Not Found


วิธีแก้
1. backup ไฟล์ sources.list ไว้ก่อน อยู่ที่ /etc/apt/sources.list
2. ใช้คำสั่ง
  1. sudo sed -i.bak -r 's/(th.archive|security).ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list

3. ทดลอง update upgrade ดู

https://gist.github.com/dergachev/f5da514802fcbbb441a1
https://askubuntu.com/questions/805523/apt-get-update-for-ubuntu-10-04

วันศุกร์ที่ 27 เมษายน พ.ศ. 2561

Vmware : Vmawre Esxi 6.5 status invalid ไม่สามารถลบปกติได้ ด้วยการคลิกขวา ลบ หรือ Unregister ได้

Vmware : Vmawre Esxi 6.5 status invalid ไม่สามารถลบปกติได้ ด้วยการคลิกขวา ลบ หรือ Unregister ได้
แก้โดย
vmware remove virtual machine status invalid by command
1. ssh เข้าเครื่อง Server Vmware ที่ Error
2. Stop vpxa and hostd service before edit คำสั่งนี้ Server อื่น ๆ ยังสามารถเข้าใช้งานได้ตามปกติ
  1. /etc/init.d/vpxa stop
  1. /etc/init.d/hostd stop

3. เข้าไปที่ /etc/vmware/hostd
  1. cd /etc/vmware/hostd

3. แก้ไฟล์ vmInventory.xml ด้วยคำสั่ง vi backup ไฟล์เดิมไว้ก่อนแก้ไขด้วย
  1. vi vmInventory.xml

4. หา Line ที่ Vm Error แล้วกด ลบ ด้วยการกด dd ลบทั้งบรรทัดออก
เช่น
  1.  <ConfigEntry id="0002">
  2.     <objID>3</objID>
  3.     <secDomain/>
  4.     <vmxCfgPath>/vmfs/volumes/590cca43-c78bd3ac-1234-000c2908a466/VMware vCenter Server Appliance/VMware vCenter Server Appliance.vmx</vmxCfgPath>
  5.   </ConfigEntry>

5. กด :wq เพื่อออกจาก จาก คำสั่ง vi
6. Start service vpxa and hostd service
  1. /etc/init.d/vpxa start
  1. /etc/init.d/hostd start

เสร็จแล้วลองเข้าดู Vm ที่ Error จะหายไป
https://communities.vmware.com/thread/582673
คำสั่ง vi เพิ่มเติม
http://thaiopensource.org/%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99-vi-editor-%E0%B9%80%E0%B8%9A%E0%B8%B7%E0%B9%89%E0%B8%AD%E0%B8%87%E0%B8%95%E0%B9%89%E0%B8%99/