起因:
前面已经使用yum安装了zabbix 3.4了,准备去交差了,交差时老大明确要求必须使用编译安装,统一放在/usr/local目录下。。。。
重来吧!!
一、环境说明
本次安装使用CentOS 7.2的操作系统,Zabbix版本采用的是3.4.11
# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) # uname -a Linux zabbix-101 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
至于系统的一些基本优化可参考本条连接:
http://blog.51cto.com/12217917/2060136
二、开始安装
(一)准备LNMP环境
1、Nginx-1.13.7编译安装
本次使用的是nginx-1.13.7版本的nginx,nginx的下载地址:http://nginx.org/download/
由于我的包是本地之前就有的,这里就不下载了,直接上传了
# yum install openssl openssl-devel pcre pcre-devel -y #安装依赖包 # useradd zabbix -s /sbin/nologin -M #创建启动用户,这里创建的是zabbix用户 # ll /usr/local/src/ -rw-r--r-- 1 root root 990836 Nov 21 2017 nginx-1.13.7.tar.gz # tar xf nginx-1.13.7.tar.gz # cd nginx-1.13.7 # ./configure --user=zabbix --group=zabbix --with-http_ssl_module --with-http_stub_status_module --prefix=/usr/local/nginx-1.13.7/ #指定用户和组,启动ssl和nginx的状态模块同时指定nginx的目录 # make && make install && echo $? #编译成功后进行编译安装 # ln -s /usr/local/nginx-1.13.7 /usr/local/nginx #创建软连接 #/usr/local/nginx/sbin/nginx -t #检查配置文件是否正确 #/usr/local/nginx/sbin/nginx #启动nginx
2、mysql 5.6.34 cmake安装
本次使用的mysql版本为5.6.34,下载地址:https://downloads.mysql.com/archives/get/file/mysql-5.6.34.tar.gz
同样,我的包也是本地之前就有的,我就直接上传安装了
# install ncurses-devel libaio-devel cmake -y #安装依赖及编译工具 # useradd -s /sbin/nologin -M mysql #创建用户 # ll /usr/local/src/ -rw-r--r-- 1 root root 32094762 Mar 15 2017 mysql-5.6.34.tar.gz # tar xf mysql-5.6.34.tar.gz # cd mysql-5.6.34 # cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.34 #cmake编译 -DMYSQL_DATADIR=/usr/local/mysql-5.6.34/data -DMYSQL_UNIX_ADDR=/usr/local/mysql-5.6.34/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_ZLIB=bundled -DWITH_SSL=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_EMBEDDED_SERVER=1 -DENABLE_DOWNLOADS=1 -DWITH_DEBUG=0 # make && make install #编译成功后编译安装 # ln -s /usr/local/mysql-5.6.34 /usr/local/mysql #创建软连接 # cp support-files/my*.cnf /etc/my.cnf #创建mysql的配置文件 # /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --user=mysql #初始化mysql # cp support-files/mysql.server /etc/init.d/mysqld #创建mysql启动脚本 # chmod 700 /etc/init.d/mysqld #修改脚本权限 #/etc/init.d/mysqld start #启动mysql
3、编译安装php-5.6.16
本次使用的php版本为5.6.16,zabbix官网有明文说明,zabbix3.4.0必须使用5.4.0以上的版本的php,下载地址:http://php.net/downloads.php
我的php也是本地的,直接上产安装了
# ll /usr/local/src/ -rw-r--r-- 1 root root 4984397 Jan 16 2017 libiconv-1.14.tar.gz -rw-r--r-- 1 root root 18319620 Nov 9 2017 php-5.6.16.tar.gz # yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel openssl-devel -y #安装依赖(需要repo源) # tar xf libiconv-1.14.tar.gz #手动安装libiconv包, # cd libiconv-1.14 # ./configure --prefix=/usr/local/libiconv # make && make install && cd .. 编译时报错: In file included from progname.c:26:0: ./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function) _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); ^ make[2]: *** [progname.o] Error 1 make[2]: Leaving directory `/home/zy/tools/libiconv-1.14/srclib' make[1]: *** [all] Error 2 make[1]: Leaving directory `/home/zy/tools/libiconv-1.14/srclib' make: *** [all] Error 2 解决办法:cd libiconv-1.14/srclib sed -i -e '/gets is a security/d' ./stdio.in.h # yum install -y libmcrypt-devel mhash mcrypt #安装php扩展库 # tar xf php-5.6.16.tar.gz # cd php-5.6.16 # ./configure --prefix=/usr/local/php-5.6.16 --enable-mysqlnd --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --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=zabbix --with-fpm-group=zabbix --enable-ftp --enable-opcache=no # ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/ #防止编译时报错 # touch ext/phar/phar.phar.phar #防止编译时报错 # make && make install #编译成功后编译安装 # ln -s /usr/local/php-5.6.16 /usr/local/php # cp -a /usr/local/src/php-5.6.16/php.ini-production /usr/local/php/lib/php.ini #配置php.ini # cd /usr/local/php/etc/ # cp php-fpm.conf.default php-fpm.conf #配置php配置文件 # /usr/local/php/sbin/php-fpm #启动php
(二)编译安装Zabbix
1、安装zabbix
标题已经说明了,本次安装的是zabbix-3.4.11版本,下载地址:https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.4.11/zabbix-3.4.11.tar.gz/download
# yum -y install fping net-snmp-devel unixODBC-devel openssl-devel OpenIPMI-devel java-devel #安装依赖包 # zabbix用户前面已经创建了 # tar xf zabbix-3.4.11.tar.gz #我本地有这个包,直接上传的 # cd zabbix-3.4.11 # ./configure --prefix=/usr/local/zabbix-3.4.11 --enable-server --enable-agent --enable-java --enable-ipv6 --with-mysql=/usr/local/mysql-5.6.34/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-unixodbc --with-openssl --with-mysql=mysqlnd
编译时遇到的报错及解决办法:
CentOS 7.2编译安装时报这个错的解决办法:configure: error: LIBXML2 library not found
解决:yum install libxml2-devel
CentOS 7.2编译安装时报这个错的解决办法:configure: error: Unable to use libevent (libevent check failed)
解决:yum install -y libevent libevent-devel
CentOS 7.2编译安装时报这个错的解决办法:configure: error: Curl library not found
解决:yum install libcurl-devel
# make && make install #问题都解决后编译安装即可 # ln -s /usr/local/zabbix-3.4.11 /usr/local/zabbix #创建软连接
2、创建数据库、授权及导入数据
create database zabbix character set utf8 collate utf8_bin; #创建库 grant all on zabbix.* to zabbix@'%' identified by 'zabbix'; #创建用户并授权 grant all on zabbix.* to zabbix@'localhost' identified by 'zabbix'; #创建用户并授权 flush privileges; #刷新权限
导入数据库:
usr zabbix; source /usr/local/src/zabbix-3.4.11/database/mysql/schema.sql; source /usr/local/src/zabbix-3.4.11/database/mysql/images.sql; source /usr/local/src/zabbix-3.4.11/database/mysql/data.sql; 说明:导入的线后顺序为:1、schema.sql(表结构、首先导入),2、images.sql(图型、其次导入),3、data.sql(数据、最后导入),如果不按顺序可能会报错!!
3、配置nginx
1、创建web代码目录并上传代码
# mkdir /usr/local/nginx/html/zabbix # cp -a /usr/local/src/zabbix-3.4.11/frontends/php/* /usr/local/nginx/html/zabbix # chown -R zabbix.zabbix /usr/local/nginx/html/zabbix
2、配置nginx配置文件为
# cat /usr/local/nginx/conf/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; root html/zabbix; location / { root html/zabbix; index index.php index.html index.htm; } location ~ .*.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } access_log logs/zabbix.log; } }
4、配置PHP
1、修改php.ini的参数大小
# vim /usr/local/php/lib/php.ini 660 post_max_size = 8M #改为16M 372 max_execution_time = 30 #改为300 382 max_input_time = 60 #改为300 704 ;always_populate_raw_post_data = -1 #取消注释 926 ;date.timezone = #时区设置为上海 date.timezone = Asia/Shanghai
这是官网给的php配置:
2、添加php模块
1、gettext模块 # cd /usr/local/src/php.5.6.16/ext/gettext/ # /usr/local/php/bin/phpize # ./configure --with-php-config=/usr/local/php/bin/php-config # make && make install # echo "extension = gettext.so" >>/usr/local/php/lib/php.ini 2、ldap模块 # cd /usr/local/src/php.5.6.16/ext/ldap/ # /usr/local/php/bin/phpize # ./configure --with-php-config=/usr/local/php/bin/php-config --with-ldap # make && make install # echo "extension = ldap.so" >>/usr/local/php/lib/php.ini 报错:configure: error: Cannot find ldap libraries in /usr/lib. 解决:cp -a /usr/lib64/libldap* /usr/lib/ 增加完模块后重启php进程
5、配置zabbix
1、修改zabbix-server
# egrep -v "^#|^$" zabbix_server.conf LogFile=/tmp/zabbix_server.log PidFile=/tmp/zabbix_server.pid DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=¥database-passwd DBSocket=/tmp/mysql.sock Timeout=4 LogSlowQueries=3000 Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf
2、修改zabbix-agent
# egrep -v "^#|^$" zabbix_agentd.conf PidFile=/tmp/zabbix_agentd.pid LogFile=/tmp/zabbix_agentd.log Server=$zabbix-server-IP ServerActive=$zabbix-server-IP Hostname=Zabbix server Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
6、启动zabbix和nginx
# /usr/local/zabbix/sbin/zabbix_server #启动zabbix-server # /usr/local/nginx/sbin/nginx -t # /usr/local/nginx/sbin/nginx #启动nginx
三、访问zabbix
浏览器访问:http://zabbix.71net.com/zabbix #其中zabbix.71net.com是你的zabbix服务器的IP地址或域名
1、进入zabbix页面
2、检查服务是否都安装了(必须都是绿色的)
3、连接数据库配置
4、配置后台
5、确认信息
6、登陆zabbix控制台(默认用户名:Admin,密码:zabbix)
7、修改控制台的字符集为中文