一、安装环境(zabbix3.0需要php在5.5版本以上)
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) [root@localhost ~]# netstat -lntup|egrep 'nginx|mysql' tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1268/nginx: master tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 1268/nginx: master tcp 0 0 0.0.0.0:8668 0.0.0.0:* LISTEN 1268/nginx: master tcp 0 0 0.0.0.0:8898 0.0.0.0:* LISTEN 1268/nginx: master tcp 0 0 0.0.0.0:8899 0.0.0.0:* LISTEN 1268/nginx: master tcp6 0 0 :::3306 :::* LISTEN 1186/mysqld [root@localhost ~]# ps -ef|grep 'php'|head -1 root 742 1 0 10月22 ? 00:00:08 php-fpm: master process (/usr/local/php-5.6.30/etc/php-fpm.conf)
二、安装zabbix-server端
1、下载安装源码包
更换阿里源:
cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo.bak
wget -O CentOS-Base.repo http://mirrors.aliyuncs.com/repo/Centos-7.repo
清理缓存 yum clean all
重新生成缓存 yum makecache
下载安装包
cd /application/tools/
wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.14/zabbix-3.4.14.tar.gz
2、安装依赖
yum -y install fping net-snmp-devel unixODBC-devel openssl-devel OpenIPMI-devel java-devel
3、解压并编译
[root@localhost tools]# tar xf zabbix-3.4.14.tar.gz [root@localhost tools]# cd zabbix-3.4.14/ [root@localhost zabbix-3.4.14]# ./configure --prefix=/application/zabbix-3.4.14 --enable-server --enable-agent --enable-java --enable-ipv6 --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-unixodbc --with-openssl
make make install ln -s /application/zabbix-3.4.14/ /application/zabbix
useradd zabbix -s /sbin/nologin -M
chown -R zabbix.zabbix /application/zabbix
4、在mysql数据库创建zabbix库和zabbix用户,及授权zabbix用户管理zabbix库
mysql -uroot -p1q2w3e create database zabbix character set utf8 collate utf8_bin; grant all on zabbix.* to zabbix@'127.0.0.1' identified by 'zabbix'; flush privileges; quit
5、找到解压zabbix软件的目录,导入数据到数据库:
[root@localhost zabbix-3.4.14]# cd /application/tools/zabbix-3.4.14/database/mysql/ [root@localhost mysql]# ll 总用量 4876 -rw-r--r-- 1 mysql mysql 2877497 9月 14 16:05 data.sql -rw-r--r-- 1 mysql mysql 1978341 9月 14 16:04 images.sql -rw-r--r-- 1 mysql mysql 134791 9月 14 16:05 schema.sql
6、注意导入的顺序
mysql -uroot -p1q2w3e use zabbix source /application/tools/zabbix-3.4.14/database/mysql/schema.sql source /application/tools/zabbix-3.4.14/database/mysql/images.sql source /application/tools/zabbix-3.4.14/database/mysql/data.sql; show tables; quit
7、创建zabbix web站点目录
mkdir /www/zabbix -p cp -a /application/tools/zabbix-3.4.14/frontends/php/* /www/zabbix/ chown -R www.www /www/zabbix
8、配置zabbix
1)、php配置,操作命令
查看: [root@localhost mysql]# egrep -n "^post_max_size|^max_execution_time|^max_input_time|^date.timezone" /usr/local/php/etc/php.ini 373:max_execution_time = 30 383:max_input_time = 60 662:post_max_size = 8M 951:date.timezone = "Asia/Shanghai" 修改: [root@localhost mysql]# sed -i 's#max_execution_time = 30#max_execution_time = 300#;s#max_input_time = 60#max_input_time = 300#;s#post_max_size = 8M#post_max_size = 16M#;910a date.timezone = Asia/Shanghai' /usr/local/php/etc/php.ini [root@localhost mysql]# egrep -n "^post_max_size|^max_execution_time|^max_input_time|^date.timezone" /usr/local/php/etc/php.ini 373:max_execution_time = 300 383:max_input_time = 300 662:post_max_size = 16M 911:date.timezone = Asia/Shanghai #已经添加了删除 952:date.timezone = "Asia/Shanghai"
pkill php
ps -ef|grep php
/usr/local/php/sbin/php-fpm
ps -ef|grep php
2)、配置nginx
# 执行命令前注意备份Nginx配置文件!! cp /usr/local/nginx/conf/nginx.conf{,ori}
[root@localhost vhosts]# cat zabbix.conf
server
{
listen 80;
server_name jk.lvka168.cn;
#index index.php index.html index.htm ;
index index.html index.htm index.php index.shtml;
root /www/zabbix;
#error_page 404 502 http://www2.lvka168.com/error;
location / {
ssi on;
ssi_silent_errors on;
ssi_types text/shtml;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|thumb) {
root /www/zabbix;
access_log off;
expires 30d;
}
location ~* ^.+\.(log) {
root /www/zabbix;
deny all;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/dev/shm/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/zabbix$fastcgi_script_name;
}
if ( $http_user_agent ~* "WebBench" ) {
return 503;
}
access_log /www/logs/zabbix-access.log main;
error_log /www/logs/zabbix-error.log crit;
}
/usr/local/nginx/sbin/nginx -s reload
3)、配置zabbix
sed -i -e '86a DBHost=127.0.0.1' -e '116a DBPassword=zabbix' -e '128a DBSocket=/tmp/mysql.sock'/application/zabbix/etc/zabbix_server.conf
4)、启动脚本
\cp /application/tools/zabbix-3.4.14/misc/init.d/fedora/core/zabbix_{server,agentd} /etc/init.d/
5)、修改启动脚本
sed -i 's#BASEDIR=/usr/local#BASEDIR=/application/zabbix#' /etc/init.d/zabbix_{server,agentd}
6)、启动脚本并加入开机自动启动
chkconfig --add zabbix_agentd chkconfig --add zabbix_server chkconfig --list LANG=en_US.UTF-8 chkconfig zabbix_server on chkconfig zabbix_agentd on LANG=zh_CN.UTF-8 /etc/init.d/zabbix_server start
7)、在浏览器上检测
8)、web页面上安装