虽然zabbix已经玩了好多遍了,但每次重新部署时,还得到处找,今天抽空整理下文档,以后就可以直接复制粘贴了,哈哈

环境说明

环境:
  centos 7.4
  zabbix 3.4.11
  mysql 5.6
  php 5.4
  nginx 12.2

zabbix 3.4环境要求:
参考:zabbix requirements

  • MySQL 5.0.3 - 5.7.x
  • PHP 5.4.0 or later

安装yum源

1
2
3
4
5
6
7
[root@localhost ~]# wget https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
[root@localhost ~]# wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
#如果网络不好,可以用epel源自带的php5.4
[root@localhost ~]# wget https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[root@localhost ~]# wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/3.4.11/zabbix-3.4.11.tar.gz
[root@localhost ~]# yum -y install epel-release-latest-7.noarch.rpm mysql80-community-release-el7-1.noarch.rpm webtatic-release.rpm

安装依赖包

1
[root@localhost ~]# yum -y install yum-utils gcc gcc-c++ make libxml2 libxml2-devel libjpeg-devel libpng-devel bzip2-devel libcurl-devel gd-devel net-snmp-devel libevent-devel

部署PHP

如果能使用webtatic源的话,可以安装高版本的PHP。这里用不了webtatic的yum源。-_-!!!

1
2
3
4
#安装php5.4
[root@localhost ~]# yum -y install php php-mysql php-gd libjpeg* php-imap php-odbc libmcrypt libmcrypt-devel php-fpm php-cli php-bcmath php-mbstring php-xml
#安装php70w
[root@localhost ~]# yum install php70w php70w-cli php70w-common php70w-fpm php70w-gd php70w-devel php70w-imap php70w-mysql php70w-odbc php70w-bcmath php70w-mbstring php70w-xml

1
2
3
4
5
6
7
8
9
10
11
12
#配置PHP
[root@localhost ~]# sed -i '/max_execution_time/s/30/300/' /etc/php.ini
[root@localhost ~]# sed -i '/post_max_size/s/8/16/' /etc/php.ini
[root@localhost ~]# sed -i '/max_input_time/s/60/300/' /etc/php.ini
[root@localhost ~]# sed -i '/^;date.timezone/adate.timezone \= \"Asia\/Shanghai\"' /etc/php.ini
#yum安装的php下面配置不需要修改
[root@localhost ~]# sed -i '/run\/php-fpm.pid/s/^;//g' /etc/php-fpm.d/www.conf
[root@localhost ~]# sed -i '/^;pm.min_spare_servers/s/^;//g' /etc/php-fpm.d/www.conf
[root@localhost ~]# sed -i '/^;pm.max_spare_servers/s/^;//g' /etc/php-fpm.d/www.conf
[root@localhost ~]# sed -i '/^;pm.start_servers/s/^;//g' /etc/php-fpm.d/www.conf
[root@localhost ~]# systemctl enable php-fpm
[root@localhost ~]# systemctl start php-fpm

部署Mysql 5.6

这里也操作了mysql迁移DATA目录

1
2
3
4
5
[root@localhost ~]# yum-config-manager --disable mysql80-community
[root@localhost ~]# yum-config-manager --enable mysql56-community
[root@localhost ~]# yum install -y mysql-community-server.x86_64 mysql-community-devel.x86_64 mysql-community-common.x86_64 mysql-community-client.x86_64
[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# systemctl start mysqld

迁移mysql data目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[root@localhost ~]# mysql -u root
mysql> use mysql
mysql> update user set password=password('123456') where user='root';
mysql> SELECT Host,User,password_expired FROM user;
mysql> update user set host='192.168.%.%',password_expired='N' where host='127.0.0.1';
mysql> grant all privileges on *.* to 'root'@'localhost' identified by '123456' with grant option;
mysql> grant all privileges on *.* to 'root'@'192.168.%.%' identified by '123456' with grant option;
mysql> flush privileges;
mysql> commit;
mysql> show global variables like "%datadir%";
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| datadir | /var/lib/mysql/ |
+---------------+-----------------+
1 row in set (0.00 sec)
mysql> quit
[root@localhost ~]# systemctl stop mysqld
[root@localhost ~]# mkdir -p /data
[root@localhost ~]# mv /var/lib/mysql /data/mysql_data
[root@localhost ~]# grep -iv '#' /etc/my.cnf | grep -iv '^$'
[mysqld]
#修改为新目录
datadir=/data/mysql_data
socket=/data/mysql_data/mysql.sock
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#添加
[client]
socket=/data/mysql_data/mysql.sock
[root@localhost ~]# systemctl start mysqld

部署zabbix

1
2
3
4
5
[root@localhost ~]# useradd -s /sbin/nologin zabbix
[root@localhost ~]# tar -zxf zabbix-3.4.11.tar.gz
[root@localhost ~]# cd zabbix-3.4.11
[root@localhost zabbix-3.4.11]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
[root@localhost zabbix-3.4.11]# make && make install
1
2
#在编译zabbix-server时,`--enable-java`需要安装下面这个依赖包
[root@localhost ~]# yum install -y java*
初始化数据库
1
2
3
4
5
6
7
[root@localhost ~]# mysql -uroot -p123456
mysql> create database zabbix default charset utf8;
mysql> grant all privileges on zabbix.* to zbxuser@localhost identified by 'zbxpass';
mysql> grant all privileges on zabbix.* to zbxuser@'192.168.%.%' identified by 'zbxpass';
mysql> flush privileges;
mysql> commit;
mysql> quit
1
2
3
4
[root@localhost ~]# cd zabbix-3.4.11
[root@localhost zabbix-3.4.11]# mysql -uzbxuser -pzbxpass zabbix < database/mysql/schema.sql
[root@localhost zabbix-3.4.11]# mysql -uzbxuser -pzbxpass zabbix < database/mysql/images.sql
[root@localhost zabbix-3.4.11]# mysql -uzbxuser -pzbxpass zabbix < database/mysql/data.sql
配置zabbix
1
2
3
4
5
6
7
[root@localhost ~]# sed -i '/LogFile/s/tmp/var\/log\/zabbix/' /usr/local/zabbix/etc/zabbix_server.conf
[root@localhost ~]# sed -i '/^DBUser\=/s/root/zbxuser/' /usr/local/zabbix/etc/zabbix_server.conf
[root@localhost ~]# sed -i '/# DBPassword/aDBPassword=zbxpass' /usr/local/zabbix/etc/zabbix_server.conf
[root@localhost ~]# sed -i '/# DBPort/aDBPort=3306' /usr/local/zabbix/etc/zabbix_server.conf
[root@localhost ~]# sed -i '/^Timeout/s/4/30/' /usr/local/zabbix/etc/zabbix_server.conf
#如果修改了数据库的data目录,也需要修改zabbix server配置文件
[root@localhost ~]# sed -i '/^# DBSocket/aDBSocket=/data/mysql_data/mysql.sock' /usr/local/zabbix/etc/zabbix_server.conf
1
2
3
4
[root@localhost ~]# sed -i '/^Server/s/127.0.0.1/192.168.1.202/g' /usr/local/zabbix/etc/zabbix_agentd.conf
[root@localhost ~]# sed -i "/^ServerActive/s/127.0.0.1/192.168.1.202:10051/g" /usr/local/zabbix/etc/zabbix_agentd.conf
[root@localhost ~]# sed -i "/^Hostname/s/Zabbix server/192.168.1.202/g" /usr/local/zabbix/etc/zabbix_agentd.conf
[root@localhost ~]# sed -i '/^LogFile/s/tmp/var\/log\/zabbix/' /usr/local/zabbix/etc/zabbix_agentd.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@localhost ~]# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
[root@localhost ~]# ln -s /usr/local/zabbix/bin/* /usr/local/sbin/
[root@localhost ~]# mkdir -p /var/log/zabbix
[root@localhost ~]# touch /var/log/zabbix/{zabbix_agentd.log,zabbix_server.log}
[root@localhost ~]# chown zabbix:zabbix /var/log/zabbix/ -R
[root@localhost ~]# /usr/local/zabbix/sbin/zabbix_server -c /usr/local/zabbix/etc/zabbix_server.conf
[root@localhost ~]# /usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf
#或者用启动脚本启动,zabbix源码自带启动脚本
[root@localhost ~]# cp -a zabbix-3.4.11/misc/init.d/fedora/core/zabbix_* /etc/init.d/
[root@localhost ~]# chmod +x /etc/init.d/zabbix_*
[root@localhost ~]# /etc/init.d/zabbix_server restart
[root@localhost ~]# /etc/init.d/zabbix_agentd restart

部署Nginx

1
2
3
4
5
6
[root@localhost ~]# yum install -y nginx
[root@localhost ~]# mkdir /usr/share/nginx/html/zabbix
[root@localhost ~]# cd zabbix-3.4.11
[root@localhost zabbix-3.4.11]# cp -a frontends/php/* /usr/share/nginx/html/zabbix/
[root@localhost ~]# chown zabbix:zabbix /usr/share/nginx/html/zabbix/ -R
[root@localhost ~]# chmod o+w /usr/share/nginx/html/zabbix/conf -R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[root@localhost ~]# cat /etc/nginx/conf.d/zabbix.conf
server {
listen 80;
server_name 192.168.1.202;
root /usr/share/nginx/html;
access_log /var/log/nginx/zabbix_access.log main;
error_log /var/log/nginx/zabbix_error.log warn;
location /zabbix {
index index.php;
try_files $uri $uri/ /index.php?$args;
}
location ~ ^(.+.php)(.*)$ {
fastcgi_buffer_size 128k;
fastcgi_buffers 32 32k;
fastcgi_split_path_info ^(.+.php)(.*)$;
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
[root@localhost ~]#
[root@localhost ~]# systemctl enable nginx
[root@localhost ~]# systemctl start nginx

效果图

zabbix_install

如果点”next step”没有反应,需要检查下/var/lib/php/session权限,如果没有这个目录就新建一个并授权777
zabbix_install
zabbix_install
zabbix_install
zabbix_install
zabbix_install
zabbix_login
zabbix_dashboard

附件:
epel-release-latest-7.noarch
mysql80-community-release-el7-1.noarch
webtatic-release
zabbix-3.4.11.tar.gz


本文出自”Jack Wang Blog”:http://www.yfshare.vip/2018/06/30/部署Zabbix-3-4/