1. 安装软件准备
1.1. 软件准备
1.zabbix-2.4.8.tar.gz zabbix-3.0.31.tar.gz
下载地址:https://www.zabbix.com/download
2.php5.4.16.tar.gz
下载地址:https://www.php.net/downloads.php
1.2. 注意事项
安装过程路径、密码尽量不要出现中文、特殊字符、空格、少于8位密码。
注意不可以跨版本升级
2. 环境准备
2.1. 配置 /etc/hosts
IP 主机名 用途
10.10.10.181 zabbixserver 监控服务器
2.2. 应用部署路径说明
应用名称
路径
Apache配置文件:/etc/httpd/conf/httpd.conf
Apache发布路径:/var/www/html
Zabbix安装路径:/usr/local/zabbix
Zabbix配置文件:/usr/local/zabbix/etc/zabbix_server.conf
Php配置文件:/etc/php.ini
Mysql安装路径:/var/lib/mysql/
2.3. 防火墙开放端口
Ø 根据上表端口规划情况,在不同服务器操作开放相应端口
# firewall-cmd --permanent --zone=public --add-port=3306/tcp# firewall-cmd --permanent --zone=public --add-port=80/tcp
Ø 重启防火墙
# firewall-cmd --reload
2.4. 关闭SELINUX
# sed -i "s@SELINUX=enforcing@SELINUX=disabled@g" /etc/selinux/config# cat /etc/selinux/config | grep SELINUX=# setenforce 0
3. Mysql与zabbix相关备份
1、Mysql备份
# /etc/init.d/zabbix_server stop# /etc/init.d/zabbix_agentd stop# mkdir /opt/bak && cd /opt/bak# mysqldump -uroot -p zabbix > /opt/bak/zabbix.sql
2、zabbix配置备份
# cp /usr/local/zabbix/etc/zabbix_server.conf /opt/bak# cp /etc/php.ini /opt/bak# cp /etc/httpd/conf/httpd.conf /opt/bak# cp -R /var/www/html/* /opt/bak/html/
4. LAMP环境准备
4.1. 依赖包安装
# yum install httpd php php-gd gcc php-mysql php-xml libcurl-devel curl-* net-snmp* libxml2-* bcmath mbstring php-devel lrzsz wget vim zip unzip net-tools ntpdate ntp php-bcmath php-mbstring-y
4.2. 创建用户
# useradd zabbix -s /sbin/nologin -M
4.3. Mysql安装
参照我的头条文章:CentOS7.x生产环境MySQL社区版yum方式部署
4.4. 建库导入
SQL> create database zabbix;SQL> grant all on zabbix.* to zabbix@localhost identified by 'zabbixpwd123';SQL> flush privileges;# mysql -uroot -p zabbix < /opt/bak/zabbix.sql
4.5. 配置系统内核参数
# vi /etc/sysctl.confkernel.shmmax = 34359738368kernel.shmmni = 4096kernel.shmall = 8388608kernel.sem = 1010 129280 1010 128net.ipv4.ip_local_port_range = 9000 65500net.core.rmem_default = 4194304net.core.rmem_max = 4194304net.core.wmem_default = 262144net.core.wmem_max = 1048576fs.aio-max-nr = 1048576fs.file-max = 6815744# /sbin/sysctl -p
4.6. 修改系统资源限制
# vi /etc/security/limits.conf* soft nproc 2047* hard nproc 16384* soft nofile 1024* hard nofile 65536* soft stack 10240
5. Zabbix2.4.8部署
5.1. Zabbix安装部署
1、下载路径:
# cd /opt/ && wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.4.8/zabbix-2.4.8.tar.gz/download?use_mirror=nchc&download=
2、上传zabbix-2.4.8.tar.gz到服务器/opt目录下面
# tar -zxvf zabbix-2.4.8.tar.gz
3、进行编译安装zabbix_server
# find / -name mysql_config# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/var/lib/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2# make && make install# cd /opt/zabbix-2.4.8/misc/init.d/fedora/core# cp zabbix_server /etc/init.d/# cp zabbix_agentd /etc/rc.d/init.d/# chmod +x /etc/rc.d/init.d/zabbix_*# vim /etc/rc.d/init.d/zabbix_serverBASEDIR=/usr/local/zabbix# vim /etc/rc.d/init.d/zabbix_agentdBASEDIR=/usr/local/zabbix# chkconfig zabbix_server on# chkconfig --add zabbix_server# chkconfig zabbix_agentd on# chkconfig --add zabbix_agentd# cp /opt/bak/zabbix_server.conf /usr/local/zabbix/etc# cd /opt/ && wget http://www.fping.org/dist/fping-4.2.tar.gz# tar -zxvf fping-4.2.tar.gz && cd fping-4.2/# ./configure && make && make install# which fping/usr/local/sbin/fping# find / -name mysql.sock# mkdir /usr/lib/zabbix/alertscripts -p# chown -R zabbix:zabbix /usr/lib/zabbix# egrep -v "^#|^$" /usr/local/zabbix/etc/zabbix_server.conf
#备注:如果数据库与zabbix_server是异机时参数DBHost的配置要修改为对应数据库IP,并注释DBSocket配置;如果机器是相同时要核对DBSocket的具体路径。
LogFile=/tmp/zabbix_server.logDBHost=localhostDBName=zabbixDBUser=zabbixDBPassword=密码DBSocket=/var/lib/mysql/mysql.sockStartPollers=20AlertScriptsPath=/usr/lib/zabbix/alertscriptsFpingLocation=/usr/local/sbin/fping
5.2. Web配置
# cd /var/www/html/# cp -R /opt/zabbix-2.4.8/frontends/php/* .# chown -R apache:apache *# cp /opt/bak/php.ini /etc/# vim /etc/httpd/conf/httpd.conf#将如下代码段#ServerName www.example.com:80---修改为ServerName localhost:80#模块中注意添加php对应版本的支持DirectoryIndex index.html index.phpAddType application/x-httpd-php .php .php3 .php4 .php5# systemctl restart httpd
5.3. 登录Zabbix的Web配置界面
1、 在浏览器中打开访问地址:http://10.10.10.181/setup.php
2、检查系统环境,必须全部ok才能继续
安装时检查系统环境时的错误提示:出现bcmath与mbstring显示为fail
解决方法:安装对应php版本的依赖库
# rpm –qa | grep php-devel# yum -y install php-devel# cd /opt && tar -zxf php-5.4.16.tar.gz# cd php-5.4.16/ext/bcmath/# which phpize/usr/bin/phpize# find / -name php-config/usr/bin/php-config# /usr/bin/phpize# ./configure --with-php-config=/usr/bin/php-config# make && make install# ll /usr/lib64/php/modules/# ll /opt/php-5.4.16/ext/bcmath/modules# cd ../mbstring/# /usr/bin/phpize# ./configure --with-php-config=/usr/bin/php-config# make && make install# systemctl restart httpd
如果还是出现fail则直接指定库位置,再重启httpd服务
# vim /etc/php.iniextension=/usr/lib64/php/modules/bcmath.soextension=/usr/lib64/php/modules/mbstring.so
3、配置mysql数据连接
Test connection #显示ok表示通过
如下图所示的错误时,原因是zabbix_server默认会去读取/var/lib/mysql/下的mysql.sock 解决办法是创建该路径,并创建软连接,操作指令如下
# mkdir /var/lib/mysql# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock# chown -R mysql:mysql /var/lib/mysql# vi /etc/php.inimysql.default_socket = /var/lib/mysql/mysql.sock# systemctl restart httpd
同时将Database host修改为127.0.0.1
4、5直接点击Next
6点击Finish(如果提示无法创建,需要手工下载提示的zabbix.conf.php ,并将其上传到服务器/var/www/html/conf/路径下)
最后的登录用户/密码:admin/zabbix
5.4. 解决中文显示与乱码问题
1、解决中文问题
到server的web界面。点击右上角profile,看是否在语言项是否有中文,要是有,直接勾选保存,web界面就可以显示中文,要是没有中文选项,那么进行一下配置。
# vim /var/www/html/include/locales.inc.phpzh_CN' => array('name' => _('Chinese (zh_CN)'), 'display' => false),---修改为'zh_CN' => array('name' => _('Chinese (zh_CN)'), 'display' => true),
重启zabbix_server服务:
# service zabbix_server restart# service zabbix_agentd restart
2、中文乱码问题,在图形等界面部分字体存在乱码问题
将本机C:WindowsFontssimkai.ttf上传到服务器/var/www/html/fonts/
# vim /var/www/html/include/defines.inc.phpdefine('ZBX_GRAPH_FONT_NAME', 'DejaVuSans');---修改为define('ZBX_GRAPH_FONT_NAME', 'simkai');重启zabbix_server服务:# service zabbix_server restart
6. Zabbix2.4.8升级至3.0.31
6.1. Zabbix2.4.8相关文件备份
# mkdir /opt/bak24/html -p# service zabbix_agentd stop# service zabbix_server stop# mysqldump -uroot -p zabbix > /opt/bak24/zabbix.sql# cp -r /usr/local/zabbix /opt/bak24# cp /etc/php.ini /opt/bak24# cp /etc/httpd/conf/httpd.conf /opt/bak24# mv /var/www/html/* /opt/bak24/html/# mv /etc/init.d/zabbix_agentd /opt/bak24# mv /etc/init.d/zabbix_server /opt/bak24
6.2. Zabbix安装部署
1、下载路径:
# cd /opt/# wget https://cdn.zabbix.com/zabbix/sources/stable/3.0/zabbix-3.0.31.tar.gz
2、上传zabbix-3.0.31.tar.gz到服务器/opt目录下面
# tar -zxvf zabbix-3.0.31.tar.gz
3、进行编译安装zabbix_server
# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/var/lib/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2# make && make install# cd /opt/zabbix-3.0.31/misc/init.d/fedora/core# cp zabbix_* /etc/init.d/# chmod +x /etc/rc.d/init.d/zabbix_*# vim /etc/rc.d/init.d/zabbix_serverBASEDIR=/usr/local/zabbix# vim /etc/rc.d/init.d/zabbix_agentdBASEDIR=/usr/local/zabbix# chkconfig zabbix_server on# chkconfig --add zabbix_server# chkconfig zabbix_agentd on# chkconfig --add zabbix_agentd# cp /usr/local/zabbix/etc/zabbix_server.conf /opt/bak24/zabbix_server3.conf# cp /opt/bak24/zabbix/etc/zabbix_server.conf /usr/local/zabbix/etc# egrep -v "^#|^$" /usr/local/zabbix/etc/zabbix_server.conf
#备注:如果数据库与zabbix_server是异机时参数DBHost的配置要修改为对应数据库IP,并注释DBSocket配置;如果机器是相同时要核对DBSocket的具体路径。
LogFile=/tmp/zabbix_server.logDBHost=localhostDBName=zabbixDBUser=zabbixDBPassword=密码DBSocket=/var/lib/mysql/mysql.sockStartPollers=20AlertScriptsPath=/usr/lib/zabbix/alertscriptsFpingLocation=/usr/local/sbin/fping
6.3. Web配置
# cd /var/www/html/# cp -R /opt/zabbix-3.0.31/frontends/php/* .# cp /opt/bak24/httpd.conf /etc/httpd/conf# chown -R apache:apache *# cp /opt/bak24/php.ini /etc/# vim /etc/httpd/httpd.conf --核对配置信息#将如下代码段#ServerName www.example.com:80---修改为ServerName localhost:80#模块中注意添加php对应版本的支持DirectoryIndex index.html index.phpAddType application/x-httpd-php .php .php3 .php4 .php5# systemctl restart httpd
6.4. 登录Zabbix的Web配置界面
1、 在浏览器中打开访问地址:http://10.10.10.181/setup.php
2、检查系统环境,必须全部ok才能继续
安装或升级时检查系统环境时的错误提示:ldap 显示Warning
解决方法:安装对应php版本的依赖库
# cd /opt && tar -zxf php-5.4.16.tar.gz# cd php-5.4.16/ext/ldap# /usr/bin/phpize# ./configure --with-php-config=/usr/bin/php-config && make && make install
安装ldap报错一:configure: error: Cannot find ldap.h
解决办法:
# yum -y install openldap openldap-devel
安装ldap报错二:configure: error: Cannot find ldap libraries in /usr/lib
解决办法:
# cp -frp /usr/lib64/libldap* /usr/lib/# /usr/bin/phpize# make clean && ./configure --with-php-config=/usr/bin/php-config && make && make install# systemctl restart httpd
如果还是出现Warning则直接指定库位置,再重启httpd服务
# vim /etc/php.iniextension=/usr/lib64/php/modules/ldap.so
3、配置mysql数据连接
Test connection #显示ok表示通过
升级连接数据库时的错误提示:Cannot connect to the database.
The frontend does not match Zabbix database. Current database version (mandatory/optional): 2040000/2040000.
Required mandatory version: 3000000. Contact your system administrator.
原因:新的Zabbix所需数据库版本与现数据库版本不一致导致,更改版本号即可
解决办法:
# mysql -uroot -pSQL> use zabbix;SQL> update dbversion set mandatory=3000000;SQL> flush privileges;
4、5直接点击Next
6点击Finish
最后的登录用户/密码:admin/zabbix
界面乱码问题处理:
# service zabbix_server start# tail -100f /var/log/messageszabbix_server: Starting zabbix_server:/usr/local/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory# find / -name 'libmysqlclient*'/usr/lib64/mysql/libmysqlclient.so.18/usr/lib64/mysql/libmysqlclient.so.18.0.0/mysql/mysql/lib/libmysqlclient.a/mysql/mysql/lib/libmysqlclient.so/mysql/mysql/lib/libmysqlclient.so.20/mysql/mysql/lib/libmysqlclient.so.20.3.15# ln -s /mysql/mysql/lib/libmysqlclient.so.20 /usr/lib64# tail -100f /tmp/zabbix_server.log ---查看zabbix_server日志,排查升级问题…………………17120:20200610:181128.506 completed 98% of database upgrade17120:20200610:181128.507 completed 99% of database upgrade17120:20200610:181128.507 completed 100% of database upgrade17120:20200610:181128.507 database upgrade fully completed17120:20200610:181128.566 server #0 started [main process]17128:20200610:181128.566 server #1 started [configuration syncer #1]17129:20200610:181128.567 server #2 started [db watchdog #1]17130:20200610:181128.567 server #3 started [poller #1]…………………