本文基于wlnmp一键安装包来部署lnmp环境,zabbix-server通过编译安装,理论适用于所有zabbix-server版本。
当前系统环境Centos7.x,php使用7.1版本,mysql使用5.7版本。
1、添加epel源
yum install epel-release
|---|--------------------------| | 1 | yum install epel-release |
2、添加wlnmp一键包源
rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
|---|--------------------------------------------------------------------------| | 1 | rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm |
3、安装nginx、php、mysql
yum install wnginx wphp71 wmysql57
|---|------------------------------------| | 1 | yum install wnginx wphp71 wmysql57 |
4、创建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 |
5、设置两个软链接
ln -sv /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20 ln -sv /usr/local/mysql/lib/libmysqlclient.so /usr/lib64/libmysqlclient.so
|-----|-------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 | ln -sv /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/libmysqlclient.so.20 ln -sv /usr/local/mysql/lib/libmysqlclient.so /usr/lib64/libmysqlclient.so |
6、创建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用户,需要创建
7、下载zabbix4.0源码包
cd /usr/local/src wget https://down.whsir.com/downloads/zabbix-4.0.15.tar.gz tar xf zabbix-4.0.15.tar.gz
|-------|----------------------------------------------------------------------------------------------------------| | 1 2 3 | cd /usr/local/src wget https://down.whsir.com/downloads/zabbix-4.0.15.tar.gz tar xf zabbix-4.0.15.tar.gz |
8、导入zabbix数据库
cd /usr/local/src/zabbix-4.0.15/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-4.0.15/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 |
9、安装依赖
yum install libssh2 libssh2-devel curl-devel gcc gcc-c++ libxml2-devel libevent-devel wphp71-ldap
|---|---------------------------------------------------------------------------------------------------| | 1 | yum install libssh2 libssh2-devel curl-devel gcc gcc-c++ libxml2-devel libevent-devel wphp71-ldap |
10、编译安装zabbix4.0server
cd /usr/local/src/zabbix-4.0.15 ./configure --prefix=/usr/local --sysconfdir=/etc/zabbix --enable-server --with-ssh2 --with-openssl --with-mysql=/usr/local/mysql/bin/mysql_config --enable-ipv6 --with-libcurl --with-libxml2 make install
|-------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | cd /usr/local/src/zabbix-4.0.15 ./configure --prefix=/usr/local --sysconfdir=/etc/zabbix --enable-server --with-ssh2 --with-openssl --with-mysql=/usr/local/mysql/bin/mysql_config --enable-ipv6 --with-libcurl --with-libxml2 make install |
11、配置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 |
12、设置zabbix_server启动脚本
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 |
13、启动zabbix4.0server
/etc/init.d/zabbix_server start
|---|---------------------------------| | 1 | /etc/init.d/zabbix_server start |
设置php.ini文件
sed -i s/"max_input_time = 60"/"max_input_time = 300"/ /usr/local/php/etc/php.ini /etc/init.d/php-fpm71 restart
|-----|-----------------------------------------------------------------------------------------------------------------| | 1 2 | sed -i s/"max_input_time = 60"/"max_input_time = 300"/ /usr/local/php/etc/php.ini /etc/init.d/php-fpm71 restart |
14、设置web目录
mkdir -p /data/www/zabbix cp -a /usr/local/src/zabbix-*/frontends/php/* /data/www/zabbix chown -R www.www /data/www
|-------|-----------------------------------------------------------------------------------------------------------------------| | 1 2 3 | mkdir -p /data/www/zabbix cp -a /usr/local/src/zabbix-*/frontends/php/* /data/www/zabbix chown -R www.www /data/www |
15、配置nginx
sed -i s#"root html;"#"root /data/www/zabbix;"# /usr/local/nginx/conf/vhost/demo.conf sed -i s/"#include enable-php71.conf;"/"include enable-php71.conf;"/ /usr/local/nginx/conf/vhost/demo.conf nginx -t /etc/init.d/nginx restart
|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 | sed -i s#"root html;"#"root /data/www/zabbix;"# /usr/local/nginx/conf/vhost/demo.conf sed -i s/"#include enable-php71.conf;"/"include enable-php71.conf;"/ /usr/local/nginx/conf/vhost/demo.conf nginx -t /etc/init.d/nginx restart |
访问http://IP进行安装
默认登录帐号为Admin,密码zabbix
登录进去后可能会有个Zabbix agent on Zabbix server is unreachable for 5 minutes警报,是因为当前server没有运行zabbix-agent
16、安装zabbix4.0-agent
zabbix-agent推荐使用rpm包直接安装
rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.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-2.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