当前使用Centos7.6版本通过编译方式安装zabbix4.0server
关闭selinux、关闭防火墙(或自行开放对应端口),同步当前系统时间
当前使用lnmp.org提供的一键包为基础lnmp环境,安装软件版本php5.6、mysql5.7
zabbix4.0server安装过程开始:
1、创建zabbix数据库
mysql -uroot -p mysql> create database zabbix character set utf8 collate utf8_bin; mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'blog.whsir.com'; mysql> quit
|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 | mysql -uroot -p mysql> create database zabbix character set utf8 collate utf8_bin; mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'blog.whsir.com'; mysql> quit |
2、创建zabbix用户组
groupadd zabbix -g 201 useradd -M -r -g zabbix -u 201 -s /bin/false zabbix
|-----|----------------------------------------------------------------------------| | 1 2 | groupadd zabbix -g 201 useradd -M -r -g zabbix -u 201 -s /bin/false zabbix |
PS:在root下运行zabbix,zabbix会主动使用zabbix用户来运行,如果系统没有zabbix用户,需要创建
3、下载zabbix4.0源码包
cd /usr/local/src wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.2/zabbix-4.0.2.tar.gz tar xf zabbix-4.0.2.tar.gz
|-------|------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | cd /usr/local/src wget https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.2/zabbix-4.0.2.tar.gz tar xf zabbix-4.0.2.tar.gz |
4、导入zabbix数据库
cd /usr/local/src/zabbix-*/database/mysql/ mysql -uzabbix -pblog.whsir.com zabbix < schema.sql mysql -uzabbix -pblog.whsir.com zabbix < images.sql mysql -uzabbix -pblog.whsir.com zabbix < data.sql
|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 | cd /usr/local/src/zabbix-*/database/mysql/ mysql -uzabbix -pblog.whsir.com zabbix < schema.sql mysql -uzabbix -pblog.whsir.com zabbix < images.sql mysql -uzabbix -pblog.whsir.com zabbix < data.sql |
5、安装依赖
yum -y install net-snmp-devel libssh2 libssh2-devel curl-devel
|---|----------------------------------------------------------------| | 1 | yum -y install net-snmp-devel libssh2 libssh2-devel curl-devel |
6、开始编译安装zabbix4.0server
cd /usr/local/src/zabbix-* ./configure --prefix=/usr/local --sysconfdir=/etc/zabbix --enable-server --with-ssh2 --with-openssl --with-mysql=/usr/local/mysql/bin/mysql_config --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 make install
|-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | cd /usr/local/src/zabbix-* ./configure --prefix=/usr/local --sysconfdir=/etc/zabbix --enable-server --with-ssh2 --with-openssl --with-mysql=/usr/local/mysql/bin/mysql_config --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 make install |
PS:安装时可能也会缺少其他依赖,根据报错自行安装,编译时我这里指定了mysql_config的路径,可以find / -name "mysql_config*"来查找,如果你使用的是lnmp.org提供的一键包,默认路径/usr/local/mysql/bin/mysql_config
7、修改zabbix配置文件
默认zabbix日志在/tmp下,建议更改,我这里更改到了/var/log/zabbix下
mkdir /var/log/zabbix chown -R zabbix.zabbix /var/log/zabbix/ sed -i s/"# DBPassword="/DBPassword=blog.whsir.com/ /etc/zabbix/zabbix_server.conf sed -i s#"LogFile=/tmp/zabbix_server.log"#"LogFile=/var/log/zabbix/zabbix_server.log"# /etc/zabbix/zabbix_server.conf
|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 | mkdir /var/log/zabbix chown -R zabbix.zabbix /var/log/zabbix/ sed -i s/"# DBPassword="/DBPassword=blog.whsir.com/ /etc/zabbix/zabbix_server.conf sed -i s#"LogFile=/tmp/zabbix_server.log"#"LogFile=/var/log/zabbix/zabbix_server.log"# /etc/zabbix/zabbix_server.conf |
8、设置启动脚本
cp /usr/local/src/zabbix-*/misc/init.d/fedora/core5/zabbix_server /etc/init.d/ chkconfig --add /etc/init.d/zabbix_server chkconfig zabbix_server on
|-------|------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | cp /usr/local/src/zabbix-*/misc/init.d/fedora/core5/zabbix_server /etc/init.d/ chkconfig --add /etc/init.d/zabbix_server chkconfig zabbix_server on |
9、启动zabbix4.0server
/etc/init.d/zabbix_server start
|---|---------------------------------| | 1 | /etc/init.d/zabbix_server start |
10、设置php.ini文件
sed -i s/";always_populate_raw_post_data = -1"/"always_populate_raw_post_data = -1"/ /usr/local/php/etc/php.ini sed -i s/"max_input_time = 60"/"max_input_time = 300"/ /usr/local/php/etc/php.ini /etc/init.d/php-fpm restart
|-------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | sed -i s/";always_populate_raw_post_data = -1"/"always_populate_raw_post_data = -1"/ /usr/local/php/etc/php.ini sed -i s/"max_input_time = 60"/"max_input_time = 300"/ /usr/local/php/etc/php.ini /etc/init.d/php-fpm restart |
11、设置web
mkdir -p /data/zabbix cp -a /usr/local/src/zabbix-*/frontends/php/* /data/zabbix/
|-----|-------------------------------------------------------------------------------------| | 1 2 | mkdir -p /data/zabbix cp -a /usr/local/src/zabbix-*/frontends/php/* /data/zabbix/ |
12、设置nginx网站根目录
sed -i s#"root /home/wwwroot/default;"#"root /data/zabbix;"# /usr/local/nginx/conf/nginx.conf nginx -t /etc/init.d/nginx restart
|-------|----------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | sed -i s#"root /home/wwwroot/default;"#"root /data/zabbix;"# /usr/local/nginx/conf/nginx.conf nginx -t /etc/init.d/nginx restart |
13、访问http://IP,进行设置
默认登录帐号为Admin,密码zabbix
登录进去后会有个Zabbix agent on Zabbix server is unreachable for 5 minutes警报,是因为当前server没有运行zabbix-agent
14、安装zabbix4.0-agent
zabbix-agent推荐使用rpm包直接安装
rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm yum install zabbix-agent systemctl start zabbix-agent systemctl enable zabbix-agent
|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 | rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm yum install zabbix-agent systemctl start zabbix-agent systemctl enable zabbix-agent |
最后:zabbix4.0server修改中文的方法和之前的版本一样,可参考
zabbix修改中文页面: https://blog.whsir.com/post-3053.html