Z.S.K.'s Records

zabbix学习(zabbix-server安装)

其它的话就不多说了, 上来说是干吧

环境说明:

  • zabbix-3.2.6
  • centos-6.4
  • mysql-5.7.18
  • nginx-1.8
  • php-5.6

NLMP环境安装

mysql-5.7.18安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#1、安装mysql依赖
[root@www ~]# yum install gcc gcc-c++ zlib-devel libtool ncurses-devel openssh-clients cmake ncurses bison

#2、新建mysql用户并将mysql系统用户的密码修改为mysql
[root@www ~]# groupadd mysql
[root@www ~]# useradd -g mysql mysql
[root@www ~]# passwd mysql

#3、mysql-5.7需要安装boost_1_59_0.tar.gz,且编译器使用cmake
[root@www ~]# tar zxvf boost_1_59_0.tar.gz
[root@www ~]# tar mysql5.7.tar.gz
[root@www ~]# cd mysql5.7
[root@www ~]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DWITH_BOOST=../boost_1_59_0 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0
[root@www ~]# make && make install

#4、初始化mysql
[root@www ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@www ~]# chmod a+x /etc/init.d/mysqld
[root@www ~]# chown -R mysql:mysql /etc/init.d/mysqld
[root@www ~]# chown -R mysql:mysql /usr/local/mysql
[root@www ~]# chown -R mysql:mysql /data/mysql
[root@www ~]# chown -R mysql:mysql /etc/my.cnf

#5、修改mysql配置文件/etc/my.cnf

#6、加入开机启动
[root@www ~]# chkconfig --add mysqld

#7、把mysql路径添加到/etc/ld.so.conf
[root@www ~]# echo "/usr/local/mysql/include/" >>/etc/ld.so.conf
[root@www ~]# echo "/usr/local/mysql/bin/" >>/etc/ld.so.conf
[root@www ~]# ldconfig

#8、修改/etc/profile在最后添加
[root@www ~]# vi /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
[root@www ~]# source /etc/profile

#9、执行
[root@www ~]#mysqld –tmpdir=/home/mysql/mysqltmp --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

#10、使用mysql用户启动mysql
[mysql@www ~]$ service mysqld start

#11、切换回root,修改mysql数据库中root用户的登陆密码
[root@www ~]# mysql_secure_installation
#一路输入Y即可,其中会询问设置密码的强度,请根据自身需要设置,如果选择密码强度为高,则密码需要符合强度要求才能继续,不然会提示密码强度不够,这里密码修改为Mysql0000#

#12、给root用户授权
[root@www ~]# mysql -uroot -pMysql0000#
mysql> use mysql;
mysql > grant all privileges on *.* to 'root'@localhost;
mysql > grant all privileges on *.* to 'root'@’100.12.255.160’;
mysql > flush privileges;

#根据实际情况改为服务器的ip地址

PHP安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#1、php依赖关系
[root@www ~]# yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers gd gd2 gd-devel gd2-devel perl-CPAN pcre-devel

#2、注意:centos源不能安装libmcrypt-devel,由于版权的原因没有自带mcrypt的包
使用php mcrypt 前必须先安装Libmcrypt 这个需要源码编译安装,且版本要大于2.5.6
[root@www ~]# tar zxvf libmcrypt.tar.gz
[root@www ~]# ./configure
[root@www ~]# make && make install

#3、对php的编译要求如下,不然的话在最后前端生成zabbix前台的时候模块会检验不过:
[root@www ~]#./configure --prefix=/usr/local/php --with-config-file-path=/etc/php/ --with-bz2 --with-curl --enable-mbstring --enable-calendar --enable-gd-native-ttf --enable-ftp --enable-sockets --enable-dom --enable-shmop --enable-fpm --enable-ctype --enable-session --enable-xmlwriter --enable-xmlreader --enable-bcmath --enable-xml --enable-opcache --enable-sysvmsg --enable-sysvsem --enable-zip --disable-ipv6 --disable-rpath --disable-debug --disable-fileinfo --with-libdir=lib64 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --with-iconv-dir=/usr/local --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-mysql --with-curl --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --with-openssl --with-mhash --with-xmlrpc --with-mcrypt
[root@www ~]# make && make install

#4、编译安装完成之后 在/usr/local/php/etc/或是/etc/php下都没有php.ini文件 所以需要cp一个模板文件到/etc/php/下
[root@www ~]# cp php.ini-production /etc/php/php.ini
#打开php.ini配置文件,找到如下参数,修改为如下值,否则zabbix安装不了

upload_max_filesize = 2M
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 32M
date.timezone = Asia/Shanghai
mbstring.func_overload = 0
session.auto_start = 0
always_populate_raw_post_data = -1

[root@www ~]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@www ~]# cp /usr/local/src/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@www ~]# chmod a+x /etc/init.d/php-fpm
[root@www ~]# chkconfig --add php-fpm
[root@www ~]# /etc/init.d/php-fpm start

#若访问前台报502 bad gateway时,修改 /usr/local/php/etc/php-fpm.ini里global中的pid=run/php-fpm.pid前的注释去掉 重启php-fpm

Nginx1.8安装

1
2
3
4
5
6
7
8
9
10
11
12
13
#1、新建www用户
[root@www ~]# groupadd www
[root@www ~]# useradd -g www www
[root@www ~]# passwd www
#密码修改为www

#2、把nginx-1.8.0.tar.gz放到/usr/local/src
[root@www ~]# tar zxvf nginx-1.8.0.tar.gz
[root@www ~]# cd nginx-1.8.0
[root@www ~]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
[root@www ~]# cd /usr/local/nginx/conf

#3. 修改nginx的配置文件nginx.conf

Zabbix3安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#1、zabbix依赖
[root@www ~]# yum install gcc mysql-devel net-snmp-devel net-snmp curl-devel perl-DBI php-gd php-ctype php-mysql php-bcmath php-mbstring php-xml php-session php-sockets php-gettext php-xmlreader php-xmlwriter libxml2-devel libcurl-devel unixODBC unixODBC-devel libssh2-devel libssh2 OpenIPMI-devel OpenIPMI OpenIPMI-libs

#2、新建系统用户
[root@www ~]#groupadd zabbix
[root@www ~]#useradd -g zabbix -m zabbix
[root@www ~]#passwd zabbix
#密码修改为 zabbix

#3、创建zabbix数据库,新建的mysql数据库用户zabbix,密码也设为zabbix
[root@www ~]#mysql -uroot -pMysql0000#
mysql>use mysql;
mysql>create database zabbix character set utf8;
mysql>grant all privileges on zabbix.* to zabbix@'100.12.255.160' identified by 'Zabbix0000#';
mysql>grant all privileges on zabbix.* to zabbix@'localhost' identified by 'Zabbix0000#';
mysql>grant all privileges on zabbix.* to zabbix@'127.0.0.1' identified by 'Zabbix0000#';
mysql>flush privileges;
mysql>exit;
#红色标注的为zabbix服务器的地址,zabbix0000#为数据库用户zabbix设置的密码

#4、从zabbix.tar.gz源文件中导入zabbix数据库文件
[root@www ~]# tar -zxvf zabbix-3.2.6.tar.gz
[root@www ~]# cd zabbix-3.2.6/database/mysql
[root@www ~]# mysql -uroot -pMysql0000# zabbix < schema.sql
[root@www ~]# mysql -uroot -pMysql0000# zabbix < images.sql
[root@www ~]# mysql -uroot -pMysql0000# zabbix < data.sql

#5、服务器端编译
[root@www ~]# ./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openssl --with-unixodbc --with-ssh2 --with-openipmi
[root@www ~]# make && make install

#6、添加服务端口:(可能这个配置文件中已有如下内容则不需要添加)
[root@www ~]# vim /etc/services
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper

#7、服务端copy源码包中的前端文件
[root@www ~]# mkdir -p /usr/local/nginx/html/zabbix
[root@www ~]# cp -rf /usr/local/src/zabbix-3.2.6/frontends/php/* /usr/local/nginx/html/zabbix/ #虚拟主机目录
[root@www ~]# chown -R zabbix:zabbix /usr/local/nginx/html/zabbix

#8、修改zabbix的GUI配置文件:
[root@www~]#cp /usr/local/nginx/html/zabbix/conf/zabbix.conf.php.default /usr/local/nginx/html/zabbix/conf/zabbix.conf.php
[root@www ~]# vim /usr/local/nginx/html/zabbix/conf/zabbix.conf.php
<?php
// Zabbix GUI configuration file.
global $DB;
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = '192.168.150.160'; #这里必须填写zabbix_server真实地址,默认的#127.0.0.1在启动zabbix_server时web会报is not running错误
$DB['PORT'] = '3306';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = 'Zabbix0000#';
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';
$ZBX_SERVER = '192.168.150.160'; #这里必须填写zabbix_server真实地址,默认的#127.0.0.1在启动zabbix_server时web会报is not running错误
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = '';
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
?>

#9、修改zabbix_server.conf
[root@www ~]# vi /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBSocket=/tmp/mysql.sock
DBName=zabbix #指定zabbix数据库
DBUser=zabbix #指定zabbix数据库用户
DBPassword=Zabbix0000# #指定zabbix数据库密码
DBPort=3306 #指定zabbix数据库端口
ListenIP=192.168.150.160 #服务器IP地址
Timeout=30

#10、[root@www ~]# chown -R zabbix:zabbix /usr/local/zabbix

#11、把zabbix_server加入开机启动服务
[root@www ~]# cp /usr/local/src/zabbix-3.2.6/misc/init.d/tru64/zabbix_server
[root@www ~]# chmod a+x /etc/init.d/zabbix_agentd
[root@www ~]# chown zabbix:zabbix /etc/init.d/zabbix_server
[root@www ~]# vi /etc/init.d/zabbix_agentd
#按照实际情况修改以下三行
SERVICE="Zabbix server"
DAEMON=/usr/local/zabbix/sbin/zabbix_server
PIDFILE=/tmp/zabbix_server.pid

#12、若启动zabbix_server 提示如下错误
./zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
[root@www ~]#vim /etc/ld.so.conf
#在最后一行添加 /usr/local/mysql/lib
[root@www ~]#ldconfig

参考文章:

转载请注明原作者: 周淑科(https://izsk.me)


 wechat
Scan Me To Read on Phone
I know you won't do this,but what if you did?