CentOS Linux release 7.5.1804 (Core)
下載地址 http://mirrors.sohu.com/centos/7.5.1804/isos/x86_64/CentOS-7-x86_64-DVD-1804.iso
Zabbix5.0原始碼包
下載地址 https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.1.tar.gz
[root@bogon ~]# yum install net-snmp-devel libevent-devel -y
建立zabbix使用者組和使用者
[root@bogon ~]# groupadd zabbix
[root@bogon ~]# useradd -r -g zabbix zabbix
安裝zabbix服務
[root@bogon ~]# cd /usr/local/src/
[root@bogon src]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.1.tar.gz
或者通過上傳的方式上傳檔案
[root@bogon src]# mkdir /usr/local/data/
[root@bogon src]# tar -xzf zabbix-5.0.1.tar.gz -C /usr/local/data/
[root@bogon src]# cd /usr/local/data/zabbix-5.0.1/
[root@bogon zabbix-5.0.1]# ./configure --prefix=/usr/local/data/zabbix --enable-server --enable-agent --with-mysql=/usr/local/data/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2
此處報錯:
checking for mysql_config... /usr/local/data/mysql/bin/mysql_config
configure: error: MySQL library not found
解決辦法:
網際網路狀態下
Centos7.5安裝MySQL57
[root@bogon zabbix-5.0.1]# cd ..
[root@bogon data]# wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
[root@bogon data]# ls
mysql57-community-release-el7-10.noarch.rpm zabbix-5.0.1
[root@bogon data]# rpm -Uvh mysql57-community-release-el7-10.noarch.rpm
[root@bogon data]# yum install -y mysql-community-server
非網際網路狀態下
安裝MySql57
必要以下幾個包安裝就可以了
mysql-community-client-5.7.30-1.el7.x86_64
mysql-community-libs-compat-5.7.30-1.el7.x86_64
mysql57-community-release-el7-10.noarch
mysql-community-server-5.7.30-1.el7.x86_64
mysql-community-common-5.7.30-1.el7.x86_64
mysql-community-libs-5.7.30-1.el7.x86_64
啓動MySQL服務
[root@bogon data]# systemctl start mysqld.service
檢視MySQL狀態
[root@bogon data]# systemctl status mysqld.service
獲取MySQL臨時使用者名稱密碼
[root@bogon data]# grep 'temporary password' /var/log/mysqld.log
A temporary password is generated for root@localhost: nc(9k0u;Fzff
輸入MySQL的臨時密碼
[root@bogon data]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.30
因爲MySQL的密碼規則需要很複雜,我們一般自己設定的不會設定成這樣,所以我們全域性修改一下
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
設定自己想要的密碼
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
授權其他機器遠程登錄
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
開啓開機自啓動
[root@bogon data]# systemctl enable mysqld
[root@bogon data]# systemctl daemon-reload
設定MySQL的字元集爲UTF-8,令其支援中文
[root@bogon data]# vim /etc/my.cnf
改成如下,然後儲存
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysql]
default-character-set=utf8
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
default-storage-engine=INNODB
character_set_server=utf8
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
重新啓動一下MySQL,令設定生效
[root@bogon data]# systemctl restart mysqld
永久關閉selinux和防火牆
[root@bogon data]# vi /etc/selinux/config 將SELINUX=enforcing改爲SELINUX=disabled 設定後需要重新啓動才能 纔能生效
[root@bogon data]# systemctl stop firewalld.service
[root@bogon data]# systemctl disable firewalld.service
再次執行部署zabbix服務
[root@bogon zabbix-5.0.1]# ./configure --prefix=/usr/local/data/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
checking for xmlReadMemory in -lxml2... no
configure: error: Not found libxml2 library
解決辦法:
網際網路狀態下
[root@bogon zabbix-5.0.1]# yum install libxml2 libxml2-devel -y
非網際網路狀態下
安裝以下包
libxml2-python-2.9.1-6.el7.4.x86_64
libxml2-devel-2.9.1-6.el7.4.x86_64
libxml2-2.9.1-6.el7.4.x86_64
再次執行部署zabbix服務
[root@bogon zabbix-5.0.1]# ./configure --prefix=/usr/local/data/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
configure: error: Curl library not found
解決辦法:
網際網路狀態下
[root@bogon zabbix-5.0.1]# yum install curl-devel
非網際網路狀態下
安裝以下包
libcurl-7.29.0-57.el7.x86_64
libcurl-devel-7.29.0-57.el7.x86_64
python-pycurl-7.19.0-19.el7.x86_64
curl-7.29.0-57.el7.x86_64
再次執行部署zabbix服務
[root@bogon zabbix-5.0.1]# ./configure --prefix=/usr/local/data/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
[root@bogon zabbix-5.0.1]# make
[root@bogon zabbix-5.0.1]# make install
[root@bogon data]# vim /etc/profile
新增以下內容
# Zabbix Environment
export PATH=$PATH:/usr/local/data/zabbix/sbin/:/usr/local/data/zabbix/bin/
[root@localhost zabbix-4.2.6]# source /etc/profile
[root@bogon data]# mysql -uroot -p
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@‘localhost’ identified by ‘123456’;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
解決辦法:
mysql> show variables like 「%validate%」;
±-------------------------------------±-------+
| Variable_name | Value |
±-------------------------------------±-------+
| query_cache_wlock_invalidate | OFF |
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
±-------------------------------------±-------+
8 rows in set (0.00 sec)
mysql> set global validate_password_length=6;
Query OK, 0 rows affected (0.00 sec)mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)mysql> show variables like 「%validate%」;
±-------------------------------------±------+
| Variable_name | Value |
±-------------------------------------±------+
| query_cache_wlock_invalidate | OFF |
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 6 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 1 |
±-------------------------------------±------+
8 rows in set (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@‘localhost’ identified by ‘123456’;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> set names utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> use zabbix;
Database changed
mysql> source /usr/local/data/zabbix-5.0.1/database/mysql/schema.sql
mysql> source /usr/local/data/zabbix-5.0.1/database/mysql/data.sql
mysql> source /usr/local/data/zabbix-5.0.1/database/mysql/images.sql
編輯zabbix_server的組態檔
[root@bogon mysql]# find / -name zabbix_server.conf
/usr/local/data/zabbix-5.0.1/conf/zabbix_server.conf
/usr/local/data/zabbix/etc/zabbix_server.conf
[root@bogon mysql]# vim /usr/local/data/zabbix/etc/zabbix_server.conf
###Option: LogFile
LogFile=/usr/local/data/zabbix/logs/zabbix_server.log
###Option: LogFileSize
LogFileSize=0
###Option: DBHost
DBHost=localhost
###Option: DBName
DBName=zabbix
###Option: DBUser
DBUser=zabbix
###Option: DBPassword
DBPassword=lixiaozhe
###Option: DBSocket
DBSocket=/tmp/mysql.sock
###Option: DBPort
DBPort=3306
###Option: Timeout
Timeout=30
###Option: AlertScriptsPath
AlertScriptsPath=/usr/local/data/zabbix/alertscripts
###Option: ExternalScripts
ExternalScripts=/usr/local/data/zabbix/externalscripts
###Option: LogSlowQueries
LogSlowQueries=3000
授權建立相關資料夾
[root@bogon mysql]# mkdir /usr/local/data/zabbix/logs
[root@bogon mysql]# mkdir /usr/local/data/zabbix/pid
[root@bogon mysql]# chown -R zabbix:zabbix /usr/local/data/zabbix/
安裝PHP73
網際網路狀態下
首先安裝 EPEL 源
yum install epel-release
安裝 REMI 源
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
安裝 Yum 源管理工具:
yum install yum-utils
非網際網路狀態下
安裝remi-release-7.rpm
安裝 PHP7.3:
yum install -y php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip php73-php-recode php73-php-snmp php73-php-soap php73-php-xmll
設定開機自啓
systemctl enable php73-php-fpm
啓動PHP服務
systemctl start php73-php-fpm
[root@bogon data]# vim /etc/ld.so.conf
/usr/local/lib /新增此路徑/
[root@bogon data]# ldconfig
啓動zabbix
[root@bogon data]# zabbix_server
殺死進程
[root@bogon data]# ps -ef | grep zabbix_server | grep -v grep | awk ‘{print $2}’ | xargs kill -9
建立服務檔案
[root@bogon data]# vim /usr/lib/systemd/system/zabbix-server.service
[Unit]
Description=Zabbix
After=network.target[Service]
Environment=「CONFFILE=/usr/local/data/zabbix/etc/zabbix_server.conf」
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/data/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s[Install]
WantedBy=multi-user.target[root@bogon zabbix-5.0.1]# systemctl daemon-reload
[root@bogon zabbix-5.0.1]# systemctl enable zabbix-server
[root@bogon zabbix-5.0.1]# systemctl stop zabbix-server
[root@bogon zabbix-5.0.1]# systemctl start zabbix-server
[root@bogon zabbix-5.0.1]# systemctl restart zabbix-server
安裝nginx
[root@bogon data]# wget http://nginx.org/download/nginx-1.9.9.tar.gz
[root@bogon data]# tar -zxvf nginx-1.9.9.tar.gz
[root@bogon data]# cd nginx-1.9.9/
[root@bogon data]# ./configure
[root@bogon data]# make
[root@bogon data]# make install
[root@bogon data]# cd /usr/local/nginx/sbin/
[root@bogon data]# ./nginx
[root@bogon data]# ps -ef | grep nginx
[root@bogon zabbix-5.0.1]# mkdir -p /usr/local/nginx/html/zabbix
[root@bogon zabbix-5.0.1]# cp -a /usr/local/data/zabbix-5.0.1/ui/* /usr/local/nginx/html/zabbix/
zabbix_web需要php設定優化,編輯php.ini檔案
[root@bogon zabbix-5.0.1]# find / -name php.ini
/etc/opt/remi/php73/php.ini
修改如下內容:
max_execution_time = 30 修改爲350-(zabbix_web優化)
max_input_time = 60 修改爲350-(zabbix_web優化)
post_max_size = 8M 修改爲32M-(zabbix_web優化)
date.timezone = Asia/Shanghai 新增-(zabbix_web優化)
找到設定cgi.fix_pathinfo的參數, 這將用分號(;)註釋掉,預設設定爲「1」
cgi.fix_pathinfo=0
[root@bogon zabbix-5.0.1]# systemctl restart php73-php-fpm
[root@bogon zabbix-5.0.1]# vim /lib/systemd/system/nginx.service
[UNIT]Deion=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
[root@bogon zabbix-5.0.1]# systemctl daemon-reload
[root@bogon zabbix-5.0.1]# systemctl enable nginx
[root@bogon zabbix-5.0.1]# systemctl stop nginx
[root@bogon zabbix-5.0.1]# systemctl start nginx
若啓動失敗,重新啓動伺服器
[root@bogon zabbix-5.0.1]# systemctl restart nginx
設定nginx檔案使PHP頁面生效
[root@bogon zabbix-5.0.1]# vim /usr/local/nginx/conf/nginx.conf
listen - 定義Nginx將偵聽的埠。
root - 定義儲存網站服務的文件根目錄。
index- 設定Nginx請求索引檔案時優先處理index.php命名的檔案。
server_name - 將此指令指向伺服器的域名或公共IP地址。
location /- 第一個位置塊包括一個try_files指令,該指令檢查是否存在滿足URI請求的檔案。如果Nginx找不到合適的檔案,則會返回404錯誤。
location ~ .php$- 此位置塊通過將Nginx指向fastcgi-php.conf組態檔和php7.2-fpm.sock檔案來處理實際的PHP處理,該檔案宣告瞭與哪個通訊端相關聯php-fpm。檢查/etc/php/7.0/fpm/pool.d/www.conf檔案並查詢「listen」行。
location ~ /.ht- 通過新增deny all指令,如果任何.htaccess檔案碰巧進入文件根目錄,它們將不會被提供給存取者。
修改如下內容:
user root;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
root /usr/local/nginx/html/zabbix;
index index.php index.html index.htm;
location / {
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/local/nginx/html;
#}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
驗證nginx組態檔語法錯誤
[root@bogon zabbix-5.0.1]# sudo nginx -t
[root@bogon zabbix-5.0.1]# systemctl reload nginx
[root@bogon zabbix-5.0.1]# nginx -s reload #重新載入組態檔
[root@bogon zabbix-5.0.1]# systemctl restart nginx
然後存取http://IP
預設點選下一步
出現報錯
PHP xmlwriter extension missing zabbix
PHP xmlreader extension missing zabbix
解決辦法:
檢查/etc/php.ini
修改內容如下:
找到自己的xmlwriter.so和xmlreader.so路徑位置
extension=/usr/lib64/php/modules/xmlwriter.so
extension=/usr/lib64/php/modules/xmlreader.so
再次啓動
檢視是否有報錯
[root@bogon zabbix-5.0.1]# php73 -v
最終儲存檔案需要上傳到伺服器本地路徑
字型顯示異常
解決辦法:
/usr/local/nginx/html/zabbix/assets/fonts
將Win10操作系統C:\Windows\Fonts目錄下的任意字型,拷貝到此目錄,更改後綴爲’.ttf’
修改php指令碼檔案/usr/local/nginx/html/zabbix/include/defines.inc.php
define('ZBX_GRAPH_FONT_NAME', 'msyh'); // font file name
define('ZBX_FONT_NAME', 'msyh');
重新啓動zabbix服務
重新啓動nginx服務
[root@bogon zabbix-5.0.1]# systemctl restart zabbix-server
[root@bogon zabbix-5.0.1]# systemctl restart nginx
2 安裝zabbix-agent
2.1 wget http://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-agent-5.0.1-1.el7.x86_64.rpm
rpm -ivh zabbix-agent-5.0.1-1.el7.x86_64.rpm
2.2 設定
[root@db01 ~]# vim /etc/zabbix/zabbix_agentd.conf
147 Hostname=db01 #本機的主機名
95 Server=192.168.1.63 #zabbix伺服器的地址,使用內網地址
2.3 啓動
[root@db01 ~]# systemctl start zabbix-agent.service
[root@db01 ~]# systemctl enable zabbix-agent.service
[root@db01 ~]# netstat -lntup|grep zabbix_agentd
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 2311/zabbix_agentd
tcp6 0 0 :::10050 :::* LISTEN 2311/zabbix_agentd
2.4 web介面操作
2.4.1 在面板中依次點選:設定——>主機——>建立主機(如果前面新增了主機也可以選擇克隆主機,修改資訊進行新增)
填寫主機資訊
選擇模板
新增完後點擊新增,稍等一會兒狀態變爲綠色。至此,用戶端主機新增完成!
3、調整觸發器設定
使用模板所預設的觸發器設定的閾值,在當前虛擬機器的環境中會不適用,啓用模板機會發生報警情況,因此需要進行設定
在面板中依次點選:設定——>模板——>Template OS Linux——>觸發器——>Too many processes,根據實際情況調整值爲合適的大小,以及修改觸發器的嚴重性
4、開啓聲音告警
在面板中依次點選:使用者——>警報聲音,開啓聲音提醒——>更新,設定完成後,從下次採集數據開始,如果觸發了觸發器定義的規則,系統將發出報警聲音
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
systemctl start php73-php-fpm
/usr/local/data/zabbix/sbin/zabbix_server -c /usr/local/data/zabbix/etc/zabbix_server.conf
systemctl restart zabbix-agent