部署zabbix监控服务器
                          Date:Wed  Jul  1  23:16:28 CST 2016

1、需要的组件:
zabbix-3.0.3.tar.gz   http://www.zabbix.com/download.php  #官网下载页面
http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.0.3/zabbix-3.0.3.tar.gz/download  #下载链接

nginx-1.10.1.tar.gz  http://nginx.org/en/download.html #官网下载页面
http://nginx.org/download/nginx-1.10.1.tar.gz          #下载链接

php-5.6.22.tar.gz  http://php.net/downloads.php     #官网下载页面
http://php.net/get/php-5.6.22.tar.gz/from/a/mirror  #下载链接列表
http://cn2.php.net/get/php-5.6.22.tar.gz/from/this/mirror  #选择中国站点下载

2、配置yum仓库
[root@zabbix-server-1 yum.repos.d]# cat zabbix.repo
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=1


yum clean all  # 清除yum缓存
yum makecache  # 生成yum缓存

3、安装nginx
#安装依赖包
yum install pcre pcre-devel openssl openssl-devel gcc-c++
useradd -s /sbin/nologin -M nginx
tar xf nginx-1.10.1.tar.gz
./configure --user=nginx --group=nginx --prefix=/application/nginx-1.10.1 --with-http_stub_status_module --with-http_ssl_module
make
make install
ln -s /application/nginx-1.10.1/ /application/nginx
/application/nginx/sbin/nginx #start nginx service

ps -ef|grep nginx
ss -lntup|grep nginx
[root@zabbix-server-1 conf]# pwd
/application/nginx/conf

egrep -v "#|^$" nginx.conf.default > nginx.conf

#修改部分配置
[root@zabbix-server-1 conf]# cat nginx.conf
worker_processes  1;
events {
worker_connections  1024;
}
http {
include       mime.types;
default_type  application/octet-stream;
sendfile        on;
keepalive_timeout  65;
server {
listen       80;
server_name  localhost;
location / {
root   html;
index  index.php index.html index.htm;
}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;
}
location ~\.(php|php5)?$ {
root /application/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /application/nginx/html$fastcgi_script_name;
include    fastcgi_params;
}
}
}

#杀死进程,重启服务
ps -ef|grep nginx
/application/nginx/sbin/nginx -t
/application/nginx/sbin/nginx 

4、安装php
#安装依赖
yum install zlib-devel libxml2-devel libjpeg-devel libiconv-devel freetype-devel libpng-devel gd-devel curl-devel libxslt-devel mysql-devel

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz   
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install

#添加epel源
#https://fedoraproject.org/wiki/EPEL
#上面这个位置找到对应的系统版本进入
#centos 6 x86_64 https://dl.fedoraproject.org/pub/epel/6/x86_64/
#https://dl.fedoraproject.org/pub/epel/              #通过这个页面下载对应的epel yum源安装包
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
yum install libmcrypt-devel mhash mcrypt

#编译安装php:
tar xf php-5.6.22.tar.gz
cd php-5.6.22
./configure \
--prefix=/application/php-5.6.22 \
--with-mysql \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-gettext \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp \
--enable-opcache=no

make
make install

ln -s /application/php-5.6.22/ /application/php
[root@zabbix-server-1 php-5.6.22]# pwd
/root/php-5.6.22

[root@zabbix-server-1 php-5.6.22]# cp php.ini-production /application/php/lib/php.ini
[root@zabbix-server-1 php-5.6.22]# cd /application/php/etc/
[root@zabbix-server-1 etc]# ls
pear.conf  php-fpm.conf.default
[root@zabbix-server-1 etc]# pwd
/application/php/etc
[root@zabbix-server-1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@zabbix-server-1 etc]# /application/php/sbin/php-fpm
[root@zabbix-server-1 etc]# netstat -lntup|grep php-fpm
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      3689/php-fpm

5、开始安装zabbix
tar zxvf zabbix-3.0.3.tar.gz
cd zabbix-3.0.3
groupadd zabbix
useradd -g zabbix zabbix

#安装依赖包,如果一次安装错误,就多试几次
yum install -y net-snmp net-snmp-devel libssh2-devel OpenIPMI-devel

./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-ssh2
 
make && make install

egrep -v "#|^$" /usr/local/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBHost=192.168.11.5
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
ListenIP=0.0.0.0
Timeout=4
AlertScriptsPath=${datadir}/zabbix/alertscripts
LogSlowQueries=3000

#拷贝启动脚本
cp misc/init.d/fedora/core/zabbix_* /etc/rc.d/init.d/

zabbix_server
#修改配置文件
vim /application/php/lib/php.ini
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
always_populate_raw_post_data = -1
date.timezone = Asia/Shanghai

#重启php
[root@zabbix-server-1 zabbix-3.0.3]# pkill -9 php-fpm
[root@zabbix-server-1 zabbix-3.0.3]# /application/php/sbin/php-fpm

#从zabbix源码包拷贝网站到nginx
[root@zabbix-server-1 zabbix-3.0.3]# pwd
/root/zabbix-3.0.3
[root@zabbix-server-1 zabbix-3.0.3]# cp -rf frontends/php /application/nginx/html/zabbix/

#如果有防火墙,要么开放80端口,要么临时停止
service iptables stop

6.mysql 5.6.32的安装。
[root@zabbix-6 ~]# rpm -ivh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
Retrieving http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
Preparing...                ########################################### [100%]
   1:mysql-community-release########################################### [100%]
[root@zabbix-6 ~]# yum install mysql-server -y
......
Installed:
  mysql-community-libs.x86_64 0:5.6.29-2.el6    mysql-community-libs-compat.x86_64 0:5.6.29-2.el6    mysql-community-server.x86_64 0:5.6.29-2.el6   
Dependency Installed:
  mysql-community-client.x86_64 0:5.6.29-2.el6          mysql-community-common.x86_64 0:5.6.29-2.el6          perl-DBI.x86_64 0:1.609-4.el6         

Dependency Updated:
  postfix.x86_64 2:2.6.6-6.el6_7.1                                                                                                                  
Replaced:
  mysql-libs.x86_64 0:5.1.71-1.el6                                                                                                                  
Complete!

#修改mysql配置文件. /etc/my.cnf,在[mysqld]中添加innodb_file_per_table=1,并登录数据库,创建zabbix 数据库以及授权zabbix用户。
[root@zabbix-6 ~]# grep -v "^#"  /etc/my.cnf | grep -v "^$"
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
innodb_file_per_table=1
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[root@zabbix-6 ~]# service mysqld start
lsof -i:3306

#导入数据库   
mysql -e "create database zabbix character set utf8;"
mysql  -e "grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix';"
mysql  -e "flush privileges;"  

#注意路径
mysql -uzabbix -pzabbix zabbix  create database zabbix character set utf8 collate utf8_bin;
#mysql> grant all privileges on zabbix.* To zabbix@localhost identified by 'testzabbix';    (testzabbix 密码根据自己要求设置,后期安装zabbix-server需要)
---------------------------

#给目录设置权限
chown -R nginx.nginx /application/nginx/html/
打开浏览器,输入以下链接
http://192.168.11.11/zabbix/setup.php