https://www.zabbix.com/documentation/3.0/manual/installation/requirements
为了使用zabbix前端(frontend),需要配置php环境。参考:
编译zabbix 3.0
- LIBS=-L/home/mysql/mysql/lib ./configure --prefix=/home/zabbix --enable-server --enable-agent --with-mysql
- make
- make install
遇到的问题:
1 找不到mysqlclient
- checking for the linux kernel version... unknown family (3.10.0-327.18.2.el7.x86_64)
- checking size of void *... 8
- checking for mysql_config... /home/mysql/mysql/bin/mysql_config
- checking for main in -lperconaserverclient... no
- configure: error: Not found mysqlclient library
所以导致找不到库。
解决方法是,建立链接并把库的目录加入环境变量:
- cd /home/mysql/mysql/lib
- ln -s libperconaserverclient.so.20.2.0 libmysqlclient.so
- LIBS=-L/home/mysql/mysql/lib ./configure xxx
配置zabbix后端数据库。这里是mysql(PerconaServer)
配置账号,创建zabbix数据库。
在从php页面进行setup之前,需要先创建数据库和schema。创建schema的SQL在zabbix源代码的database/mysql/下面。
- create user 'zabbix'@'%' identified by 'password';
- flush privileges;
- CREATE DATABASE `zabbix` /*!40100 COLLATE 'utf8_general_ci' */;
- grant all on zabbix.* to 'zabbix'@'%';
- flush privileges;
- source schema.sql
- source images.sql
- source data.sql
访问zabbix前端页面,自动进入setup程序。
setup的最后,需要把配置写入conf文件,需要php有写权限。
- touch /home/nginx/html/zabbix/conf/zabbix.conf.php
- chmod 777 /home/nginx/html/zabbix/conf/zabbix.conf.php
setup完成后,就可以登录了。zabbix默认账号是 admin/zabbix
zabbix server 配置:
创建zabbix账号,配置文件
- useradd -r -M zabbix
- LogFile=/tmp/zabbix_server.log
- DBName=zabbix
- DBUser=zabbix
- DBPassword=password
- DBSocket=/var/lib/mysql/mysql.sock
- Timeout=4
- LogSlowQueries=3000
init启动脚本
可以参考zabbix源代码的misc/init.d/目录下的模板。
systemd启动脚本
centos7使用systemd管理服务,因此参见下面的systemd启动脚本。
一般由软件包安装的服务脚本放在/lib/systemd/system下,
手工创建的脚本放在/etc/systemd/system下。
- # cat zabbix_agentd.service
- [Unit]
- Description=zabbix_agentd
- [Service]
- Type=forking
- PIDFile=/tmp/zabbix_agentd.pid
- ExecStart=/home/zabbix/sbin/zabbix_agentd
- ExecStop=/bin/kill $MAINPID
- [Install]
- WantedBy=multi-user.target
- # cat zabbix_server.service
- [Unit]
- Description=zabbix_server
- [Service]
- Type=forking
- PIDFile=/tmp/zabbix_server.pid
- ExecStart=/home/zabbix/sbin/zabbix_server
- ExecStop=/bin/kill $MAINPID
- [Install]
- WantedBy=multi-user.target
配置开机启动:
- systemctl enable zabbix_agentd.service
- systemctl start zabbix_agentd.service
- systemctl enable zabbix_server.service
- systemctl start zabbix_server.service
- # 查看是否为enable
- systemctl list-unit-files --type=service|grep zabbix
补充:
关键systemd的帮助,可以查看 man systemd.service,或查看官网
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Services.html
zabbix agent 配置:
- useradd -r -M zabbix
- # grep -v '^;' zabbix_agentd.conf |grep -v -e '^ *$' -e '^#'
- LogFile=/tmp/zabbix_agentd.log
- LogFileSize=10
- Server=zbserver.example.com
- ServerActive=zbserver.example.com
- Hostname=client1.example.com
windows客户机配置zabbix agentd:
- # 安装服务
- C:\zabbix_agents\bin\win64\zabbix_agentd.exe -c C:\zabbix_agents\conf\zabbix_agentd.win.conf -i
- # 启动
- C:\zabbix_agents\bin\win64\zabbix_agentd.exe -c C:\zabbix_agents\conf\zabbix_agentd.win.conf -s