zabbix-3.0源码编译安装

第1章 zabbix3.0安装部署文档

摘要

本文的安装过程摘自http://www.ttlsa.com/以及http://b.lifec-inc.com ,和站长凉白开的《ZABBIX从入门到精通v3.0.1 - 运维生存时间(2016)》一书。
关于zabbix及相关服务软件版本:

Linux:centos 6.6
nginx:1.9.15
MySQL:5.5.49
PHP:5.5.35

第2章 安装nginx

2.1 安装依赖包

yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel

2.2 创建用户

useradd nginx -s /sbin/nologin -M

2.3 下载nginx软件包并进入到目录中

wget http://nginx.org/download/nginx-1.9.15.tar.gz && tar xvf nginx-1.9.15.tar.gz && cd nginx-1.9.15

2.4 编译

./configure --prefix=/opt/nginx --user=www --group=www --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre
make && make install

参数解释:

--with-http_stub_status_module:支持nginx状态查询
--with-http_ssl_module:支持https
--with-http_spdy_module:支持google的spdy,想了解请百度spdy,这个必须有ssl的支持
--with-pcre:为了支持rewrite重写功能,必须制定pcre

第3章 安装PHP

3.1 下载PHP安装包

wget http://cn2.php.net/get/php-5.5.35.tar.gz/from/this/mirror

3.2 解压并编译

mv mirror php-5.5.35.tar.gz && tar xvf php-5.5.35.tar.gz && cd php-5.5.35
./configure --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/opt/ --with-png-dir=/opt/ --with-freetype-dir=/opt/ --enable-gd-native-ttf --with-iconv-dir=/opt/ --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/opt/ --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
make && make install
cp php.ini-production /opt/php/etc/php.ini
cd /opt/php/etc/
cp php-fpm.conf.default php-fpm.conf

3.3 修改php.ini参数

(zabbix环境需要修改的参数)

max_execution_time = 300 
memory_limit = 128M 
post_max_size = 16M 
upload_max_filesize = 2M 
max_input_time = 300 
date.timezone = PRC

第4章 安装MySQL

4.1 添加mysql用户,创建mysql的数据目录

groupadd mysql
mkdir -pv /opt/mysql/data/
useradd -r -g mysql -d /opt/mysql/data -s /sbin/nologin mysql
chown -R mysql.mysql /opt/mysql/data/

4.2 安装cmake及依赖

yum install cmake gcc* ncurses-devel -y 

4.3 下载MySQL安装包

wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49.tar.gz

4.4 编译安装MySQL

tar -xvf mysql-5.5.49.tar.gz && cd mysql-5.5.49
cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql -DDEFAULT_CHARSET=utf8 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/opt/mysql/data -DWITH_EXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DDEFAULT_COLLATION=utf8_general_ci
make && make install
chown -R mysql.mysql /opt/mysql

4.5 拷贝mysql的配置文件

cd /opt/mysql/support-files/
cp my-medium.cnf /opt/mysql/data/my.cnf
cp mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld

4.6 初始化MySQL

cd /opt/mysql/scripts
./mysql_install_db --user=mysql --basedir=/opt/mysql/ --datadir=/opt/mysql/data/

4.7 修改MySQL配置文件my.cnf中数据目录

datadir=/opt/mysql/data/

4.8 启动MySQL

/etc/init.d/mysqld start
Starting MySQL... SUCCESS!

4.9 创建zabbix数据库及用户名和密码

mysql> create database zabbix default charset utf8;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix';
Query OK, 0 rows affected (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)

4.10 如果登录数据库出现问题

mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

解决办法:

[root@zabbix ~]# ln -s /tmp/mysql.sock /var/lib/mysql/

4.11 为数据库的root创建密码

mysqladmin -uroot password  "zabbix"

第5章 安装zabbix server

5.1 安装zabbix

安装包在百度网盘上

tar zxf zabbix-3.2.5.tar.gz && cd zabbix-3.2.5

编译zabbix:

./configure --prefix=/opt/zabbix/ --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --enable-ipv6 --with-ssh2 --enable-java(监控tomcat要加的编译参数)
make && make install

5.2 报错解决

1、故障:

checking for mysql_config... no
configure: error: MySQL library not found

解决:

yum install mysql-devel -y

2、故障:

checking for net-snmp-config... no
configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config

解决:

yum install net-snmp-devel -y

3、报错如下:

checking for SSH2 support... no
configure: error: SSH2 library not found

解决办法:

yum -y install libssh2-devel

4、上面一个报错解决了,继续./configure,又出现如下错误:

checking for LDAP support... no
configure: error: Invalid LDAP directory - unable to find ldap.h

解决办法:

yum -y install openldap openldap-devel

5、缺少相关C/C++编译器:

configure: error: in `/zabbix/zabbix-3.0.4':
configure: error: no acceptable C compiler found in $PATH

安装C++编译器:

yum install gcc* -y

6、缺少mysql的开发库:

configure: error: MySQL library not found

安装mysql-devel:

yum install mysql-devel -y

7、缺少libxml2的开发库:

configure: error: LIBXML2 library not found

安装libxml2的开发库:

yum install libxml2-devel -y

8、缺少net-snmp以及其安装库:

configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config

安装net-snmp及其安装库:

yum install net-snmp* -y

9、缺少java的开发库:

configure: error: Unable to find "javac" executable in path

安装java的开发库:

yum install java* -y

10、缺少curl的开发库:

configure: error: Curl library not found

安装curl的开发库:

yum install curl-devel -y

5.3 创建zabbix用户

groupadd zabbix
useradd zabbix -s /sbin/nologin -M -g zabbix

5.4 zabbix server需要导入3个sql文件

#进入zabbix解压目录

mysql -uzabbix -pzabbix zabbix < database/mysql/schema.sql 
mysql -uzabbix -pzabbix zabbix < database/mysql/images.sql 
mysql -uzabbix -pzabbix zabbix < database/mysql/data.sql 

第6章 zabbix管理网站配置(nginx)

6.1 创建项目目录

mkdir /data/web/zabbix.lifec.com -p
mkdir /data/logs/zabbix -p

6.2 将前端文件拷贝到项目目录下

#进入zabbix解压目录

cp -rp frontends/php/* /data/web/zabbix.lifec.com/

6.3 编辑nginx虚拟主机

#进入nginx的conf目录

mkdir extra
cd extra/
vim zabbix.conf
server {
listen 8027;
server_name zabbix.lifec.com;
access_log /data/logs/zabbix/zabbix.lifec.com.access.log main;
index index.html index.php index.html;
root /data/web/zabbix.lifec.com;
location /{
       try_files $uri $uri/ /index.php?$args;
}
location ~ ^(.+.php)(.*)$ {
       fastcgi_split_path_info ^(.+.php)(.*)$;
       include fastcgi.conf;
       fastcgi_pass 127.0.0.1:9000;
       fastcgi_index index.php;
       fastcgi_param PATH_INFO $fastcgi_path_info;
}
}

6.4 编辑nginx.conf配置文件

cat nginx.conf
user  nginx;
worker_processes  1;
#error_log  logs/error.log warning;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    include extra/*.conf;
}
编辑zabbix_server.conf文件:
vim /opt/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix

第7章 启动服务

7.1 启动nginx

/opt/nginx/sbin/nginx

7.2 启动PHP

/opt/php/sbin/php-fpm

7.3 启动zabbix server

/opt/zabbix/sbin/zabbix_server
如果启动的时候报错
/opt/zabbix/sbin/zabbix_server
/opt/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
ln -s /opt/mysql/lib/libmysqlclient.so.18 /usr/lib64/

7.4 添加/etc/hosts文件

192.168.119.140 zabbix.lifec.com

7.5查看服务端口

netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1029/sshd           
tcp        0      0 0.0.0.0:8027                0.0.0.0:*                   LISTEN      3730/nginx          
tcp        0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      3743/zabbix_server  
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      3736/php-fpm        
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      24922/mysqld        
tcp        0      0 :::22                       :::*                        LISTEN      1029/sshd           
udp        0      0 0.0.0.0:68                  0.0.0.0:*                               880/dhclient   

7.6 将服务加入开机自启动

echo "/opt/nginx/sbin/nginx" >>/etc/rc.local 
echo "/opt/php/sbin/php-fpm" >>/etc/rc.local 
echo "/etc/init.d/mysqld start" >>/etc/rc.local
echo "/opt/zabbix/sbin/zabbix_server" >>/etc/rc.local

7.7 web端配置zabbix

需要下载文件,并上传到指定的服务器目录中。
修改界面为中文界面
默认登录界面为英文:
修改以下配置,并重启服务即可;

vim /data/web/zabbix.lifec.com/include/locales.inc.php
      #'zh_CN' => ['name' => _('Chinese (zh_CN)'), 'display' => false],
      'zh_CN' => ['name' => _('Chinese (zh_CN)'), 'display' => true],

为了防止图形中的字符出现乱码:
需要自己上传字体:
将选择的字体上传到Linux服务器的zabbix的fonts目录:

/data/web/zabbix.lifec.com/fonts

并修改以下配置:

vim /data/web/zabbix.lifec.com/include/defines.inc.php
define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans'); // font file name
define('ZBX_GRAPH_FONT_NAME', 'simsun'); // font file name        ==>此行为新增行;
define('ZBX_FONT_NAME', 'DejaVuSans');
define('ZBX_FONT_NAME', 'simsun');       ==>此行为新增行;

重启服务即可。

第8章 报错处理

8.1 编译错误处理

以下操作可能需要第三方源,参考此进行安装第三方Yum源

rpm -ivh  http://ftp.sjtu.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm     configure: error: Jabber library not found  #yum install iksemel-devel即可,   configure: error: LIBXML2 library not found    #yum install libxml2-devel   configure: error: unixODBC library not found    #yum install unixODBC-devel   configure: error: Invalid OPENIPMI directory - unable to find ipmiif.h    #yum install OpenIPMI-devel   configure: error: Unable to find "javac" executable in path    
#yum install java*    

具体什么包没找,直接通配算逑,生产环境可去掉–enable-java选项

configure: error: Curl library not found  
#yum install curl-devel

8.2 Web界面报错处理

Cannot create the configuration file.
Details
•	Unable to create the configuration file.
Alternatively, you can install it manually:
1.	Download the configuration file
2.	Save it as "/data/web/zabbix.lifec.com/conf/zabbix.conf.php"

解决方法:已经给出,点击Download the configuration file下载文件,并将其上传到

/data/web/zabbix.lifec.com/conf/zabbix.conf.php

文件内容如下

vim zabbix.conf.php

你可能感兴趣的:(Zabbix,zabbix)