本文介绍zabbix3.0.2的安装历程:
源码包:http://pan.baidu.com/s/1gflpa2v http://pan.baidu.com/s/1kVcZuOf http://pan.baidu.com/s/1qYzPKde http://pan.baidu.com/s/1pLaPt7l
一、 php安装
二、 zabbix安装
1.环境依赖
2.安装依赖
3.zabbix安装
4.zabbix数据库初始化
5.zabbix-server配置
6.启动zabbix-server服务
7.zabbix-web部署
8.使用nginx代理
9.在线配置zabbix
一、php安装
1.上传php-5.6.20.tar.bz2 到 /usr/local/src/ 并解压
tar -jxf php-5.6.20.tar.bz2
2.安装php依赖
yum groupinstall 'Development Tools'
yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel -y
3.编译并安装php
cd /usr/local/src/php-5.6.20
./configure --prefix=/usr/local/php-5.6.20 --with-config-file-path=/usr/local/php-5.6.20/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --enable-bcmath --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --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
#如安装不成功, 可make clean下再安装
4.配置文件
cd /usr/local/php-5.6.20/etc
cp /usr/local/src/php-5.6.20/php.ini-production php.ini
mv php-fpm.conf.default php-fpm.conf
vi /usr/local/php-5.6.20/etc/php.ini
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone = PRC
always_populate_raw_post_data = -1
5.启动php-fpm
/usr/local/php-5.6.20/sbin/php-fpm
netstat -lnt | grep 9000
6.nginx代理
1)nginx安装
cd /usr/local/src/
上传nginx-1.9.12.tar.gz至/usr/local/src/目录
tar -zxf nginx-1.9.12.tar.gz
cd nginx-1.9.12
./configure --prefix=/usr/local/nginx-1.9.12 --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre
make
make install
2)配置
#创建保存日志目录
mkdir -p /data/logs/nginx
#创建phpweb目录
mkdir -p /data/site/phpweb
#写个测试php
cd /data/site/phpweb
vi info.php
#内容:
phpinfo();
?>
#使用nginx部署并代理
vi /usr/local/nginx-1.9.12/conf/nginx.conf
server {
listen 12582;
server_name php.fangcang.com;
access_log /data/logs/nginx/phpweb.access.log;
index index.php index.html index.html;
root /data/site/phpweb;
location /
{
try_files $uri $uri/ /index.php?$args;
}
location ~ .*\.(php)?$
{
expires -1s;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
}
启动或重启nginx:
/usr/local/nginx/sbin/nginx -s (start|reload)
测试是否安装成功:
http://yourhost:12582/info.php
二、zabbix安装
1.环境依赖
1) mysql-devel mysql-libs
2) net-snmp-devel
3) curl-devel
2.安装依赖
yum -y install net-snmp-devel mysql-devel mysql-libs curl-devel
后面发现yum源自带的msyql包比较古老,zabbix-3.0.2依赖mysql5.6的开发库.
直接安装mysql5.6到/usr/local/mysql
上传mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz,并解压到/usr/local/mysql即可
执行:
echo "/usr/local/mysql/lib/" >> /etc/ld.so.conf
ldconfig
详细安装请移步:http://strongit.blog.51cto.com/10020534/1659265
3.zabbix安装
上传zabbix-3.0.2.tar.gz 至 /usr/local/src 并解压(安装完后不要删除源码包,后面还要用到)
cd /usr/local/src/zabbix-3.0.2
编译:
./configure --prefix=/usr/local/zabbix-3.0.2/ --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
安装:
make
make install
如安装不成功,make clean后再安装。
4.zabbix数据库初始化
连接mysql数据库,如用户名密码为: root/tty2016
mysql -uroot -ptty2016
mysql> create database zabbix default charset utf8;
mysql> quit
根据sql导入数据:
如果是初始化zabbix-server,则导入下面3个sql:
mysql -uroot -ptty2016 zabbix < /usr/local/src/zabbix-3.0.2/database/mysql/schema.sql
mysql -uroot -ptty2016 zabbix < /usr/local/src/zabbix-3.0.2/database/mysql/p_w_picpaths.sql
mysql -uroot -ptty2016 zabbix < /usr/local/src/zabbix-3.0.2/database/mysql/data.sql
如果仅初始化zabbix-proxy,则导入下面这个sql即可(导多了会报错):
mysql -uroot -ptty2016 zabbix < /usr/local/src/zabbix-3.0.2/database/mysql/schema.sql
5.zabbix-server配置
vi /usr/local/zabbix-3.0.2/etc/zabbix_server.conf
DBName=zabbix
DBUser=root
DBPassword=tty2016
DBPort=3306
6.启动zabbix-server服务
root环境下,zabbix-server默认会以zabbix用户启动,所以先创建zabbix用户
groupadd zabbix
useradd -g zabbix zabbix
启动:
启动zabbix-server服务:
cd /usr/local/zabbix-3.0.2
./sbin/zabbix_server
启动后,如报./sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
执行下面2个命令:
echo "/usr/local/mysql/lib/" >> /etc/ld.so.conf
ldconfig
如报:./sbin/zabbix_server: error while loading shared libraries: libnetsnmp.so.25: cannot open shared object file: No such file or directory
同理:
echo "/usr/local/net-snmp-5.6.2.1/lib/" >> /etc/ld.so.conf
Ldconfig
./sbin/zabbix_server
启动zabbix-agent
./sbin/zabbix_agentd
7.zabbix-web部署
1)拷贝前端文件
mkdir -p /data/logs/nginx
mkdir -p /data/site/zabbix
cd /data/site/zabbix/
cp -rp /usr/local/src/zabbix-3.0.2/frontends/php/* .
8.使用nginx代理
将原来安装php用于测试的server删掉,加上以下内容:
nginx启动用户设为root:
user root;
配置服务:
server {
listen 12582;
server_name zabbix.fangcang.com;
access_log /data/logs/nginx/zabbix.access.log;
index index.php index.html index.html;
root /data/site/zabbix;
location /
{
try_files $uri $uri/ /index.php?$args;
}
location ~ .*\.(php)?$
{
expires -1s;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
}
9.在线配置zabbix
http://yourhost:12582/zabbix
1)进入配置页面
2)检查环境和配置
往下拉动滚动条,确保所有项目都是OK状态。
3)数据库配置
4)直接下一步即可
5)直接下一步
6)自动生成配置文件
如遇上述问题:一般是php对/data目录没有写权限
我搭建的环境里php-fpm运行:
ps -aux | grep php-fpm
将/data目录为nobody用户赋予rwx权限:
setfacl -m u:nobody:rwx -R /data
7)登录
zabbix默认用户为admin/zabbix
8)自定义脚本配置
上传alertscripts.tar.gz包,解压到/usr/local/zabbix-3.0.2/alertscripts;
配置alertscripts
vi /usr/local/zabbix-3.0.2/etc/zabbix_server.conf
内容:
AlertScriptsPath=/usr/local/zabbix-3.0.2/alertscripts
配置自定义命令
vi /usr/local/zabbix-3.0.2/etc/zabbix_agentd.conf
UserParameter=mysql.ping[*],/usr/local/mysql-5.6.21/bin/mysqladmin -u$1 -p$2 ping 2> /dev/null | grep -c alive
UserParameter=port.ping[*],/usr/local/zabbix-3.0.2/alertscripts/netstat.sh $1
UserParameter=curl.metric[*],/usr/local/zabbix-3.0.2/alertscripts/curl.sh $1
安装zabbix-agent3.0.2 yum install unixODBC unixODBC-devel postgresql-libs rpm -ivh http://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/zabbix-agent-3.0.2-1.el7.x86_64.rpm
好了,zabbix安装已经完成。