实验环境:CentOS 6.5(最小化安装)
Zabbix Install Scripts:https://yunpan.cn/crF5YFDkRqsGh 访问密码 cfd7
安装包下载地址:
http://down.51cto.com/data/2214893
[root@CentOS software]# yum -y install gcc gcc-c++ make
安装PHP:
[root@CentOS software]# yum -y install libxml2 libxml2-devel libjpeg-devel libpng-devel bzip2-devel libcurl-devel gd-devel [root@CentOS software]# tar -jxvf php-5.3.8.tar.bz2 &>/dev/null [root@CentOS software]# cd php-5.3.8 [root@CentOS php-5.3.8]# ./configure --prefix=/usr/local/php --with-bz2 --with-curl --enable-ftp --enable-sockets --enable-bcmath --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local/photo --with-png-dir=/usr/local/photo --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 [root@CentOS php-5.3.8]# make &&make install [root@CentOS php-5.3.8]# cp php.ini-production /usr/local/php/lib/php.ini [root@CentOS php-5.3.8]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf [root@CentOS ~]# sed -i '/max_execution_time/s/30/300/' /usr/local/php/lib/php.ini [root@CentOS ~]# sed -i '/post_max_size/s/8/16/' /usr/local/php/lib/php.ini [root@CentOS ~]# sed -i '/max_input_time/s/60/300/' /usr/local/php/lib/php.ini [root@CentOS ~]# sed -i '/^;date.timezone/adate.timezone \= \"Asia\/Shanghai\"' /usr/local/php/lib/php.ini [root@CentOS ~]# sed -i '/^\;date\.timezone \=/d' /usr/local/php/lib/php.ini
注:如果PHP的时区不是"Asia/Shanghai",则在安装Zabbix的时候会出现下面的报错信息
--with-config-file-path=PATH这个参数可以指定php.ini文件的位置,默认在PREFIX/lib目录下
[root@CentOS ~]# /usr/local/php/bin/php -i |grep date.timezone date.timezone => Asia/Shanghai => Asia/Shanghai [root@CentOS ~]# [root@CentOS ~]# sed -i '/run\/php-fpm.pid/s/^;//g' /usr/local/php/etc/php-fpm.conf [root@CentOS ~]# sed -i '/^;pm.min_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf [root@CentOS ~]# sed -i '/^;pm.max_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf [root@CentOS ~]# sed -i '/^;pm.start_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf [root@CentOS ~]# sed -i '/^listen/s/127.0.0.1/0.0.0.0/g' /usr/local/php/etc/php-fpm.conf [root@CentOS ~]# /usr/local/php/sbin/php-fpm [root@CentOS ~]# echo "/usr/local/php/sbin/php-fpm" >>/etc/rc.local [root@CentOS ~]# netstat -anp|grep php-fpm tcp 0 0 0 0.0.0.0 9000 0.0.0.0:* LISTEN 106728/php-fpm unix 3 [ ] STREAM CONNECTED 98463 106728/php-fpm unix 3 [ ] STREAM CONNECTED 98462 106728/php-fpm [root@CentOS ~]# [root@CentOS ~]# ps -ef|grep php|grep -v grep root 30167 1 0 05:01 ? 00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf) nobody 30168 30167 0 05:01 ? 00:00:00 php-fpm: pool www nobody 30169 30167 0 05:01 ? 00:00:00 php-fpm: pool www ・・・ [root@CentOS ~]#
安装Nginx:
[root@CentOS software]# tar -jxvf pcre-8.12.tar.bz2 &>/dev/null [root@CentOS software]# cd pcre-8.12 [root@CentOS pcre-8.12]# ./configure &&make &&make install [root@CentOS software]# tar -zxvf zlib-1.2.7.tar.gz &>/dev/null [root@CentOS software]# cd zlib-1.2.7 [root@CentOS zlib-1.2.7]# ./configure &&make &&make install [root@CentOS software]# tar -zxvf openssl-1.0.1c.tar.gz &>/dev/null [root@CentOS software]# cd openssl-1.0.1c [root@CentOS openssl-1.0.1c]# ./config &&make &&make install [root@CentOS software]# tar -zxvf nginx-1.6.2.tar.gz &>/dev/null [root@CentOS software]# cd nginx-1.6.2 [root@CentOS nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-pcre=/software/pcre-8.12 --with-zlib=/software/zlib-1.2.7 --with-openssl=/software/openssl-1.0.1c --with-http_stub_status_module [root@CentOS nginx-1.6.2]# make &&make install [root@CentOS nginx-1.6.2]# chmod 775 /etc/init.d/nginx [root@CentOS nginx-1.6.2]# chkconfig --add nginx [root@CentOS nginx-1.6.2]# chkconfig nginx on [root@CentOS nginx-1.6.2]# /etc/init.d/nginx start Starting nginx: [ OK ] [root@CentOS nginx-1.6.2]#
安装mysql:
[root@CentOS software]# yum -y install mysql* [root@CentOS software]# /etc/init.d/mysqld start Starting mysqld: [ OK ] [root@CentOS software]# chkconfig mysqld on [root@CentOS software]# mysqladmin -uroot password redhat [root@CentOS software]# mysql -uroot -predhat mysql> [root@CentOS software]#
安装Zabbix:
[root@CentOS software]# yum -y install net-snmp net-snmp-devel libxml2-devel libcurl-devel [root@CentOS software]# tar -zxvf zabbix-2.0.14.tar.gz &>/dev/null [root@CentOS software]# cd zabbix-2.0.14 [root@CentOS zabbix-2.0.14]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 //libcurl监控web [root@CentOS zabbix-2.0.14]# make &&make install zabbix server一般充当两个角色:server、angent,所以上面的配置参数也同时加上了�enable-agent。 备注:请安装好MySQL,snmp,curl开发库。 root@CentOS software]# useradd -s /sbin/nologin zabbix
初始化数据库:
[root@CentOS software]# mysql -uroot -predhat mysql> create database zabbix default charset utf8; Query OK, 1 row affected (0.00 sec) mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; Query OK, 0 rows affected (0.00 sec) mysql> grant all privileges on zabbix.* to [email protected] identified by 'zabbix'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql>
zabbix server与proxy需要数据库,angent不需要。尤其要注意的是proxy只需要导入一个sql文件,而server一共要导入3个sql文件。我当时在搭建proxy的时候导入了3个sql,导致出现报错。后来才发现proxy只需要导入一个表结构即可
[root@CentOS zabbix-2.0.14]# mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql [root@CentOS zabbix-2.0.14]# mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql [root@CentOS zabbix-2.0.14]# mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql [root@CentOS zabbix-2.0.14]# cp misc/init.d/fedora/core/zabbix_* /etc/init.d/ [root@CentOS zabbix-2.0.14]# chmod 775 /etc/init.d/zabbix_* [root@CentOS ~]# sed -i '/LogFile/s/tmp/var\/log/' /usr/local/zabbix/etc/zabbix_server.conf [root@CentOS ~]# sed -i '/^DBUser\=/s/root/zabbix/' /usr/local/zabbix/etc/zabbix_server.conf [root@CentOS ~]# sed -i '/DBPassword\=$/s/^#//g' /usr/local/zabbix/etc/zabbix_server.conf [root@CentOS ~]# sed -i '/DBPassword\=$/s/^[ \t]//g' /usr/local/zabbix/etc/zabbix_server.conf [root@CentOS ~]# sed -i '/DBPassword\=$/s/\=/&zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf [root@CentOS ~]# sed -i -e '/DBPort\=/s/^#//g' /usr/local/zabbix/etc/zabbix_server.conf -e '/DBPort\=/s/^[ \t]//g' /usr/local/zabbix/etc/zabbix_server.conf [root@Zabbix ~]# sed -i '/^Server/s/127.0.0.1/192.168.100.241/g' /usr/local/zabbix/etc/zabbix_agent.conf [root@Zabbix ~]# sed -i '/^Server/s/127.0.0.1/192.168.100.241/g' /usr/local/zabbix/etc/zabbix_agentd.conf [root@Zabbix ~]# sed -i "/^ServerActive/s/127.0.0.1/${remote_ip}:10051/g" /usr/local/zabbix/etc/zabbix_agentd.conf [root@Zabbix ~]# sed -i "/^Hostname/s/Zabbix server/${remote_ip}/g" /usr/local/zabbix/etc/zabbix_agentd.conf mkdir /usr/local/nginx/html/zabbix [root@CentOS ~]# cat /usr/local/zabbix/etc/zabbix_agent.conf|grep Server|grep -v ^# Server=192.168.100.241 //服务端的IP [root@CentOS ~]# cat /usr/local/zabbix/etc/zabbix_agent.conf|grep UnsafeUser ### Option: UnsafeUserParameters # UnsafeUserParameters=0 [root@CentOS ~]#
默认是不启用自定义脚本功能的,要自定义key,需开启,设置为 1
[root@CentOS ~]# mkdir /usr/local/nginx/html/zabbix [root@CentOS ~]# cp -rf /software/zabbix-2.0.14/frontends/php/* /usr/local/nginx/html/zabbix/ [root@CentOS ~]# chown zabbix:zabbix /usr/local/nginx/html/zabbix/ -R [root@CentOS ~]# chmod o+w /usr/local/nginx/html/zabbix/conf [root@CentOS ~]# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/ [root@CentOS ~]# touch /var/log/zabbix_server.log [root@CentOS ~]# chown zabbix:zabbix /var/log/zabbix_server.log [root@CentOS ~]# chmod 775 /var/log/zabbix_server.log [root@CentOS ~]# /etc/init.d/zabbix_server start Starting zabbix_server: [ OK ] [root@CentOS ~]# /etc/init.d/zabbix_agentd start Starting zabbix_agentd: [ OK ] [root@CentOS ~]# chkconfig --add zabbix_server [root@CentOS ~]# chkconfig --add zabbix_agentd [root@CentOS ~]# chkconfig zabbix_server on [root@CentOS ~]# chkconfig zabbix_agentd on [root@CentOS ~]# chkconfig --list|grep zabbix zabbix_agentd 0:off1:off2:on3:on4:on5:on6:off zabbix_server 0:off1:off2:on3:on4:on5:on6:off [root@CentOS ~]# [root@CentOS ~]# ps -ef|grep zabbix|grep -v grep zabbix 12929 1 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12931 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12932 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12933 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12934 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12935 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12936 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12937 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12938 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12939 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12940 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12941 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12942 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12943 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12944 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12945 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12946 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12947 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12948 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12949 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12961 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12962 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12963 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12964 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12965 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12966 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12967 12929 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_server zabbix 12994 1 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_agentd zabbix 12995 12994 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_agentd zabbix 12996 12994 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_agentd zabbix 12997 12994 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_agentd zabbix 12998 12994 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_agentd zabbix 12999 12994 0 01:56 ? 00:00:00 /usr/local/sbin/zabbix_agentd [root@CentOS ~]# netstat -tunlp|grep zabbix tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 12994/zabbix_agentd tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 12929/zabbix_server [root@CentOS ~]# [root@CentOS ~]# touch /usr/local/nginx/logs/zabbix.access.log [root@CentOS conf]# /etc/init.d/nginx reload nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful Reloading nginx: [ OK ] [root@CentOS conf]#
[root@CentOS ~]# sed -i '/^\:OUTPUT/a\-A INPUT \-p tcp \-m state \-\-state NEW \-m tcp \-\-dport 80 \-j ACCEPT' /etc/sysconfig/iptables [root@CentOS ~]# /etc/init.d/iptables restart iptables: Flushing firewall rules: [ OK ] iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Unloading modules: [ OK ] iptables: Applying firewall rules: [ OK ] [root@CentOS ~]#
访问:http://192.168.100.241/zabbix/
基于LNMP的Zabbix安装完成
更改Zabbix语言:Profile---User---Language:
PHP探针: [root@CentOS phpinfo]# cat index.php <?php phpinfo(); ?> [root@CentOS phpinfo]#
Zabbix Agent安装:
[root@Client software]# yum -y install gcc gcc-c++ make net-snmp net-snmp-devel libxml2-devel libcurl-devel [root@Client software]# tar -zxvf zabbix-2.0.14.tar.gz &>/dev/null [root@Client software]# cd zabbix-2.0.14 [root@Client zabbix-2.0.14]# ./configure --prefix=/usr/local/zabbix --enable-agent [root@Client zabbix-2.0.14]# make &&make install [root@Client software]# useradd -s /sbin/nologin zabbix [root@Client etc]# grep -v ^# zabbix_agentd.conf|grep -v ^$ PidFile=/tmp/zabbix_agentd.pid LogFile=/var/log/zabbix_agentd.log //修改日志存储路径 DebugLevel=4 //开启DEBUG EnableRemoteCommands=0 //允许远程执行命令 Server=192.168.1.10 //允许那台机器访问本机key ListenPort=10050 //监听端口 StartAgents=8 //启动的客户端进程数 ServerActive=192.168.1.10:10051 //主动监控,服务端的ip及端口 Hostname=Client.example.com //客户端的主机名和在WEB添加主机名时一致 Timeout=30 //超时时间 UnsafeUserParameters=1 //用户自定义的key [root@Client etc]# [root@Client ~]# tail -n 2 /etc/hosts 192.168.1.10Zabbix.example.com Zabbix 192.168.1.11Client.example.com Client [root@Client ~]# cp /software/zabbix-2.0.14/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/ [root@Client ~]# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/ [root@Client ~]# touch /var/log/zabbix_agentd.log [root@Client ~]# chown -R zabbix:zabbix /var/log/zabbix_agentd.log [root@Client ~]# chmod -R 775 /var/log/zabbix_agentd.log [root@Client ~]# /etc/init.d/zabbix_agentd start Starting zabbix_agentd: [ OK ] [root@Client ~]# chkconfig --add zabbix_agentd [root@Client ~]# chkconfig zabbix_agentd on [root@Client ~]# netstat -anp|grep zabbix tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 10660/zabbix_agentd [root@Client ~]# [root@Client ~]# grep 100 /etc/sysconfig/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 10050 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 10051 -j ACCEPT [root@Client ~]#
10051为Zabbix Server的Listen Port
10050为Zabbix Agent的Listen Port
测试端口是否正常:
本文出自 “鹏城-酱油瓶” 博客,谢绝转载!