แสดงบทความที่มีป้ายกำกับ CentOS7 แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ CentOS7 แสดงบทความทั้งหมด

10/01/2560

การติดตั้ง Zabbix Server สำหรับ Monitor ระบบ

ในที่นี้ทางผู้เขียน จะขอแนะนำวิธีการติดตั้ง Zabbix โดยใช้ Centos 7  ครับ  
ก่อนการติดตั้ง ให้ทำการ ติดตั้ง Lamp Server ก่อนครับ (ในที่นี้จะใช้ MariaDB ครับ)
ทำการติดตั้ง Apache  
# yum install httpd -y
หลังจากนั้น Start Service Apache และตั้งค่าให้ เริ่มต้นเมื่อเปิดเครื่อง
#systemctl start httpd
#systemctl enable httpd
เมื่อเสร็จเรียบร้อยให้ติดตั้ง MariaDB สำหรับการจัดการ ฐานข้อมูล
#yum install mariadb-server mariadb -y
Start Service MariaDB และตั้งค่าให้เริ่มต้นเมื่อเปิดเครื่อง
# systemctl start mariadb
# systemctl enable mariadb
หลังจากนั้น ให้สร้าง password ของ mysql โดยปกติจะเป็นค่าว่างให้ใส่ command
#mysql_secure_installation
จะขึ้น รายละเอียดดังนี้ และทำตาม comment ##
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y ## Enter Y and press Enter
//SET root password หรือไม่ ให้ตอบ Y

New password: ## Enter new password สร้าง Password
Re-enter new password: ## Enter password again กรอกใหม่อีกครั้ง
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y ## Enter Y and press Enter ลบ ๊user ที่ไม่รู้จักใช่ไหม ตอบ Y 
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y ## Enter Y and press Enter
 ... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y ## Enter Y and press Enter
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y ## Enter Y and press Enter
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
หลังจากนั้น ให้ Install EPEL
# yum install epel-release
Config Zabbix Zone และ GPG Key
#rpm --import http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX
#rpm -Uv http://repo.zabbix.com/zabbix/2.4/rhel/7/x86_64/zabbix-release-2.4-1.el7.noarch.rpm
Install Zabbix Server และ Zabbix Agent
#yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-java-gateway
แก้ไขไฟล์ /etc/httpd/conf.d/zabbix โดยใช้ Editor ที่ถนัด ตัวอย่าง nano
# nano /etc/httpd/conf.d/zabbix.conf
ให้ Update Time Zone
หาที่มีคำว่า php_value date.timezone Asia/Bangkok
Save!! หลังจากนั้น ให้ Restart Service httpd
#systemctl restart httpd
ต่อมาให้สร้าง Mysql Database และ User สำหรับ Zabbix
ให้เข้า mysql
# mysql -u root -p
Enter Password : ให้ใส่รหัสผ่าน ตอนตั้งค่า password ตอนลง mysql
สร้าง database zabbixdb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.41-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
////เริ่มตรงนี้
MariaDB [(none)]> create database zabbixdb character set utf8; ///ให้สร้าง databases ขึ้นมา ชื่อ zabbixdb
Query OK, 1 row affected (0.05 sec)
MariaDB [(none)]> grant all privileges on zabbixdb.* to 'zabbixuser'@'localhost' identified by 'password';
// ให้สิทธ์ในการเข้าถึงDatabases นี้ สำหรับ User อะไร password อะไร 

Query OK, 0 rows affected (0.21 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit ออกจากMariaDb
หลังจากนั้น ให้Import Template zabbix database มาก่อน เพราะในตอนที่เราสร้าง Databases มานั้น จะยังไม่มี table อะไรเลย โดยให้ใช้ command
#mysql -u zabbixuser -p zabbixdb < /usr/share/doc/zabbix-server-mysql-2.4.5/create/schema.sql
Enter Password: ให้ใส่Password mysql
#mysql -u zabbixuser -p zabbixdb < /usr/share/doc/zabbix-server-mysql-2.4.5/create/images.sql
#mysql -u zabbixuser -p zabbixdb < /usr/share/doc/zabbix-server-mysql-2.4.5/create/data.sql
ต่อมาจะเป็นการ Config Zabbix Server
แก้ไฟล์ด้วย editor  /etc/zabbix/zabbix_server.conf
#nano /etc/zabbix/zabbix_server.conf
โดยให้หาkeyword ตามด้านล่าง และทำการเปลี่ยน
[...]
DBName=zabbixdb ชื่อ Database
[...]
DBUser=zabbixuser ชื่อ User จำเป็น ต้องให้ตรง กับการให้สิทธิ์ในฐานข้อมูล
[...]
DBPassword=password Password
[...]
Save และปิดไฟล์
คราวนี้เราจะมาทำ Agent  ตัว Server เอง คือการ Monitor เครื่อง Zabbix Server
แก้ไฟล์   /etc/zabbix/zabbix_agentd.conf
#nano /etc/zabbix/zabbix_agentd.conf
แก้ตามนี้
[...]
## Line 85 - Specify Zabbix server ##
Server=127.0.0.1
[...]
## Line 126 - Specify Zabbix server ##
ServerActive=127.0.0.1
[...]
## Line 137 - Specify Zabbix server Hostname or IP address ##
Hostname=server1.unixmen.local
[...]
หลังจากนั้น แก้ไขไฟล์ php.ini
#nano /etc/php.ini
set ตามด้านล่าง
max_execution_time = 600
max_input_time = 600
memory_limit = 256M
post_max_size = 32M
upload_max_filesize = 16M
date.timezone = Asia/Bangkok
Save
หลังจากนั้น กำหนด iptables ให้ อนุญาต port zabbix 10050และ 10051 ตาม command ด้านล่าง
#firewall-cmd --permanent --add-port=10050/tcp
#firewall-cmd --permanent --add-port=10051/tcp
หลังจากนั้น ให้ Restart service iptables
#systemctl restart firewalld
หลังจากนั้น Restart Service ตาม Command ด้านล่าง
#systemctl start zabbix-server
#systemctl start zabbix-agent
#systemctl restart httpd
#systemctl restart mariadb
#systemctl enable zabbix-server
#systemctl enable zabbix-agent
หลังจากนั้น ให้ลองเข้าweb console ผ่าน url เช่น http://ip-address/zabbix

วิธีติดตั้งและใช้งาน SSH Secure Shell บน Centos 7

วิธีการติดตั้ง
# yum -y install openssh
หลังจากได้ทำการติดตั้งเสร็จเรียบร้อยแล้วให้เราทำการเปิดใช้งาน
# systemctl start sshd.service
และให้เปิดคำสั่งนี้เพื่อให้โปรแกรมใช้งานอัตโนมัติเมื่อทำการเปิดเครื่อง
# chkconfig sshd on
สามารถเข้าไปแก้ไขไฟล์ config ได้ที่
# vi /etc/ssh/sshd_config
 

การติดตั้ง FTP Server และการเข้าใช้งาน บน Centos 7

การติดตั้ง FTP Server
ให้เริ่มทำการดาวโหลดโปรแกรม vsftpd
#  yum install vsftpd ftp
เมื่อทำการติดตั้งเสร็จ ให้ทำการเริ่มการทำงานของ vsftpd
#  systemctl start vsftpd
เมื่อติดตั้งและได้ทำการเปิดการใช้งานแล้ว ให้เราทำการสร้าง User ของ ftp server
# useradd sk
# passwd sk
เสร็จจากการสร้าง User - Password เราก็มาลองทำการเข้าใช้งานดูว่าเข้าใช้งานได้หรือไม่
ftp 192.168.1.101 (ip นี้เป็นตัวอย่างให้ใส่เป็นของเราเอง)
ถ้ามันขึ้นว่า
ftp>
แปลว่าเราได้ทำการติดตั้งและะได้เริ่มใช้งาน FTP Server ได้เรียบร้อยแล้ว

วิธี Reset password root บน CentOS 7

บางครั้งหากคุณลืมรหัสผ่านที่สำคัญในการเข้าใช้งานเว็บไซต์ เว็บไซต์ส่วนใหญ่สามารถรีเซ็ตรหัสผ่านได้ไม่ยากนักเพียงแค่คุณจดจำรายละเอียดข้อมูลการสมัคร ก็จะสามารถรีเซ็ตรหัสผ่านสำหรับบัญชีได้

ความแตกต่างกันหากคุณลืมรหัสผ่านของระบบหรืออุปกรณ์ มันไม่ง่ายนักที่จะรีเซ็ตรหัสผ่านได้ CentOS 7 ก็เป็นหนึ่งในระบบนั้น หากคุณลืมรหัสผ่าน Root บนเครื่อง CentOS 7 ของคุณ

วิธีนี้สามารถทำงานได้ หากคุณสามารถเข้าถึงเมนูของการบูตของเครื่องได้

เริ่มต้นเปิดเครื่อง CentOS 7 ที่ลืมรหัสผ่าน Root ระบบจะใช้เวลา 5 วินาทีในการบูตเมนูเพื่อเลือกระบบปฏิบัติการใช้งาน

ระยะเวลานี้เป็นสิ่งสำคัญเพราะช่วยให้ผู้ดูแลระบบสามารถแก้ไขพารามิเตอร์ที่มีอยู่ก่อนที่ระบบจะเริ่มต้นทำงานได้

ที่เมนูกด E เพื่อแก้ไขค่าต่าง ๆ ของเคอร์เนลหลักที่มีอยู่

เลื่อนลงเรื่อยๆ จนเห็นบรรทัดที่มีคำสั่ง ro

จากนั้นเปลี่ยน ro ไปเป็น rw init=/sysroot/bin/sh

หลังจากเปลี่ยนแล้วกด Control + X เพื่อเริ่มใช้งานโหมด Single user โดยเรียก bash shell ในการเปลี่ยน root password เมื่อเข้าโหมด Single user พิมพ์คำสั่ง chroot /sysroot

สุดท้ายพิมพ์คำสั่ง passwd root เพื่อเปลี่ยนรหัสผ่านของ root

หลังจากที่สร้างรหัสผ่านใหม่แล้ว พิมพ์คำสั่ง touch /.autorelabel เพื่อปรับปรุงพารามิเตอร์ของ SELinux
Exit และ reboot ระบบ คุณจะสามารถเข้าใช้งาน root บน CentOS 7 ได้