zabbix 4.0.7 LTS安装

本次安装采用源码方式部署,将其部署到容器中
第一部分:初始化基础环境
1.首先创建一个docker container环境,要80端口映射出来,便于访问zabbix web界面,22端口映射出来,方便运维管理
docker run -d --privileged -v /data/ddata/zabbix:/data -v /data/ddata/dfile:/dfile -p1010:22 -p8080:80 --net zstnet --ip 172.18.0.10 --cap-add=NET_ADMIN --name zabbix -h zabbix trsen/centos76_mysql:20190605
2.查看container已经启动
[root@trsenzhangdb logs]# docker ps -a|grep zabbix
4874fd8d2beb trsen/centos76_mysql:20190605 "/usr/bin/supervisor…" 14 seconds ago Up 11 seconds (healthy) 0.0.0.0:1010->22/tcp, 0.0.0.0:8080->80/tcp zabbix
3.容器可以登录和使用
通过telnet 22端口测试,80端还没有监听,所以不通正常
若不能进测试不通,建议通过iptables看一下宿主机的转发配置
[root@trsenzhangdb ~]# iptables -t nat -nL |grep "0.10"
MASQUERADE tcp -- 172.18.0.10 172.18.0.10 tcp dpt:80
MASQUERADE tcp -- 172.18.0.10 172.18.0.10 tcp dpt:22
DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 to:172.18.0.10:80
DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:1010 to:172.18.0.10:22
4.部署mysql,我这边部署的是mysql5.7.24官方版本
groupadd mysql
useradd -g mysql -d /usr/local/mysql -s /sbin/nologin -MN mysql
chown mysql:mysql /usr/local/mysql -R
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306.cnf --initialize-insecure
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/my3306.cnf &
[root@zabbix data]# ps -ef |grep mysql
mysql 11156 5224 11 11:57 pts/1 00:00:19 /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/my3306.cnf
第二部分安装zabbix server
1.创建zabbix用户
groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
我这里有yum配置,所以很多东西都是通过安装,个人建议在自己的环境中配置一个yum服务器
2.安装php和apache
yum install httpd php -y
3.安装依赖包
yum install gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xml libxml2-devel libxml2 libevent-devel -y
4.解压源码文件包到/usr/local下
tar -xvf zabbix-4.0.7.tar.gz -C /usr/local/
5.进入/usr/local/zabbix-4.0.7进行源码编译配置和安装
./configure --prefix=/usr/local/zabbix \
--enable-server \
--enable-agent \
--with-mysql=/usr/local/mysql/bin/mysql_config \
--enable-ipv6 \
--with-net-snmp \
--with-libcurl \
--with-libxml2

make install
编译完成后会生成/usr/local/zabbix目录里面包含运行相关命令及配置
6.提高zabbix ping性能,编译安装fping工具
tar -xvf fping-4.2.tar.gz -C /usr/local/
cd /usr/local/fping-4.2
./configure && make install
chown root.zabbix /usr/local/sbin/fping
chmod 4710 /usr/local/sbin/fping
7.在存放zabbix的mysql数据库中创建db和利用源码包中sql脚本初始化数据,初始化脚本在源码文件目录/usr/local/zabbix-4.0.7/database/mysq中三个*.sql文件
create database if not exists zabbix default character set utf8 collate utf8_general_ci;
use zabbix
source /usr/local/zabbix-4.0.7/database/mysql/schema.sql;
source /usr/local/zabbix-4.0.7/database/mysql/images.sql;
source /usr/local/zabbix-4.0.7/database/mysql/data.sql;
create user zabbix@'%' identified by 'zabbix';
grant all privileges on *.* to zabbix@'%';
8.创建zabbix服务存放日志和临时文件地方
mkdir -p /usr/local/zabbix/{logs,tmps}
chown zabbix:zabbix /usr/local/zabbix/{logs,tmps} -R
9.配置zabbix server配置文件
vi /usr/local/zabbix/etc/zabbix_server.conf
egrep -v "^#|^$" /usr/local/zabbix/etc/zabbix_server.conf

ListenPort=10051
LogFile=/usr/local/zabbix/logs/zabbix_server.log
PidFile=/usr/local/zabbix/tmps/zabbix_server.pid
SocketDir=/tmp
DBHost=172.18.0.10
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/tmp/mysql3306.sock
DBPort=3306
Timeout=4
FpingLocation=/usr/local/sbin/fping
LogSlowQueries=3000
10.复制并配置自启动脚本
cp /usr/local/zabbix-4.0.7/misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server

[root@zabbix etc]# cat /etc/init.d/zabbix_server |egrep "BASEDIR=|PIDFILE="
BASEDIR=/usr/local/zabbix
PIDFILE=$BASEDIR/tmps/$BINARY_NAME.pid
11.创建软连接,并启动zabbix server
ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/

[root@zabbix etc]# /etc/init.d/zabbix_server start
Starting zabbix_server: [ OK ]


chkconfig --add zabbix_server
chkconfig --level 35 zabbix_server on
chkconfig --list
12.配置web
cp -a /usr/local/zabbix-4.0.7/frontends/php/* /var/www/html/
chown -R apache:apache /var/www/html/
13.修改参数/etc/php.ini参数
sed -i "s#post_max_size = 8M#post_max_size = 32M#g" /etc/php.ini
sed -i "s/;date.timezone =/date.timezone = Asia\/Shanghai/g" /etc/php.ini
sed -i "s#max_execution_time = 30#max_execution_time = 300#g" /etc/php.ini
sed -i "s#max_input_time = 60#max_input_time = 300#g" /etc/php.ini
sed -i "s#memory_limit = 128M#memory_limit = 128M#g" /etc/php.ini
14.配置apache,并启动httpd
[root@zabbix logs]# grep "^ServerName" /etc/httpd/conf/httpd.conf
ServerName 172.18.0.10:80
15.进入web界面配置http://132.232.101.188:8080

16.check list,如果上面不修改php.ini这个里会有很多error,无法下一步
17.配置db连接
18.配置zabbix server信息
19.复检,没有问题就下一步
20.成功配置
21.登录 zabbix默认账密是admin/zabbix