Giới thiêu

Zabbix là một phần mềm mã nguồn mã có chức năng giám sát được sử dụng để thu thập các số liệu từ các thiết bị và hệ thống khác nhau như thiết bị mạng, hệ thống VM, hệ thống Linux/Windows và dịch vụ đám mây. Zabbix có thể gửi thông báo thông báo về các vấn đề trong bất kỳ hệ thống được giám sát nào.

Trong bài hướng dẫn này Linux Căn Bản sẽ hướng dẫn bạn thực hiện cài đặt Zabbix trên hệ thống CentOS và cấu hình, mời các bạn cùng theo dõi nhé.

Điều kiện

  • Máy chủ web Apache
  • PHP và các extension cần thiết
  • Máy chủ Cơ sở dữ liệu MySQL/MariaDB

Cài đặt Zabbix trên CentOS

Bước 1: Vô hiệu SElinux

Đầu tiên bạn kiểm tra xem selinux có đang tắt không, nếu đang bật thì bạn tắt đi nhé. Bạn kiểm tra bằng lệnh sau sestatus . Nếu Disable thì thôi, còn đang Enable thì bạn tắt bằng cách sau.

vi /etc/sysconfig/selinux

Change SELINUX=enforcing to SELINUX=disabled

Sau đó reboot lại máy chủ bằng lệnh reboot

Bước 2: Cài đặt và cấu hình Apache

Bạn thực hiện chạy các lệnh sau

  • Cài đặt httpd
yum -y install httpd
  • Start httpd
systemctl start httpd.service
  • Kích hoạt httpd khi khởi động
systemctl enable httpd
  • Kiểm tra trạng thái httpd
systemctl status httpd.service

Install Zabbix Centos OS

Cấu hình các repo cần thiết

  • Cài đặt epel và remi repos
yum -y install epel-release -y
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
  • Vô hiệu PHP 5 repositories và enable PHP 7.2 repo
yum-config-manager --disable remi-php54
yum-config-manager --enable remi-php72

Bước 3: Cài đặt PHP

yum install php php-pear php-cgi php-common php-mbstring php-snmp php-gd php-pecl-mysql php-xml php-mysql php-gettext php-bcmath
  • Chỉnh sửa time Zone PHP tại file php.ini
vi /etc/php.ini

Bạn nhỏ comment và chỉnh sửa như sau (data..timezone ở dòng 878)

date.timezone = Asia/Ho_Chi_Minh

Bước 4: Cài đặt MariaDB

Bạn chạy lệnh sau để cài đặt

yum --enablerepo=remi install mariadb-server
  • Start MariaDB
systemctl start mariadb.service
  • Kích hoạt MariaDB khi boot hệ thống
systemctl enable mariadb
  • Kiểm tra trạng thái MariaDB
systemctl status mariadb.service

Install Zabbix Centos OS

Sau đó bạn chạy lệnh sau để cấu hình bảo mật MariaDB

mysql_secure_installation

Bạn chọn Y và thêm vào pass root mới cho MariaDB và tiếp tục, khi nhận thông báo bạn cứ chọn Y hết nhé.

[root@zabbix ~]# mysql_secure_installation

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): <== Nhấn enter
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
New password: <== Nhập vào password mới
Re-enter new password: <== Nhập lại lần nữa
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
 ... 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
 ... 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
 - 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
 ... 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!

Sau đó bạn đăng nhập vào DB server và nhập password vào

mysql -u root -p

Bước 5: Tạo Database cho Zabbix

Bạn thực hiện chạy các lệnh sau sau khi đăng nhập vào DB server

[root@zabbix ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.64-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database linuxcanban CHARACTER SET UTF8 COLLATE UTF8_BIN; ## lệnh tạo DB có tên là linuxcanban
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> create user 'zabbixuser'@'localhost' identified BY 'Gn)fa$5laBqL'; ## Tạo User DB
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> grant all privileges on linuxcanban.* to zabbixuser@localhost; ## Gán quyền DB với DB User
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit; ## Nhấn để thoát
Bye

Bước 6: Cài đặt Zabbix và các

Bạn thực hiện chạy các lệnh sau

  • Thêm Zabbix repository bằng cách copy lệnh bên dưới và chạy
rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
  • Cài đặt Zabbix
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-get

Install Zabbix Centos OS

Bước 7: Configure Zabbix

Thay đổi Time Zone trong cấu hình Zabbix Apache, bạn mở file /etc/httpd/conf.d/zabbix.conf và sửa như sau.

Bạn umcomment Time Zone và sửa như sau.

php_value date.timezone Asia/Ho_Chi_Minh

Install Zabbix Centos OS

  • Sau đó bạn Restart lại httpd
systemctl restart httpd.service

Tiếp theo bạn truy cập vào thư mục sau /usr/share/doc/zabbix-server-mysql-4.0.16 và import MySQL.

Lưu ý: Tùy phiên bản mà chổ mình tô đỏ sẽ khác, để chắc chắn bạn kiểm tra và truy cập cho đúng nhé

zcat create.sql.gz | mysql -u zabbixuser -p linuxcanban

Install Zabbix Centos OS

Sau khi import hoàn tất bạn bắt đầu chỉnh sửa cấu hình Database như sau

Mở file zabbix_server.conf tại đây

vi /etc/zabbix/zabbix_server.conf

Tại đây bạn tìm đến dòng số 91100, 116125 và thay đổi thông số cấu hình mặc định thành thông tin database mà bạn đã tạo trước đó ở Bước 5

DBHost=localhost
DBNamelinuxcanban
DBUser=zabbixuser
DBPassword=Gn)fa$5laBqL

Sau khi chỉnh sửa hoàn tất bạn Restart lại dịch vụ Zabbix

  • Start Zabbix
systemctl start zabbix-server.service
  • Kích hoạt Zabbix khi boot
systemctl enable zabbix-server.service
  • Restart lại Zabbix
systemctl restart zabbix-server.service
  • Kiểm tra trạng thái
systemctl status zabbix-server.service

Install Zabbix Centos OS

Nếu máy chủ có cấu hình firewalld thì bạn thực hiện thay đổi firewall rules như sau

firewall-cmd --add-service={http,https} --permanent
firewall-cmd --add-port={10051/tcp,10050/tcp} --permanent
firewall-cmd --reload
systemctl restart httpd

 

Nếu máy chủ cài đặt CSF thì bạn mở file /etc/csf//csf.conf và thêm port vào Allow incoming TCP ports với port 10050. 10051. và thực hiện restart CSF bằng lệnh csf -r

Bước 8: Setup Zabbix

Bây giờ bạn truy cập Zabbix tại trình duyệt với URL như sau

  •  

    http://ip/zabbix hoặc http://server-host-name/zabbix

Ví dụ: http://zabbix.linuxcanban.com/zabbix

Tuy nhiên nếu bạn muốn truy cập thẳng vào ip hoặc url không cần thêm /zabbix thì bạn hãy tạo một virtuahost sau trong file /etc/httpd/conf/httpd.conf


DocumentRoot /usr/share/zabbix
ServerName monitor.linuxcanban.com

Bạn click chọn Next Step để đến các bước thực hiện

Install Zabbix Centos OS

Tiếp tục chọn Next Step

Install Zabbix Centos OS

Tại đây bạn nhập vào thông tin Database đã tạo ở Bước 5 và đã set trong file cấu hình ở trên

Install Zabbix Centos OS

Chổ Name bạn nhập tên vào

Install Zabbix Centos OS

Tiếp tục nhấn Next Step

Install Zabbix Centos OS

Thông báo Setup hoàn tất Zabbix

Install Zabbix Centos OS

Cửa sổ đăng nhập bây giờ bạn hãy đăng nhập với thông tin mặc định là

Username: admin
Password: zabbix

Install Zabbix Centos OS

Đây là cửa số quản trị.

Install Zabbix Centos OS

Bước tiếp tiếp theo mình sẽ hướng dẫn bạn thực hiện giám sát máy chủ với Zabbix Agent