3212312 发表于 2016-5-1 15:15:14

Zabbix源码安装(LNMP)

实验环境:CentOS 6.5(最小化安装)
Zabbix Install Scripts:https://yunpan.cn/crF5YFDkRqsGh访问密码 cfd7
# yum -y install gcc gcc-c++ make
安装PHP:

1
2
3
4
5
6
7
8
9
10
11
12
# yum -y install libxml2 libxml2-devel libjpeg-devel libpng-devel bzip2-devel libcurl-devel gd-devel
# tar -jxvf php-5.3.8.tar.bz2 &>/dev/null
# cd 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
# make &&make install
# cp php.ini-production /usr/local/php/lib/php.ini
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# sed -i '/max_execution_time/s/30/300/' /usr/local/php/lib/php.ini
# sed -i '/post_max_size/s/8/16/' /usr/local/php/lib/php.ini
# sed -i '/max_input_time/s/60/300/' /usr/local/php/lib/php.ini
# sed -i '/^;date.timezone/adate.timezone = \"Asia\/Shanghai\"' /usr/local/php/lib/php.ini
# sed -i '/^;date.timezone =/d' /usr/local/php/lib/php.ini




注:如果PHP的时区不是"Asia/Shanghai",则在安装Zabbix的时候会出现下面的报错信息

--with-config-file-path=PATH这个参数可以指定php.ini文件的位置,默认在PREFIX/lib目录下




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# /usr/local/php/bin/php -i |grep date.timezone
date.timezone => Asia/Shanghai => Asia/Shanghai
#
# sed -i '/run\/php-fpm.pid/s/^;//g' /usr/local/php/etc/php-fpm.conf
# sed -i '/^;pm.min_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf
# sed -i '/^;pm.max_spare_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf
# sed -i '/^;pm.start_servers/s/^;//g' /usr/local/php/etc/php-fpm.conf
# sed -i '/^listen/s/127.0.0.1/0.0.0.0/g' /usr/local/php/etc/php-fpm.conf
# /usr/local/php/sbin/php-fpm
# echo "/usr/local/php/sbin/php-fpm" >>/etc/rc.local
# netstat -anp|grep php-fpm
tcp      0      00 0.0.0.0 9000            0.0.0.0:*                   LISTEN      106728/php-fpm      
unix3      [ ]         STREAM   CONNECTED   98463106728/php-fpm      
unix3      [ ]         STREAM   CONNECTED   98462106728/php-fpm      
#
# ps -ef|grep php|grep -v grep
root      30167      10 05:01 ?      00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody    30168301670 05:01 ?      00:00:00 php-fpm: pool www         
nobody    30169301670 05:01 ?      00:00:00 php-fpm: pool www
···   
#




安装Nginx:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# tar -jxvf pcre-8.12.tar.bz2 &>/dev/null
# cd pcre-8.12
# ./configure &&make &&make install
# tar -zxvf zlib-1.2.7.tar.gz &>/dev/null
# cd zlib-1.2.7
# ./configure &&make &&make install
# tar -zxvf openssl-1.0.1c.tar.gz &>/dev/null
# cd openssl-1.0.1c
# ./config &&make &&make install
# tar -zxvf nginx-1.6.2.tar.gz &>/dev/null
# cd 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
# make &&make install
# chmod 775 /etc/init.d/nginx
# chkconfig --add nginx
# chkconfig nginx on
# /etc/init.d/nginx start
Starting nginx:                                          
#




安装mysql:

1
2
3
4
5
6
7
8
# yum -y install mysql*
# /etc/init.d/mysqld start
Starting mysqld:                                          
# chkconfig mysqld on
# mysqladmin -uroot password redhat
# mysql -uroot -predhat
mysql>
#




安装Zabbix:

1
2
3
4
5
6
7
8
# yum -y install net-snmp net-snmp-devel libxml2-devel libcurl-devel
# tar -zxvf zabbix-2.0.14.tar.gz &>/dev/null
# cd zabbix-2.0.14
# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2         //libcurl监控web
# make &&make install
zabbix server一般充当两个角色:server、angent,所以上面的配置参数也同时加上了–enable-agent。
备注:请安装好MySQL,snmp,curl开发库。
root@CentOS software]# useradd -s /sbin/nologin zabbix




初始化数据库:

1
2
3
4
5
6
7
8
9
10
# 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 zabbix@192.168.100.241 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只需要导入一个表结构即可


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql
# mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql
# mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql
# cp misc/init.d/fedora/core/zabbix_* /etc/init.d/
# chmod 775 /etc/init.d/zabbix_*
# sed -i '/LogFile/s/tmp/var\/log/' /usr/local/zabbix/etc/zabbix_server.conf
# sed -i '/^DBUser=/s/root/zabbix/' /usr/local/zabbix/etc/zabbix_server.conf
# sed -i '/DBPassword=$/s/^#//g' /usr/local/zabbix/etc/zabbix_server.conf
# sed -i '/DBPassword=$/s/^[         ]//g' /usr/local/zabbix/etc/zabbix_server.conf
# sed -i '/DBPassword=$/s/=/&zabbix/g' /usr/local/zabbix/etc/zabbix_server.conf
# sed -i -e '/DBPort=/s/^#//g' /usr/local/zabbix/etc/zabbix_server.conf -e '/DBPort=/s/^[         ]//g' /usr/local/zabbix/etc/zabbix_server.conf
# sed -i '/^Server/s/127.0.0.1/192.168.100.241/g' /usr/local/zabbix/etc/zabbix_agent.conf
# sed -i '/^Server/s/127.0.0.1/192.168.100.241/g' /usr/local/zabbix/etc/zabbix_agentd.conf
# sed -i "/^ServerActive/s/127.0.0.1/${remote_ip}:10051/g" /usr/local/zabbix/etc/zabbix_agentd.conf
# sed -i "/^Hostname/s/Zabbix server/${remote_ip}/g" /usr/local/zabbix/etc/zabbix_agentd.conf
mkdir /usr/local/nginx/html/zabbix
# cat /usr/local/zabbix/etc/zabbix_agent.conf|grep Server|grep -v ^#
Server=192.168.100.241            //服务端的IP
# cat /usr/local/zabbix/etc/zabbix_agent.conf|grep UnsafeUser
### Option: UnsafeUserParameters
# UnsafeUserParameters=0
#




默认是不启用自定义脚本功能的,要自定义key,需开启,设置为 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# mkdir /usr/local/nginx/html/zabbix
# cp -rf /software/zabbix-2.0.14/frontends/php/* /usr/local/nginx/html/zabbix/
# chown zabbix:zabbix /usr/local/nginx/html/zabbix/ -R
# chmod o+w /usr/local/nginx/html/zabbix/conf
# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
# touch /var/log/zabbix_server.log
# chown zabbix:zabbix /var/log/zabbix_server.log
# chmod 775 /var/log/zabbix_server.log
# /etc/init.d/zabbix_server start
Starting zabbix_server:                                    
# /etc/init.d/zabbix_agentd start
Starting zabbix_agentd:                                    
# chkconfig --add zabbix_server
# chkconfig --add zabbix_agentd
# chkconfig zabbix_server on
# chkconfig zabbix_agentd on
# chkconfig --list|grep zabbix
zabbix_agentd0:off1:off2:on3:on4:on5:on6:off
zabbix_server0:off1:off2:on3:on4:on5:on6:off
#
# ps -ef|grep zabbix|grep -v grep
zabbix    12929      10 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12931129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12932129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12933129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12934129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12935129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12936129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12937129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12938129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12939129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12940129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12941129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12942129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12943129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12944129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12945129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12946129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12947129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12948129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12949129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12961129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12962129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12963129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12964129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12965129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12966129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12967129290 01:56 ?      00:00:00 /usr/local/sbin/zabbix_server
zabbix    12994      10 01:56 ?      00:00:00 /usr/local/sbin/zabbix_agentd
zabbix    12995129940 01:56 ?      00:00:00 /usr/local/sbin/zabbix_agentd
zabbix    12996129940 01:56 ?      00:00:00 /usr/local/sbin/zabbix_agentd
zabbix    12997129940 01:56 ?      00:00:00 /usr/local/sbin/zabbix_agentd
zabbix    12998129940 01:56 ?      00:00:00 /usr/local/sbin/zabbix_agentd
zabbix    12999129940 01:56 ?      00:00:00 /usr/local/sbin/zabbix_agentd
# 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
#
# touch /usr/local/nginx/logs/zabbix.access.log
# /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:                                          
#





1
2
3
4
5
6
7
# sed -i '/^:OUTPUT/a-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT' /etc/sysconfig/iptables
# /etc/init.d/iptables restart
iptables: Flushing firewall rules:                        
iptables: Setting chains to policy ACCEPT: filter         
iptables: Unloading modules:                              
iptables: Applying firewall rules:                        
#




访问:http://192.168.100.241/zabbix/









基于LNMP的Zabbix安装完成
更改Zabbix语言:Profile---User---Language:


1
2
3
4
5
6
PHP探针:
# cat index.php
phpinfo();
?>
#




Zabbix Agent安装:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# yum -y install gcc gcc-c++ make net-snmp net-snmp-devel libxml2-devel libcurl-devel
# tar -zxvf zabbix-2.0.14.tar.gz &>/dev/null
# cd zabbix-2.0.14
# ./configure --prefix=/usr/local/zabbix --enable-agent
# make &&make install
# useradd -s /sbin/nologin zabbix
# 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
#
# tail -n 2 /etc/hosts
192.168.1.10Zabbix.example.com Zabbix
192.168.1.11Client.example.com Client
# cp /software/zabbix-2.0.14/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
# touch /var/log/zabbix_agentd.log
# chown -R zabbix:zabbix /var/log/zabbix_agentd.log
# chmod -R 775 /var/log/zabbix_agentd.log
# /etc/init.d/zabbix_agentd start
Starting zabbix_agentd:                                    
# chkconfig --add zabbix_agentd
# chkconfig zabbix_agentd on
# netstat -anp|grep zabbix
tcp      0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN      10660/zabbix_agentd
#
# 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
#




10051为Zabbix Server的Listen Port
10050为Zabbix Agent的Listen Port
测试端口是否正常:









页: [1]
查看完整版本: Zabbix源码安装(LNMP)