環(huán)境依賴
- CentOS 7.3 + PHP5.4 + MariaDB + Nginx
- Zabbix Server 3.4.1
環(huán)境要求
- 12 CPU 桩卵,最少8 CPU
- 32G 內(nèi)存,最少16G
- 1T 硬盤胜嗓,最少500G钩乍,最好用RAID,如果監(jiān)控的服務(wù)器數(shù)量較多变过,建議采用RAID10
安裝過程
- 安裝CentOS7.3涝涤,分區(qū)如下
/boot 500M
swap 16G
/ 50G
/var 剩下所有空間,如果做了RAID崭孤,建議將RAID劃分給 /var
- 關(guān)閉Firewalld和SElinux
# systemctl disable firewalld.service && systemctl stop firewalld.service
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
# setenforce 0
- 安裝zabbix server YUM源
# yum -y install vim wget lsof net-tools -y
# wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
# rpm -ivh zabbix-release-3.4-2.el7.noarch.rpm
# yum install zabbix-server-mysql zabbix-web-mysql -y
- 安裝Nginx+PHP+MariaDB
# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# yum install php php-fpm mariadb mariadb-server nginx -y
- 復(fù)制www目錄
# mkdir -p /data/html/zabbix
# cd /usr/share/zabbix/ && cp -r * /data/html/zabbix/
# chown -Rf /data/html/zabbix/* && chmod -Rf 755 /data/html/zabbix/*
- 配置Nginx+HTTPS
生成自簽名證書辨宠,先創(chuàng)建一個(gè)存放證書的目錄
# mkdir -p /etc/nginx/cert && cd /etc/nginx/cert
創(chuàng)建服務(wù)器私鑰,會(huì)提示輸入一個(gè)口令
# openssl genrsa -des3 -out nginx.key 2048
創(chuàng)建簽名請(qǐng)求的證書(CSR)
# openssl req -new -key nginx.key -out nginx.csr
加載SSL支持的Nginx并使用上述私鑰時(shí)除去必須的口令
# cp nginx.key nginx.key.org
# openssl rsa -in nginx.key.org -out nginx.key
標(biāo)記證書使用上述私鑰和CSR
# openssl x509 -req -days 365 -in nginx.csr -signkey nginx.key -out nginx.crt
備份默認(rèn)配置文件
# cd /etc/nginx/conf.d/ && mv default.conf default.conf.back
編輯新的zabbix.conf
# vim /etc/nginx/conf.d/zabbix.conf
寫入以下內(nèi)容
···
#http
server {
listen 80;
server_name localhost;
rewrite ^(.*) https://192.168.1.1$1 permanent;
#為了安全起見彭羹,配置了80重定向到443,IP地址自己根據(jù)環(huán)境定義
location / {
root /data/html/zabbix/;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /data/html/zabbix/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/html/zabbix/$fastcgi_script_name;
include fastcgi_params;
}
}
#https
server {
listen 443;
server_name localhost;
ssl on;
ssl_certificate /etc/nginx/cert/nginx.crt;
ssl_certificate_key /etc/nginx/cert/nginx.key;
ssl_protocols SSLv3 SSLv2 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
location / {
root /data/html/zabbix/;
index index.html index.htm index.php;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /data/html;
}
location ~ \.php$ {
root /data/html/zabbix/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/html/zabbix/$fastcgi_script_name;
include fastcgi_params;
}
}
- 配置數(shù)據(jù)庫(kù)
啟動(dòng)數(shù)據(jù)庫(kù)
# systemctl start mariadb.service && systemctl enable mariadb.service
設(shè)置數(shù)據(jù)庫(kù)root管理員的密碼
# mysqladmin -u root password "Talent123"
登錄數(shù)據(jù)庫(kù)
# mysql -uroot -pTalent123
mysql> create database zabbix character set utf8; //創(chuàng)建zabbix數(shù)據(jù)庫(kù)
mysql> insert into mysql.user(Host,User,Password) values("localhost","admin",password("Talent123")); //添加admin用戶
mysql> flush privileges; //刷新權(quán)限表
mysql> grant all privileges on zabbix.* to admin@localhost identified by 'Talent123'; //將zabbix授權(quán)給admin
mysql> flush privileges; //刷新權(quán)限表
mysql> exit
# cd /usr/share/doc/zabbix-server-mysql-3.4.1
# gunzip create.sql.gz
# mysql -uadmin -pTalent123 zabbix < create.sql
# systemctl restart mariadb.service
提示
上面導(dǎo)入初始數(shù)據(jù)庫(kù)的方法可能存在問題,我是選取了最笨的辦法毡惜,先下載了zabbix-3.4.1.tar.gz
# wget https://sourceforge.net/projects/zabbix/files/latest/zabbix-3.4.1.tar.gz
# tar -zxvf zabbix-3.4.1.tar.gz
# cd zabbix-3.4.1
導(dǎo)入數(shù)據(jù)
# mysql -uroot -p zabbix < database/mysql/schema.sql
# mysql -uroot -p zabbix < database/mysql/data.sql
# mysql -uroot -p zabbix < database/mysql/images.sql
# service mariadb restart
- 配置PHP斯撮,修改php.ini
# vim /etc/php.ini
···
date.timezone = Asia/Shanghai
upload_max_filesize 2M
max_execution_time = 300
max_input_time = 300
post_max_size = 32M
memory_limit = 128M
···
啟動(dòng)php-fpm
# service php-fpm start && chkconfig php-fpm on
啟動(dòng)nginx
# systemctl enable nginx.service && systemctl start nginx.service
- 配置zabbix_server
# vim /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=admin
DBPassword=Talent123
啟動(dòng)zabbix server
# service zabbix-server start && chkconfig zabbix-server on
- 安裝zabbix-agent
RHEL6系列按照如下命令安裝
# wget http://repo.zabbix.com/zabbix/3.4/rhel/6/x86_64/zabbix-agent-3.4.1-1.el6.x86_64.rpm
# yum install zabbix-agent-3.4.1-1.el6.x86_64.rpm -y
RHEL7系列按照如下命令安裝
# wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.1-1.el7.x86_64.rpm
# yum install zabbix-agent-3.4.1-1.el7.x86_64.rpm -y
修改agent客戶端的配置文件
# vim /etc/zabbix/zabbix_agentd.conf
修改y以下地方內(nèi)容
···
Server=192.168.1.1
ServerActive=192.168.1.1
#Hostname和自己的主機(jī)名不一致沒關(guān)系,但是必須和在zabbix監(jiān)控平臺(tái)添加時(shí)的主機(jī)名一致帕膜,否則會(huì)產(chǎn)生錯(cuò)誤日志
Hostname=ad1.cloud.top
···
- 啟動(dòng)zabbix-agent客戶端服務(wù)
# service zabbix-agent start && chkconfig zabbix-agent on