实验环境:CentOS 6.5(最小化安装)
[[email protected] software]# yum -y install gcc gcc-c++
安装PHP:
[[email protected] software]# yum -y install libxml2 libxml2-devel libjpeg-devel libpng-devel bzip2-devel libcurl-devel gd-devel [[email protected] software]# tar -jxvf php-5.3.8.tar.bz2 &>/dev/null [[email protected] software]# cd php-5.3.8 [[email protected] 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 [[email protected] php-5.3.8]# make &&make install [[email protected] php-5.3.8]# cp php.ini-production /usr/local/php/lib/php.ini [[email protected] php-5.3.8]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf [[email protected] ~]# sed -i ‘/max_execution_time/s/30/300/‘ /usr/local/php/lib/php.ini [[email protected] ~]# sed -i ‘/post_max_size/s/8/16/‘ /usr/local/php/lib/php.ini [[email protected] ~]# sed -i ‘/max_input_time/s/60/300/‘ /usr/local/php/lib/php.ini [[email protected] ~]# sed -i ‘/^;date.timezone/adate.timezone \= \"Asia\/Shanghai\"‘ /usr/local/php/lib/php.ini [[email protected] ~]# sed -i ‘/^\;date\.timezone \=/d‘ /usr/local/php/lib/php.ini
注:如果PHP的时区不是"Asia/Shanghai",则在安装Zabbix的时候会出现下面的报错信息
--with-config-file-path=PATH这个参数可以指定php.ini文件的位置,默认在PREFIX/lib目录下
[[email protected] ~]# /usr/local/php/bin/php -i |grep date.timezone date.timezone => Asia/Shanghai => Asia/Shanghai [[email protected] ~]# [[email protected] ~]# sed -i ‘/run\/php-fpm.pid/s/^;//g‘ /usr/local/php/etc/php-fpm.conf [[email protected] ~]# sed -i ‘/^;pm.min_spare_servers/s/^;//g‘ /usr/local/php/etc/php-fpm.conf [[email protected] ~]# sed -i ‘/^;pm.max_spare_servers/s/^;//g‘ /usr/local/php/etc/php-fpm.conf [[email protected] ~]# sed -i ‘/^;pm.start_servers/s/^;//g‘ /usr/local/php/etc/php-fpm.conf [[email protected] ~]# /usr/local/php/sbin/php-fpm [[email protected] ~]# echo "/usr/local/php/sbin/php-fpm" >>/etc/rc.local [[email protected] ~]# netstat -anp|grep php-fpm tcp 0 0 127.0.0.1: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 [[email protected] ~]# [[email protected] ~]# 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 ··· [[email protected] ~]#
安装Nginx:
[[email protected] software]# tar -jxvf pcre-8.12.tar.bz2 &>/dev/null [[email protected] software]# cd pcre-8.12 [[email protected] pcre-8.12]# ./configure &&make &&make install [[email protected] software]# tar -zxvf zlib-1.2.7.tar.gz &>/dev/null [[email protected] software]# cd zlib-1.2.7 [[email protected] zlib-1.2.7]# ./configure &&make &&make install [[email protected] software]# tar -zxvf openssl-1.0.1c.tar.gz &>/dev/null [[email protected] software]# cd openssl-1.0.1c [[email protected] openssl-1.0.1c]# ./config &&make &&make install [[email protected] software]# tar -zxvf nginx-1.6.2.tar.gz &>/dev/null [[email protected] software]# cd nginx-1.6.2 [[email protected] 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 [[email protected] nginx-1.6.2]# make &&make install [[email protected] nginx-1.6.2]# chmod 775 /etc/init.d/nginx [[email protected] nginx-1.6.2]# chkconfig --add nginx [[email protected] nginx-1.6.2]# chkconfig nginx on [[email protected] nginx-1.6.2]# /etc/init.d/nginx start Starting nginx: [ OK ] [[email protected] nginx-1.6.2]#
安装mysql:
[[email protected] software]# yum -y install mysql* [[email protected] software]# /etc/init.d/mysqld start Starting mysqld: [ OK ] [[email protected] software]# chkconfig mysqld on [[email protected] software]# mysqladmin -uroot password redhat [[email protected] software]# mysql -uroot -predhat mysql> [[email protected] software]#
安装Zabbix:
[[email protected] software]# yum -y install net-snmp net-snmp-devel libxml2-devel libcurl-devel [[email protected] software]# tar -zxvf zabbix-2.0.14.tar.gz &>/dev/null [[email protected] software]# cd zabbix-2.0.14 [[email protected] zabbix-2.0.14]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 [[email protected] zabbix-2.0.14]# make &&make install
zabbix server一般充当两个角色:server、angent,所以上面的配置参数也同时加上了–enable-agent。
备注:请安装好MySQL,snmp,curl开发库。
[email protected] software]# useradd -s /sbin/nologin zabbix
初始化数据库:
[[email protected] 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 [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只需要导入一个表结构即可
[[email protected] zabbix-2.0.14]# mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql [[email protected] zabbix-2.0.14]# mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql [[email protected] zabbix-2.0.14]# mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql [[email protected] zabbix-2.0.14]# cp misc/init.d/fedora/core/zabbix_* /etc/init.d/ [[email protected] zabbix-2.0.14]# chmod 775 /etc/init.d/zabbix_* [[email protected] ~]# sed -i ‘/LogFile/s/tmp/var\/log/‘ /usr/local/zabbix/etc/zabbix_server.conf [[email protected] ~]# sed -i ‘/^DBUser\=/s/root/zabbix/‘ /usr/local/zabbix/etc/zabbix_server.conf [[email protected] ~]# sed -i ‘/DBPassword\=$/s/^#//g‘ /usr/local/zabbix/etc/zabbix_server.conf [[email protected] ~]# sed -i ‘/DBPassword\=$/s/^[ \t]//g‘ /usr/local/zabbix/etc/zabbix_server.conf [[email protected] ~]# sed -i ‘/DBPassword\=$/s/\=/&zabbix/g‘ /usr/local/zabbix/etc/zabbix_server.conf [[email protected] ~]# 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 [[email protected] ~]# cat /usr/local/zabbix/etc/zabbix_agent.conf|grep Server|grep -v ^# Server=127.0.0.1 //服务端的IP [[email protected] ~]# cat /usr/local/zabbix/etc/zabbix_agent.conf|grep UnsafeUser ### Option: UnsafeUserParameters # UnsafeUserParameters=0 [[email protected] ~]#
默认是不启用自定义脚本功能的,要自定义key,需开启,设置为 1
[[email protected] ~]# mkdir /usr/local/nginx/html/zabbix [[email protected] ~]# cp -rf /software/zabbix-2.0.14/frontends/php/* /usr/local/nginx/html/zabbix/ [[email protected] ~]# chown zabbix:zabbix /usr/local/nginx/html/zabbix/ -R [[email protected] ~]# chmod o+w /usr/local/nginx/html/zabbix/conf [[email protected] ~]# ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/ [[email protected] ~]# touch /var/log/zabbix_server.log [[email protected] ~]# chown zabbix:zabbix /var/log/zabbix_server.log [[email protected] ~]# chmod 775 /var/log/zabbix_server.log [[email protected] ~]# /etc/init.d/zabbix_server start Starting zabbix_server: [ OK ] [[email protected] ~]# /etc/init.d/zabbix_agentd start Starting zabbix_agentd: [ OK ] [[email protected] ~]# chkconfig --add zabbix_server [[email protected] ~]# chkconfig --add zabbix_agentd [[email protected] ~]# chkconfig zabbix_server on [[email protected] ~]# chkconfig zabbix_agentd on [[email protected] ~]# chkconfig --list|grep zabbix zabbix_agentd 0:off1:off2:on3:on4:on5:on6:off zabbix_server 0:off1:off2:on3:on4:on5:on6:off [[email protected] ~]# [[email protected] ~]# 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 [[email protected] ~]# 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 [[email protected] ~]# [[email protected] ~]# touch /usr/local/nginx/logs/zabbix.access.log [[email protected] 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 ] [[email protected] conf]#
访问:http://172.24.17.130/zabbix/
基于LNMP的Zabbix安装完成
更改Zabbix语言:Profile---User---Language:
PHP探针:
[[email protected] phpinfo]# cat index.php <?php phpinfo(); ?> [[email protected] phpinfo]#
时间: 2024-09-30 07:56:58