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

ไม่มีความคิดเห็น:

แสดงความคิดเห็น