zabbix安装配置(LNMP环境)

1、配置参数

zabbix对PHP参数、PHP模块有特殊要求。
如下模块要特别留意加上

bcmath        --enable-bcmath
mbstring    --enable-mbstring
sockets        --enable-sockets
gd            --with-gd
libxml        --with-libxml-dir=/usr/local
xmlwriter    同上
xmlreader    同上
ctype        默认支持
session        默认支持
gettext        默认支持

以下是我PHP的编译配置参数(需要yum install libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel gd -y)

编译:

[root@M4 ~]# ./configure  --prefix=/usr/local/php56 
--with-config-file-path=/usr/local/php56/etc --with-bz2 --with-curl 
--enable-ftp --enable-sockets --disable-ipv6 --with-gd 
--with-jpeg-dir=/usr/local --with-png-dir=/usr/local 
--with-freetype-dir=/usr/local --enable-gd-jis-conv  
--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-mysqli=mysqlnd 
--enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath

安装:

[root@M4 ~]# make && make install

配置:

[root@M4 ~]# cp php.ini-development /usr/local/php56/etc/php.ini
[root@M4 ~]# ln -s /usr/local/php56/etc/php.ini /etc/php.ini
[root@M4 ~]# cp /usr/local/php56/etc/php-fpm.conf.default /usr/local/php56/etc/php-fpm.conf
[root@M4 ~]# vim /usr/local/php/etc/php-fpm.d/www.conf #编辑
user = zabbix #设置php-fpm运行账号为www
group = zabbix #设置php-fpm运行组为www
security.limit_extensions = .php .php3 .php4 .php5 .js .css .jpg .gif .png .jpeg .html .ico .bmp

设置 php-fpm开机启动

[root@M4 ~]# cp /usr/local/src/php-56/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm

#拷贝php-fpm到启动目录

[root@M4 ~]# chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限
[root@M4 ~]# chkconfig php-fpm on #设置开机启动
[root@M4 ~]# vi /usr/local/php/etc/php.ini #编辑配置文件
找到:disable_functions =
修改为:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,
shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,
openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,
dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,
getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,
posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,
posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid,
posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,
posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
找到:;date.timezone =
修改为:date.timezone = PRC #设置时区
找到:expose_php = On
修改为:expose_php = Off #禁止显示php版本的信息
找到:short_open_tag = Off
修改为:short_open_tag = ON #支持php短标签
找到opcache.enable=0
修改为opcache.enable=1 #php支持opcode缓存
找到:;opcache.enable_cli=1 #php支持opcode缓存
修改为:opcache.enable_cli=0
post_max_size=16M
max_execution_time=300
max_input_time=300
always_populate_raw_post_data=off
在最后一行添加:zend_extension=opcache.so #开启opcode缓存功能
:wq! #保存退出

2、nginx编译安装

nginx版本1.12.2,以下我的安装编译参数

编译

[root@M4 ~]# ./configure --prefix=/web/soft/nginx/ --with-http_stub_status_module --with-http_ssl_module

安装:

[root@M4 ~]# make && make install

配置nginx支持php

[root@M4 ~]# vim /web/soft/nginx/conf/nginx.conf   
server {
        listen       8095;
        server_name  zabbix;
        location  / {
           root /web/soft/nginx/zabbix;
        }
       location ~ .php$ {
           root /web/soft/nginx/zabbix;
           fastcgi_pass 127.0.0.1:9000;
           fastcgi_index index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           include fastcgi_params;
        }

    } 
[root@M4 ~]# /etc/init.d/nginx restart #重启nginx
[root@M4 ~]# /etc/init.d/php-fpm restart #重启php-fpm

3、zabbix服务端安装

下载安装zabbix
所有版本下载地址:http://www.zabbix.com/download.php
// 一定先安装依赖

[root@M4 ~]# yum install net-snmp-devel libxml2-devel libcurl-devel libevent-devel
[root@M4 ~]# tar xf zabbix-3.4.4.tar.gz

编译

[root@M4 ~]# ./configure --prefix=/web/data/zabbix-3.4.4/ --enable-server 
--enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2

安装

[root@M4 ~]# make && make install

在zabbix server一般充当两个角色:server、angent,所以上面的配置参数也同时加上了–enable-agent。
备注:请安装好MySQL,snmp,curl开发库。
创建用户
为了安全考虑zabbix只使用普通用户运行,假如你当前用户叫ttlsa,那么你运行他,他便使用ttlsa身份运行。但是如果你在root环境下运行zabbix,那么zabbix将会主动使用zabbix用户来运行。但是如果你的系统没有名叫zabbix的用户,你需要创建一个用户,如下:

[root@M4 ~]# groupadd zabbix
[root@M4 ~]# useradd -g zabbix zabbix

配置zabbix_server配置文件,zabbix源码目录下

[root@M4 ~]# mkdir /etc/zabbix
[root@M4 ~]# cp config/zabbix_server.conf /etc/zabbix/
[root@M4 ~]# vim /etc/zabbix/zabbix_server.conf
DBName=zabbix
DBUser=root
DBPassword=ttlsapwd
DBPort=3306

4、数据库安装配置

安装:数据库安装 http://yangxx.net/?p=154

初始化数据库

zabbix server与proxy需要数据库,angent不需要。尤其要注意的是proxy只需要导入一个sql文件,而server一共要导入3个sql文件。我当时在搭建proxy的时候导入了3个sql,导致出现报错。后来才发现proxy只需要导入一个表结构即可。
我假想你安装好了MySQL,用户名为root,密码为ttlsapwd

[root@M4 ~]# mysql -uroot -pttlsapwd
mysql> create database zabbix default charset utf8;
mysql> quit;
[root@M4 ~]# mysql -uroot -pttlsapwd zabbix < database/mysql/schema.sql

备注:创建数据库请别忘记加default charset utf8,有可能会导致你出现中文乱码问题

如果你仅仅是初始化proxy的数据库,那么够了。如果初始化server,那么接着导入下面两个sql

[root@M4 ~]# mysql -uroot -pttlsapwd zabbix < database/mysql/images.sql
[root@M4 ~]# mysql -uroot -ppttlsapwd zabbix < database/mysql/data.sql

5、登录web开始配置

192.168.30.6:8095

6、开启zabbix中文

原来zabbix默认把对中文的支持给关闭了,我们需要修改zabbix的php源文件. 修改站点根目录下include/locales.inc.php文件.

[root@M4 ~]# vim include/locales.inc.php
function getLocales() {
        return array(
                'en_GB' => array('name' => _('English (en_GB)'),        'display' => true),
                'en_US' => array('name' => _('English (en_US)'),        'display' => true),
                'bg_BG' => array('name' => _('Bulgarian (bg_BG)'),      'display' => true),
                'zh_CN' => array('name' => _('Chinese (zh_CN)'),        'display' => true),
                //原本这里为false,请改为true
                ...........代码省略掉........
        );
}

7、agent安装

监控主机

安装zabbix-agent

首先需要在被监控的主机上安装agent,可以下载预编译好的RPM进行安装,下载地址:http://www.zabbix.com/download
也可以源码安装,类似server的安装,只是一个地方有区别,就是配置的参数只有一个:

[root@M4 ~]# ./configure –prefix=/home/zabbix --enable-agent

配置agent

以RPM安装为例,安装后的agent配置文件位置:/etc/zabbix/zabbix_agentd.conf,主要需要修改下列2项:

Server=192.168.0.41
ServerActive=192.168.0.41:10051
Hostname=M4
#配置成主机名需要在server hosts文件中添加对应信息或者直接使用本机IP

修改完成后,重启zabbix-agent 服务。