top of page

HƯỚNG DẪN CÀI ĐẶT ZABBIX SERVER TRÊN CENTOS 7

Writer's picture: Tuan NguyenTuan Nguyen

Updated: Jul 16, 2018

Các bước thực hiện:

  • Cài apache

  • Cài đặt CSDL

  • Cài đặt PHP

  • Cài zabbix server



1. Cài đặt apache web server

# yum install httpd
# systemctl start httpd
# systemctl enable httpd

Kiểm tra apache đang lắng nghe trên port 80 hay chưa

# netstat -natp | grep httpd

Vào trình duyệt web gõ ip của zabbix server vào xem vào được web apache hay chưa, nếu không vào được thì kiểm tra xem firewall có mở port chưa.



Nếu dùng iptables thì mở port như sau:

# iptables -A INPUT -p tcp --match multiport --dports 80,443 -j ACCEPT

Nếu dùng firewalld thì mở port như sau:

# firewall-cmd --zone=public --permanent --add-port=80/tcp
# firewall-cmd --zone=public --permanent --add-port=443/tcp
# firewall-cmd --reload

Cài Virtualhost (bước này có thể không cần nếu không dùng virtualhost)

Vào DNS tạo New host (A or AAAA) trỏ về ip của zabbix server


Tạo thư mục chứa website zabbix

# cd /var/www
# mkdir -p zabbix.pivotalvietnam.com/public_html
# chown apache:apache /var/www/zabbix.pivotalvietnam.com/public_html/

Tạo thư mục chứa virtualhost file của website

# cd /etc/httpd/
# mkdir sites-available
# cd sites-available
# vim zabbix.pivotalvietnam.com.conf

<VirtualHost *:80>

ServerName zabbix.pivotalvietnam.com

ServerAlias wwww.zabbix.pivotalvietnam.com

DocumentRoot /var/www/zabbix.pivotalvietnam.com/public_html

ErrorLog /var/www/zabbix.pivotalvietnam.com/error.log

CustomLog /var/www/zabbix.pivotalvietnam.com/requests.log combined

</VirtualHost>


Tạo symbolic link cho website

# cd /etc/httpd/
# mkdir sites-enabled
# ln -s /etc/httpd/sites-available/zabbix.pivotalvietnam.com.conf /etc/httpd/sites-enabled/zabbix.pivotalvietnam.com.conf

Chỉnh lại file cấu hình apache

# vim /etc/httpd/conf/httpd.conf

Xuống cuối file thêm dòng sau

IncludeOptional sites-enabled/*.conf

Khởi động lại apache

# systemctl restart httpd

Kiểm tra cấu hình virtualhost đã hoạt động chưa

Vào trình duyệt web gõ tên miền zabbix.pivotalvietnam.com xem vào được là đã thành công.


2. Cài đặt MariaDB


2.1. Tạo repository MariDB

# vim /etc/yum.repos.d/MariaDB.repo

[mariadb]

name = MariaDB

baseurl = http://yum.mariadb.org/10.3/centos7-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1


2.2. Cài đặt MariaDB

# yum repolist
# yum install MariaDB-server MariaDB-client MariaDB-devel MariaDB-shared -y

2.3. Khởi động MariaDB

# systemctl start mysql
# systemctl enable mariadb

Thiết lập cấu hình ban đầu cho MariaDB

# mysql_secure_installation

Kiểm tra mysqld có đang listening hay chưa

# netstat -natp | grep mysqld

3. Cài đặt PHP


3.1. Cài repository REMI

# rpm -Uvh remi-release-7.rpm

Kích hoạt repo remi sử dụng cho PHP 7.0

# vim /etc/yum.repos.d/remi-php70.repo

Tìm section [remi-php70] kích hoạt enabled=1

[remi-php70]

name=Remi's PHP 7.1 RPM repository for Enterprise Linux 7 - $basearch

# baseurl=http://rpms.remirepo.net/enterprise/7/php70/$basearch/

# mirrorlist=https://rpms.remirepo.net/enterprise/7/php70/httpsmirror

mirrorlist=http://cdn.remirepo.net/enterprise/7/php70/mirror

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

# yum repolist

3.2. Tiến hành cài đặt PHP

# yum install --disablerepo=* --enablerepo=remi-php70 php php-mysql php-bcmath php-cli php-common php-devel php-embedded php-enchant php-mbstring php-mcrypt php-pdo php-xml -y
# yum install php-gd


4. Cài đặt zabbix server 3.4


Cài đặt Zabbix Server bằng cách cài đặt biên dịch mã nguồn chuẩn.


4.1. Các thiết lập cần thiết


4.1.1. Tạo user zabbix để chạy dịch vụ Zabbix Server Monitor

# useradd -m -s /sbin/nologin -g zabbix zabbix

4.1.2. Tạo thư mục chứa file .pid của Zabbix Server là file log của Zabbix Server cùng Zabbix Agentd local

# mkdir -p /var/run/zabbix
# chown zabbix: /var/run/zabbix/ -R
# mkdir -p /var/log/zabbix
# touch /var/log/zabbix/zabbix_server.log
# chown zabbix: /var/log/zabbix/ -R
# chmod 660 /var/log/zabbix/zabbix_server.log

Kiểm tra phiên bản phần mềm hỗ trợ cần thiết curl 7.20.0 trở lên.

# curl --version

Cài đặt các thư viện cần thiết.

# yum groupinstall "Development Tools" -y
# yum install libxml2 libxslt libxml2-devel net-snmp-devel curl-devel libevent libevent-devel -y

4.2. Download source Zabbix Server và cài đặt

Trang chủ Zabbix

# cd /opt
# tar xvf zabbix.tar.gz
# cd zabbix-3.4.11
# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
# make
# make install

Sau khi cài đặt compile xong thì mặc định file daemon binary (zabbix_server, zabbix_agentd, zabbix_proxy) sẽ nằm ở đường dẫn thư mục /usr/local/sbin/

Các file binary client (zabbix_get, zabbix_sender) sẽ nằm ở thư mục /usr/local/bin/

4.3. Tạo file khởi động zabbix _server


Nội dung file systemd service dành cho Zabbix Server trên CentOS 7, phải tự tạo file này để khởi động dịch vụ do khi compile sẽ không có.

# vim /lib/systemd/system/zabbix_server.service

[Unit]

Description=Zabbix Server

After=syslog.target network.target mysqld.service

[Service]

Type=oneshot

ExecStart=/usr/local/sbin/zabbix_server -c /usr/local/etc/zabbix_server.conf

ExecReload=/usr/local/sbin/zabbix_server -R config_cache_reload

RemainAfterExit=yes

PIDFile=/var/run/zabbix/zabbix_server.pid

[Install]

WantedBy=multi-user.target

4.4. Tạo nội dung file systemd cho dịch vụ Zabbix Agentd

# vim /lib/systemd/system/zabbix_agentd.service

[Unit]

Description=Zabbix Agent

After=syslog.target network.target network-online.target

Wants=network.target network-online.target

[Service]

Type=oneshot

ExecStart=/usr/local/sbin/zabbix_agentd -c /usr/local/etc/zabbix_agentd.conf

RemainAfterExit=yes

PIDFile=/var/run/zabbix/zabbix_agentd.pid

[Install]

WantedBy=multi-user.target


4.5. Cài đặt Database Zabbix Server

Cài đặt template mẫu schema CSDL cho zabbix, mặc định template này trong source zabbix mà lúc nãy ta đã tải ở trang chủ zabbix về.

4.5.1. Tạo CSDL cho zabbix

# mysql -u root -p
MariaDB [(none)]> create database zabbix_db character set utf8 collate utf8_bin;
MariaDB [(none)]> grant all privileges on zabbix_db.* to 'zabbix_admin'@'localhost' identified by 'testzabbix123';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> quit;

4.5.2 Import các mẫu table cho zabbix_db

# cd /opt/zabbix-3.4.11/database/mysql
# mysql -u zabbix_admin -p'testzabbix123' zabbix_db < schema.sql
# mysql -u zabbix_admin -p'testzabbix123' zabbix_db < images.sql
# mysql -u zabbix_admin -p'testzabbix123' zabbix_db < data.sql

4.6. Cấu hình dịch vụ Zabbix Server

# vim /usr/local/etc/zabbix_server.conf

LogFile=/var/log/zabbix/zabbix_server.log

LogFileSize=250

DebugLevel=3

PidFile=/var/run/zabbix/zabbix_server.pid

DBHost=localhost

DBName=zabbix_db

DBUser=zabbix_admin

DBPassword=testzabbix123

DBSocket=/var/lib/mysql/mysql.sock

DBPort=3306

CacheSize=32M

StartPingers=5

StartPollers=40

StartPollersUnreachable=40

StartTrappers=15

StartPingers=40

StartDiscoverers=10

AlertScriptsPath=/usr/local/share/zabbix/alertscripts

ExternalScripts=/usr/local/share/zabbix/externalscripts


4.7. Cấu hình dịch vụ Zabbix Agentd

# vi /usr/local/etc/zabbix_agentd.conf

PidFile=/var/run/zabbix/zabbix_agentd.pid

LogFile=/var/log/zabbix/zabbix_agentd.log

Server=127.0.0.1

ServerActive=127.0.0.1

Hostname=zabbix


4.8. Khởi động dịch vụ zabbix_server và zabbix_agentd

# systemctl start zabbix_server
# systemctl start zabbix_agentd
# systemctl enable zabbix_server
# systemctl enable zabbix_agentd

Nếu bị lỗi service nào thì vào xem log

# tailf /var/log/zabbix/zabbix_server.log
# tailf /var/log/zabbix/zabbix_agentd.log

Copy source Zabbix Frontend vào thư mục chứa website zabbix

# cp -rp /opt/zabbix-3.4.11/frontends/php/* /var/www/zabbix.pivotalvietnam.com/public_html/
# chown apache: -R /var/www/zabbix.pivotalvietnam.com/

4.9. Chỉnh lại file php.ini

# vim /etc/php.ini

Tìm và sửa các dòng sau

post_max_size = 16M

max_execution_time = 300

max_input_time = 300

date.timezone = Asia/Ho_Chi_Minh


4.10. Khởi động lại apache

# systemctl restart httpd

4.11. Cấu hình Zabbix Server trên giao diện


Gõ tên miền hoặc ip của zabbix server vào duyệt web

Các yêu cầu phải OK


Điền các thông số database đã tạo



Điền hostname của máy zabbix server vào ô Name


Xem lại tất cả thông tin cấu hình


Báo thành công


Giao diện đăng nhập:

Username: Admin

Password: zabbix


Done !



30 views0 comments

Recent Posts

See All

Comments


 

© 2018 by Tuấn Nguyễn

 Liên hệ tôi
  • Facebook - Black Circle
  • Google+ - Black Circle
bottom of page