Write by lyc at 2020-2-12
zabbix 官网下载
zabbix 官方文档

zabbix-4.0.16 编译安装

1.安装依赖

1
$ yum install -y gcc fping net-snmp-devel libxml2-devel libevent-devel  curl-devel mysql-devel

2.编译安装

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
# 创建zabbix用户
$ useradd zabbix -M -s /sbin/nologin

# 下载
$ cd /usr/local/src
$ wget -c https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.16/zabbix-4.0.16.tar.gz
$ tar xvf zabbix-4.0.16.tar.gz

# 编译安装
$ cd /usr/local/src/zabbix-4.0.16
./configure \
--prefix=/usr/local/zabbix-4.0.16 \
--enable-server \
--enable-agent \
--enable-proxy \
--with-mysql \
--enable-ipv6 \
--with-net-snmp \
--with-libcurl \
--with-libxml2

$ make && make install

# 创建软连接
$ ln -s /usr/local/zabbix-4.0.16 /usr/local/zabbix

3.zabbix_server.conf 配置文件

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
# 备份默认配置文件
$ cd /usr/local/zabbix/etc
$ cp -pv zabbix_server.conf{,.default}
$ cp -pv zabbix_agentd.conf{,.default}
$ cp -pv zabbix_proxy.conf{,.default}

# 创建日志目录
$ mkdir -p /var/log/zabbix
$ chown -R zabbix.zabbix /var/log/zabbix/

# zabbix_server.conf 配置文件
$ egrep -v "#|^$" zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=60
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/data/mysql_data_3306/mysql_3306.sock
DBPort=3306
StartPollers=100
StartPollersUnreachable=60
StartTrappers=100
StartPingers=100
StartDiscoverers=120
StartHTTPPollers=5
StartTimers=100
MaxHousekeeperDelete=5000
CacheSize=1024M
CacheUpdateFrequency=120
StartDBSyncers=20
HistoryCacheSize=1024M
HistoryIndexCacheSize=32M
TrendCacheSize=1024M
ValueCacheSize=128M
Timeout=10
UnreachablePeriod=45
UnavailableDelay=60
UnreachableDelay=45
AlertScriptsPath=/usr/local/zabbix/bin/alertscripts
FpingLocation=/usr/sbin/fping
Fping6Location=/usr/sbin/fping6
LogSlowQueries=3000

4.mysql 初始化zabbix数据库

1
2
3
4
5
6
7
8
9
10
# 登入mysql创建数据库、zabbix用户
CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY 'zabbix';
FLUSH PRIVILEGES;

# 导入zabbix表结构
$ cd /usr/local/src/zabbix-4.0.16/database/mysql
$ mysql -uzabbix -pzabbix -S /data/mysql_data_3306/mysql_3306.sock zabbix < schema.sql
$ mysql -uzabbix -pzabbix -S /data/mysql_data_3306/mysql_3306.sock zabbix < images.sql
$ mysql -uzabbix -pzabbix -S /data/mysql_data_3306/mysql_3306.sock zabbix < data.sql

5.拷贝php前端站点代码

1
2
3
$ mkdir -p /data/wwwroot/devops.xxx.com/zabbix
$ cp -ar /usr/local/src/zabbix-4.0.16/frontends/php/* /data/wwwroot/devops.xxx.com/zabbix
$ chown -R nginx.nginx /data/wwwroot/devops.xxx.com/zabbix

6.配置nginx vhost

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
$ vim devops.xxx.com.conf
server
{
listen 80;
server_name devops.xxx.com;
index index.html index.htm index.php;
root /data/wwwroot/devops.xxx.com;

location = /favicon.ico {
log_not_found off;
}

location ~* \.(gif|jpg|jpeg|css|js|bmp|png)$ {
expires max;
}

location /zabbix {
alias /data/wwwroot/devops.xxx.com/zabbix;
index index.php index.html;
auth_basic "Restricted Access";
auth_basic_user_file /usr/local/nginx/conf/htpasswd.users;
}
location ~ /zabbix/(.*)\.php$ {
rewrite ^/zabbix/(.*)\.php$ /$1.php break;
root /data/wwwroot/devops.xxx.com/zabbix;
include fastcgi_params;
#fastcgi_pass 127.0.0.1:10080;
fastcgi_pass unix:/usr/local/php/etc/php-cgi.socket;
fastcgi_index index.php;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
error_log /data/httplogs/devops.xxx.com-error.log ;
access_log /data/httplogs/devops.xxx.com-access.log weblog ;
}

7.启动服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 拷贝服务启动文件
$ cd /usr/local/src/monitor/zabbix/zabbix-4.0.16
$ cp -vp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
$ cp -vp misc/init.d/fedora/core/zabbix_server /etc/init.d/

# 修改启动文件的BASEDIR,只要修改BASEDIR就可以用了。
$ vim /etc/init.d/zabbix_server
BASEDIR=/usr/local/zabbix
$ vim /etc/init.d/zabbix_agentd
BASEDIR=/usr/local/zabbix

# 添加服务到chkconfig
chkconfig --level 35 zabbix_server on
chkconfig --level 35 zabbix_agentd on

启动zabbix-server

1
$ /etc/init.d/zabbix-server start