zabbix编译安装部署文档

摘要

本文安装过程部分取自 运维生存时间 以及站长凉白开的《ZABBIX从入门到精通v3.0.1 - 运维生存时间(2016)》一书。

  • 2016年8月17日
    • 更新3.0.4 下载地址
  • 2017年8月8日
    • 更新文档内容
  • 2017年8月30日
    • 更新systemd配置,调整内容
  • 2017年9月21日
    • 更新proxy配置
    • 更新zabbix版本至3.2.7
    • 更新mysql版本为5.6.37
  • 2018年5月10日
    • 更新zabbix版本为3.4.8
    • 调整了一些环境安装的依赖
    • agent安装脚本配置文件中新增了自动注册需要的配置参数

本文仅记录编译安装部署过程

如果你是小白,请严格按照本文过程执行,不要遗漏任何步骤;

如果你有一定的基础,请按照你的习惯修改一些参数

zabbix安装环境准备

版本说明

  • zabbix:3.2.7
  • nginx:1.13.3
  • php:5.5.35
  • mysql:5.6.37

安装依赖包

1
2
3
4
yum install -y epel*
yum install -y wget curl curl-devel gcc gcc-c++ autoconf automake fping make cmake zlib zlib-devel openssl openssl-devel pcre* gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel net-snmp net-snmp-devel mysql-devel ncurses-devel libevent-devel perl-DBI unixODBC-devel OpenIPMI-devel openldap openldap-devel

cp -a /usr/lib64/libldap* /usr/lib/

设置环境变量

1
2
3
4
5
6
7
8
WORKDIR="/usr/local/src"
INSTALL_DIR="/usr/local/product"
NGINX_VERSION="1.13.3"
PHP_VERSION="5.5.35"
MVERSION="5.6"
MYSQL_VERSION="5.6.37"
#ZABBIX_VERSION="3.2.7"
ZABBIX_VERSION="3.4.8"

安装nginx

添加nginx用户

1
2
groupadd -r www
useradd -s /sbin/nologin -g www -r www

编译安装nginx

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
cd ${WORKDIR}
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
tar xvf nginx-${NGINX_VERSION}.tar.gz && cd nginx-${NGINX_VERSION}

./configure \
--prefix=${INSTALL_DIR}/nginx-${NGINX_VERSION} \
--user=www \
--group=www \
--with-pcre \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-stream \
--with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'

make && make install
ln -s ${INSTALL_DIR}/nginx-${NGINX_VERSION} /usr/local/nginx

参数说明

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

修改nginx配置文件

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
mkdir /data/logs/nginx
mkdir -p /usr/local/nginx/conf/vhosts

cat >/usr/local/nginx/conf/nginx.conf <<E0F
user www;
worker_processes 4;

error_log /data/logs/nginx/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

pid /var/run/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"';
sendfile on;
keepalive_timeout 65;
include vhosts/*.conf;
}
E0F

创建nginx启动文件

init

1
2
curl https://c.isme.pub/2017/08/30/service-install/nginx.init -o /etc/init.d/nginx
chmod +x /etc/init.d/nginx

systemd

1
curl https://c.isme.pub/2017/08/30/service-install/nginx.service -o /usr/lib/systemd/system/nginx.service

安装php

编译安装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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
cd ${WORKDIR}
wget http://cn2.php.net/get/php-${PHP_VERSION}.tar.gz/from/this/mirror -O php-${PHP_VERSION}.tar.gz

tar xvf php-${PHP_VERSION}.tar.gz && cd php-${PHP_VERSION}

./configure \
--prefix=${INSTALL_DIR}/php-${PHP_VERSION} \
--with-config-file-path=${INSTALL_DIR}/php-${PHP_VERSION}/etc \
--with-curl \
--with-libxml-dir \
--with-mysql=mysqlnd \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-zlib \
--with-gd \
--enable-gd-jis-conv \
--with-jpeg-dir \
--with-png-dir \
--with-gettext \
--with-freetype-dir \
--enable-gd-native-ttf \
--with-mhash \
--with-iconv \
--with-xmlrpc \
--with-pcre-regex \
--without-pear \
--without-pdo-sqlite \
--without-sqlite3 \
--disable-cgi \
--disable-ipv6 \
--disable-phar \
--disable-rpath \
--enable-fpm \
--enable-ftp \
--enable-zip \
--enable-soap \
--with-gettext \
--enable-bcmath \
--enable-sockets \
--enable-calendar \
--enable-shmop \
--enable-opcache \
--enable-sysvsem \
--enable-sysvshm \
--enable-sysvmsg \
--enable-mbstring \
--with-ldap

sed -i '/EXTRA_LIBS/s/$/ -llber/' Makefile
make && make install

ln -s ${INSTALL_DIR}/php-${PHP_VERSION} /usr/local/php
cp php.ini-production /usr/local/php/etc/php.ini
cd /usr/local/php/etc/
curl https://c.isme.pub/2017/08/30/service-install/php-fpm.conf -o php-fpm.conf
mkdir -p /data/logs/php/

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

1
2
3
4
5
6
7
sed -i '/^max_execution_time/s/=.*/= 300/' php.ini
sed -i '/^memory_limit/s/=.*/= 128M/' php.ini
sed -i '/^post_max_size/s/=.*/= 16M/' php.ini
sed -i '/^upload_max_filesize/s/=.*/= 2M/' php.ini
sed -i '/^max_input_time/s/=.*/= 300/' php.ini
sed -i '/^;date.timezone/s/^;//' php.ini
sed -i '/^date.timezone/s/=.*/= PRC/' php.ini

创建php-fpm启动文件

init

1
2
curl https://c.isme.pub/2017/08/30/service-install/php-fpm.init -o /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

systemd

1
curl https://c.isme.pub/2017/08/30/service-install/php-fpm.service -o /usr/lib/systemd/system/php-fpm.service

安装mysql

添加mysql用户

1
2
3
4
groupadd mysql
mkdir -p /data/mysql
useradd -r -g mysql -d /data/mysql -s /sbin/nologin mysql
chown -R mysql.mysql /data/mysql

获取安装包

1
2
3
4
cd ${WORKDIR}
wget http://dev.mysql.com/get/Downloads/MySQL-${MVERSION}/mysql-${MYSQL_VERSION}.tar.gz

tar -xvf mysql-${MYSQL_VERSION}.tar.gz && cd mysql-${MYSQL_VERSION}

编译安装

1
2
3
4
5
6
7
8
9
10
11
12
13
cmake \
-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}/mysql-${MYSQL_VERSION} \
-DDEFAULT_CHARSET=utf8 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/data/mysql \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_READLINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DDEFAULT_COLLATION=utf8_general_ci

make && make install
ln -s ${INSTALL_DIR}/mysql-${MYSQL_VERSION} /usr/local/mysql

初始化数据库

1
2
3
4
5
6
7
8
mkdir /data/logs/mysql
cd /usr/local/mysql/support-files/
cp mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
cd /usr/local/mysql/scripts/
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

curl https://c.isme.pub/2017/08/30/service-install/my.cnf -o /etc/my.cnf

启动并添加环境变量

1
2
3
4
5
6
7
8
chkconfig mysqld on
/etc/init.d/mysqld start

echo 'export PATH="$PATH:/usr/local/bin:/usr/local/mysql/bin"' >> /root/.bashrc

echo 'export PATH="$PATH:/usr/local/bin:/usr/local/mysql/bin"' >> /etc/profile

source /etc/profile

安装zabbix

添加zabbix用户

1
2
groupadd zabbix
useradd -g zabbix -s /sbin/nologin zabbix

获取安装包

官方下载地址

1
2
3
cd ${WORKDIR}
wget "https://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/${ZABBIX_VERSION}/zabbix-${ZABBIX_VERSION}.tar.gz?r=&ts=1502894025&use_mirror=jaist" -O zabbix-${ZABBIX_VERSION}.tar.gz
tar xvf zabbix-${ZABBIX_VERSION}.tar.gz && cd zabbix-${ZABBIX_VERSION}

编译安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
./configure \
--prefix=${INSTALL_DIR}/zabbix-${ZABBIX_VERSION}/ \
--enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2 \
--with-openipmi \
--with-unixodbc

./configure \
--prefix=${INSTALL_DIR}/zabbix-${ZABBIX_VERSION}/ \
--enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2 \
--with-openipmi \
--with-unixodbc

make && make install
ln -s ${INSTALL_DIR}/zabbix-${ZABBIX_VERSION} /usr/local/zabbix

创建zabbix数据库以及数据库用户

1
2
3
4
5
mysql
create database zabbix default charset utf8;
grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix@xxx.com';
flush privileges;
quit;

导入数据

1
2
3
mysql -uzabbix -pzabbix@xxx.com zabbix < database/mysql/schema.sql 
mysql -uzabbix -pzabbix@xxx.com zabbix < database/mysql/images.sql
mysql -uzabbix -pzabbix@xxx.com zabbix < database/mysql/data.sql

zabbix proxy只需要导入第一个sql数据,server需要导入全部三个数据

导入web文件

1
2
3
4
mkdir -p /data/web/zabbix.xxx.com
mkdir -p /data/logs/zabbix
cp -a frontends/php/* /data/web/zabbix.xxx.com/
chown www.www -R /data/web/zabbix.xxx.com

修改配置文件

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
cat >/usr/local/zabbix/etc/zabbix_server.conf <<EOF
ListenPort=10051
LogFile=/data/logs/zabbix/zabbix_server.log
LogFileSize=10
DebugLevel=3
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBSchema=zabbix
DBUser=zabbix
DBPassword=zabbix@xxx.com
DBSocket=/tmp/mysql.sock
DBPort=3306
StartPollers=10
StartPollersUnreachable=5
StartPingers=5
StartDiscoverers=5
StartIPMIPollers=5
StartTrappers=10
StartHTTPPollers=2
ListenIP=0.0.0.0
CacheSize=2048M
CacheUpdateFrequency=100
StartDBSyncers=10
HistoryCacheSize=2048M
TrendCacheSize=2048M
ValueCacheSize=1G
Timeout=30
LogSlowQueries=1000
AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts
ExternalScripts=/usr/local/zabbix/share/zabbix/externalscripts
FpingLocation=/usr/sbin/fping
TmpDir=/tmp
AllowRoot=1
StartProxyPollers=10
ProxyConfigFrequency=50
ProxyDataFrequency=30
Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf
#SSLCertLocation=/usr/local/zabbix/share/zabbix/ssl/certs
#SSLKeyLocation=/usr/local/zabbix/share/zabbix/ssl/keys
LoadModulePath=/usr/local/zabbix/share/zabbix/modules
EOF

cat >/usr/local/zabbix/etc/zabbix_agentd.conf <<EOF
PidFile=/tmp/zabbix_agentd.pid
LogFile=/data/logs/zabbix/zabbix_agentd.log
LogFileSize=10
DebugLevel=3
EnableRemoteCommands=1
LogRemoteCommands=1
RefreshActiveChecks=60
MaxLinesPerSecond=200
Server=127.0.0.1
ListenPort=10050
StartAgents=5
ServerActive=127.0.0.1
Timeout=30
AllowRoot=1
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
LoadModulePath=/usr/local/zabbix/share/zabbix/modules
EOF

mkdir /data/logs/zabbix/ -p && chown zabbix.zabbix /data/logs/zabbix/

创建zabbix虚拟主机

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
cat >/usr/local/nginx/conf/vhosts/zabbix.conf <<EOF
server {
listen 80;
server_name zabbix.xxx.com;

access_log /data/logs/nginx/zabbix_access.log;
error_log /data/logs/nginx/zabbix_error.log;

index index.html index.php index.html;
root /data/web/zabbix.xxx.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;
}
}
EOF

创建zabbix启动文件

init

1
2
curl https://c.isme.pub/2016/05/19/zabbix-install/zabbix_server.init -o /etc/init.d/zabbix_server
chmod +x /etc/init.d/zabbix_server

systemd

1
curl https://c.isme.pub/2016/05/19/zabbix-install/zabbix-server.service -o /usr/lib/systemd/system/zabbix-server.service

创建agent启动文件

init

1
2
curl https://c.isme.pub/2016/05/19/zabbix-install/zabbix_agentd.init -o /etc/init.d/zabbix_agentd
chmod +x /etc/init.d/zabbix_agentd

systemd

1
curl https://c.isme.pub/2016/05/19/zabbix-install/zabbix-agentd.service -o /usr/lib/systemd/system/zabbix-agentd.service

启动服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# init
chkconfig nginx on
chkconfig php-fpm on
chkconfig zabbix_server on
chkconfig zabbix_agentd on

/etc/init.d/nginx start
/etc/init.d/php-fpm start
/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start

# systemd
systemctl enable nginx.service
systemctl enable php-fpm.service
systemctl enable zabbix-server.service
systemctl enable zabbix-agentd.service

systemctl start nginx.service
systemctl start php-fpm.service
systemctl start zabbix-server.service
systemctl start zabbix-agentd.service

web安装zabbix

浏览器访问http://your-ip or http://your-domin

img

直接下一步

img

环境监测,确保所有监测都是OK的

img

连接数据库信息

img

server端口,默认

img

信息确认

img

此处需要给conf目录nginx用户www权限。

img

安装完成

登陆测试

img

默认账号admin、密码zabbix

img

zabbix支持中文,但是默认是不能修改成中文的
需要以下操作

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

img

修改后重启服务,可以选择中文

修改中文后,为了防止图形出现乱码,修改以下配置
需要自己上传中文字体到fonts 文件夹下

1
2
3
4
5
6
vim /data/web/zabbix.xxx.com/include/defines.inc.php 
#define('ZBX_GRAPH_FONT_NAME','DejaVuSans'); // font file name
define('ZBX_GRAPH_FONT_NAME','xxx'); // font file name

#define('ZBX_FONT_NAME', 'DejaVuSans');
define('ZBX_FONT_NAME', 'xxx');

安装zabbix-agent

1
2
3
4
5
curl https://c.isme.pub/2016/05/19/zabbix-install/zabbix_agent_install_centos.sh -o zabbix_agent_install_centos.sh
chmod +x zabbix_agent_install_centos.sh

# 修改
vim zabbix_agent_install_centos.sh

安装zabbix-proxy

zabbix-proxy 可以替代zabbix-server 收集客户端数据,并将数据汇总给zabbix-server,在一定的程度上分担了zabbix-server的压力,可以说zabbix-proxy实现了集中式、分布式监控。

使用场景

  • 监控远程区域设备;
  • 监控本地网络不稳定区域;
  • 当zabbix监控上千设备时,使用它来减轻server的压力;
  • 简化zabbix的维护。

功能及原理

  • zabbix-proxy 必须要和 zabbix-server 同一个版本
  • zabbix-proxy 仅仅需要一条tcp连接 zabbix-server;
  • zabbix-proxy 数据库必须和 zabbix-server 分开;
  • zabbix-proxy 收集到数据之后,首先将数据缓存在本地,然后在一定得时间之后传递给 zabbix-server。这个时间由proxy配置文件中参数ProxyLocalBuffer and ProxyOfflineBuffer决定;
  • zabbix-proxy是一个数据收集器,它不计算触发器、不处理事件、不发送报警;
  • 使用 agent-active 模式,一定要记住在 agent 的配置文件参数 ServerActive 加上 proxy 的IP地址

以下是 zabbix-proxy 的功能

Items Function Supported by proxy
Zabbix agent checks Yes
Zabbix agent checks (active) Yes
Simple checks Yes
Trapper items Yes
SNMP checks Yes
SNMP traps Yes
IPMI checks Yes
JMX checks Yes
Log file monitoring Yes
Internal checks Yes
SSH checks Yes
Telnet checks Yes
External checks Yes
Built-in web monitoring Yes
Network discovery Yes
Low-level discovery Yes
Calculating triggers No
Processing events No
Sending alerts No
Remote commands No

安装依赖

1
2
3
4
yum install -y epel*
yum install -y wget curl curl-devel gcc gcc-c++ autoconf automake fping make cmake zlib zlib-devel openssl openssl-devel pcre* gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel net-snmp net-snmp-devel mysql-devel ncurses-devel libevent-devel perl-DBI unixODBC-devel OpenIPMI-devel openldap openldap-devel

cp -a /usr/lib64/libldap* /usr/lib/

设置环境变量

1
2
3
4
5
WORKDIR="/usr/local/src"
INSTALL_DIR="/usr/local/product"
MVERSION="5.6"
MYSQL_VERSION="5.6.37"
ZABBIX_VERSION="3.4.8"

编译安装mysql

跳转到mysql安装

添加zabbix用户

1
2
groupadd zabbix
useradd -g zabbix -s /sbin/nologin zabbix

获取安装包

官方下载地址

1
2
3
cd ${WORKDIR}
wget "https://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/${ZABBIX_VERSION}/zabbix-${ZABBIX_VERSION}.tar.gz?r=&ts=1502894025&use_mirror=jaist" -O zabbix-${ZABBIX_VERSION}.tar.gz
tar xvf zabbix-${ZABBIX_VERSION}.tar.gz && cd zabbix-${ZABBIX_VERSION}

编译安装

1
2
3
4
5
6
7
8
9
10
11
./configure \
--prefix=${INSTALL_DIR}/zabbix-${ZABBIX_VERSION}/ \
--enable-proxy \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2

make && make install
ln -s ${INSTALL_DIR}/zabbix-${ZABBIX_VERSION} /usr/local/zabbix

创建zabbix数据库以及数据库用户

1
2
3
4
5
mysql
create database zabbix_proxy default charset utf8;
grant all privileges on zabbix_proxy.* to zabbix@'localhost' identified by 'zabbix@xxx.com';
flush privileges;
quit;

导入数据

1
mysql -uzabbix -pzabbix@xxx.com zabbix_proxy < database/mysql/schema.sql

zabbix-proxy表结构的sql,三个sql全部导入可能会报错。

修改配置文件

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
MASTER="10.0.0.187"
PROXY="10.0.0.188"
HOSTNAME="env-proxy"

cat >/usr/local/zabbix/etc/zabbix_proxy.conf <<EOF
ProxyMode=0
Server=${MASTER}
ServerPort=10051
Hostname=${HOSTNAME}
ListenPort=10051
LogFile=/data/logs/zabbix/zabbix_proxy.log
LogFileSize=10
DebugLevel=3
PidFile=/tmp/zabbix_proxy.pid
DBHost=localhost
DBName=zabbix_proxy
DBUser=zabbix
DBPassword=zabbix@xxx.com
DBSocket=/tmp/mysql.sock
DBPort=3306
ProxyOfflineBuffer=1
HeartbeatFrequency=20
ConfigFrequency=40
DataSenderFrequency=1
StartPollers=10
StartPollersUnreachable=5
StartTrappers=10
StartPingers=5
StartDiscoverers=5
ListenIP=${PROXY}
CacheSize=1G
StartDBSyncers=5
Timeout=30
FpingLocation=/usr/sbin/fping
TmpDir=/tmp
AllowRoot=1
ExternalScripts=/usr/local/zabbix/share/zabbix/externalscripts
LoadModulePath=/usr/local/zabbix/share/zabbix/modules
Include=/usr/local/zabbix/etc/zabbix_proxy.conf.d/*.conf
EOF

cat >/usr/local/zabbix/etc/zabbix_agentd.conf <<EOF
PidFile=/tmp/zabbix_agentd.pid
LogFile=/data/logs/zabbix/zabbix_agentd.log
LogFileSize=10
DebugLevel=3
EnableRemoteCommands=1
LogRemoteCommands=1
RefreshActiveChecks=60
MaxLinesPerSecond=200
Server=${PROXY}
ListenPort=10050
StartAgents=5
ServerActive=${PROXY}
#Hostname=${HOSTNAME}
HostMetadataItem=system.uname
Timeout=30
AllowRoot=1
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
LoadModulePath=/usr/local/zabbix/share/zabbix/modules
EOF

mkdir /data/logs/zabbix/ -p && chown zabbix.zabbix /data/logs/zabbix/
echo "${PROXY} ${HOSTNAME}" >> /etc/hosts

创建 zabbix-proxy 启动文件

init

1
2
curl https://c.isme.pub/2016/05/19/zabbix-install/zabbix_proxy.init -o /etc/init.d/zabbix_proxy
chmod +x /etc/init.d/zabbix_proxy

systemd

1
curl https://c.isme.pub/2016/05/19/zabbix-install/zabbix-proxy.service -o /usr/lib/systemd/system/zabbix-proxy.service

创建 zabbix-agent 启动文件

init

1
2
curl https://c.isme.pub/2016/05/19/zabbix-install/zabbix_agentd.init -o /etc/init.d/zabbix_agentd
chmod +x /etc/init.d/zabbix_agentd

systemd

1
curl https://c.isme.pub/2016/05/19/zabbix-install/zabbix-agentd.service -o /usr/lib/systemd/system/zabbix-agentd.service

启动服务

1
2
3
4
5
6
7
8
9
10
11
# init
chkconfig zabbix_proxy on
chkconfig zabbix_agentd on
/etc/init.d/zabbix_proxy start
/etc/init.d/zabbix_agentd start

# systemd
systemctl enable zabbix-proxy.service
systemctl enable zabbix-agentd.service
systemctl start zabbix-proxy.service
systemctl start zabbix-agentd.service

master添加proxy

参数 描述
Proxy name proxy名称,必须和proxy配置文件中的hostname一致
Proxy mode 选择proxy模式
Active proxy主动连接到zabbix server并且请求配置文件数据
Passive Zabbix server连接到proxy
Hosts 哪些主机需要被proxy监控

添加proxy

添加agent

选择一个默认的监控模板

最后看到的效果,这样应该就没什么问题了

附录

nginx

init

点击下载

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
cat /etc/init.d/nginx
#!/bin/bash
######################################################
## Modify by nanu@qq.com at 2012-07-20 13:52 ##
## Compatible with RedHat/CentOS Debian/Ubuntu SUSE ##
######################################################

# Support chkconfig on RedHat/CentOS
# chkconfig: 2345 90 60
# description: nginx
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /var/run/nginx.pid

# Support Linux Standard Base Core Specification 3.2
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $syslog $network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 S 1 6
# Short-Description: start/stop nginx daemon
# Description: nginx is a web server, http and mail proxy server
### END INIT INFO

#debug
#set -x
#check unbound variables
#set -u
# Scripts PATH enviroment
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
# disable core dump
ulimit -c 0
# return value
RETVAL=0
# nginx general config
PROG="nginx"
SYMLINK=$(readlink -f /usr/local/nginx)
BASEDIR=${SYMLINK:-/usr/local/nginx}
DAEMON="${BASEDIR}/sbin/nginx"
CONF="${BASEDIR}/conf/nginx.conf"
PIDFILE="/var/run/${PROG}.pid"
LOCKFILE="/var/lock/$PROG"
# nginx start timeout milliscond
STARTTIME=10000
# nginx stop timeout milliscond
STOPTIME=10000

#Common Function
color_msg(){
local COLOR=$1
local MSG=$2
OFFSET="\033[60G"
NORMAL="\033[0m"
case $COLOR in
red)
COLOR="\033[1;40;31m"
;;
green)
COLOR="\033[1;40;32m"
;;
yellow)
COLOR="\033[1;40;33m"
;;
*)
COLOR="\033[0m"
;;
esac
echo -en "$OFFSET [$COLOR $MSG $NORMAL"
echo "]"
}

configtest() {
echo -n "Configtest $PROG : "
$DAEMON -tq -c $CONF
if [ $? -eq 0 ] ;then
color_msg green SUCCESS
else
color_msg red FAILED && exit 1
fi
}

start() {
echo -n "Starting $PROG : "
PROC_PID=$(pgrep -P 1 -u root ^$PROG)
if [ -n "$PROC_PID" ]; then
echo -n "is already running."
color_msg yellow WARNING
else
$DAEMON -c $CONF >/dev/null 2>&1
if [ $? -eq 0 ]; then
color_msg green SUCCESS && touch $LOCKFILE
else
color_msg red FAILED && exit 1
fi
fi
}

stop() {
echo -n "Stopping $PROG : "
PROC_PID=$(pgrep -P 1 -u root ^$PROG)
if [ -z "$PROC_PID" ]; then
echo -n "is not running."
color_msg yellow WARNING
else
kill -TERM ${PROC_PID} >/dev/null 2>&1
while [ "$STOPTIME" -gt 0 ]; do
kill -0 ${PROC_PID} >/dev/null 2>&1 || break
STOPTIME=$(($STOPTIME-1))
echo -n "." && sleep 0.001s
done
if [ "$STOPTIME" -le 0 ]; then
color_msg red TIMEOUT && exit 1
else
color_msg green SUCCESS
rm -f $PIDFILE $LOCKFILE
fi
fi
}

restart() {
echo -n "Restart $PROG : "
echo
echo -en "\t" && stop
echo -en "\t" && start
}

reload() {
echo -n "Reloading $PROG : "
PROC_PID=$(pgrep -P 1 -u root ^$PROG)
if [ -n "$PROC_PID" ]; then
kill -HUP ${PROC_PID} >/dev/null 2>&1
if [ $? -eq 0 ]; then
color_msg green SUCCESS
else
color_msg red FAILED && exit 1
fi
else
echo -n "is not running."
color_msg yellow WARNING
fi
}

status() {
PROC_PID=$(pgrep -P 1 -u root ^$PROG)
if [ -z "$PROC_PID" ];then
echo "$PROG is stopped"
exit 3
else
echo "$PROG (pid $PROC_PID) is running..."
exit 0
fi
}

quit() {
echo -n "Quit $PROG : "
PROC_PID=$(pgrep -P 1 -u root ^$PROG)
if [ -z "$PROC_PID" ]; then
echo -n "is not running."
color_msg yellow WARNING
else
kill -QUIT ${PROC_PID} >/dev/null 2>&1
while [ "$STOPTIME" -gt 0 ]; do
kill -0 ${PROC_PID} >/dev/null 2>&1 || break
STOPTIME=$(($STOPTIME-1))
echo -n "." && sleep 0.001s
done
if [ "$STOPTIME" -le 0 ]; then
color_msg red TIMEOUT && exit 1
else
color_msg green SUCCESS
rm -f $PIDFILE $LOCKFILE
fi
fi
}

logrotate() {
echo -n "Re-opening $PROG log file : "
PROC_PID=$(pgrep -P 1 -u root ^$PROG)
if [ -z "$PROC_PID" ]; then
echo -n "is not running."
color_msg yellow WARNING
else
kill -USR1 ${PROC_PID} >/dev/null 2>&1
if [ $? -eq 0 ]; then
color_msg green SUCCESS
else
color_msg red FAILED && exit 1
fi
fi
}

case "$1" in
configtest)
configtest
;;
start)
configtest
start
;;
stop)
stop
;;
restart|try-restart)
configtest
restart
;;
reload|force-reload)
configtest
reload
;;
status)
status
;;
quit)
quit
;;
logrotate)
logrotate
;;
*)
echo $"Usage: $0 {configtest|start|stop|restart|reload|status|quit|logrotate}"
exit 1
;;
esac

systemd

点击下载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=Nginx Server
Documentation=http://nginx.org/en/docs/
After=syslog.target network.target
Wants=network.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -t
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecStop=/bin/kill -s TERM $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=control-group
Restart=no
TimeoutSec=10

[Install]
WantedBy=multi-user.target

php

php-fpm

点击下载

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
cat php-fpm.conf
;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;
; Global Options ;
;;;;;;;;;;;;;;;;;;

[global]
pid = /var/run/php-fpm.pid
error_log = /data/logs/php/fpm_error.log
;error_log = syslog
;syslog.facility = daemon
;syslog.ident = php-fpm
log_level = warning
emergency_restart_threshold = 30
emergency_restart_interval = 30s
process_control_timeout = 3s
process.max = 100
daemonize = yes
rlimit_files = 100000
rlimit_core = 0
events.mechanism = epoll

;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;
[www]
user = www
group = www
;listen = /tmp/www.sock
listen = 127.0.0.1:9000
listen.backlog = 8192
listen.owner = www
listen.group = www
listen.mode = 0600
;listen.allowed_clients = 127.0.0.1,192.168.1.0/24
pm = static
pm.max_children = 100
pm.max_requests = 5000
pm.status_path = /status.php
ping.path = /ping.php
ping.response = pong
;access.log = /data/logs/php/$pool.access.log
;access.format = %f-[%m %l %r%Q%q %s %d]-[%C %M]
slowlog = /data/logs/php/$pool.slow.log
request_slowlog_timeout = 1s
request_terminate_timeout = 60
rlimit_files = 100000
rlimit_core = 0
catch_workers_output = yes
security.limit_extensions = .php

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@$HOSTNAME
php_flag[display_errors] = off
php_admin_value[error_log] = /data/logs/php/$pool_fpm_error.log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 2048M

init

点击下载

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
cat /etc/init.d/php-fpm
#!/bin/bash
######################################################
## Modify by adam.li@ismole.com at 2012-07-20 14:48 ##
## Compatible with RedHat/CentOS Debian/Ubuntu SUSE ##
######################################################

# Support chkconfig on RedHat/CentOS Linux
# chkconfig: 2345 70 70
# description: PHP FastCGI Server
# processname: php-fpm
# config: /usr/local/php/etc/php-fpm.conf
# pidfile: /var/run/php-fpm.pid

# Support Linux Standard Base Core Specification 3.2
### BEGIN INIT INFO
# Provides: php-fpm
# Required-Start: $local_fs $syslog $network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 S 1 6
# Short-Description: start/stop php-fpm daemon
# Description: php-fpm is fastcgi deamon
### END INIT INFO

#debug
#set -x
#check unbound variables
#set -u
# scripts PATH enviroment
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
# disable core dump
ulimit -c 0
# script return value
RETVAL=0
# php-fpm general config
PROG='php-fpm'
SYMLINK=$(readlink -f /usr/local/php)
BASEDIR=${SYMLINK:-/usr/local/php}
DAEMON="${BASEDIR}/sbin/$PROG"
CONF="${BASEDIR}/etc/php-fpm.conf"
PIDFILE="/var/run/${PROG}.pid"
LOCKFILE="/var/lock/$PROG"
# php-fpm start timeout milliscond
STARTTIME=10000
# php-fpm stop timeout milliscond
STOPTIME=10000

#Common Function
color_msg(){
local COLOR=$1
local MSG=$2
OFFSET="\033[60G"
NORMAL="\033[0m"
case $COLOR in
red)
COLOR="\033[1;40;31m"
;;
green)
COLOR="\033[1;40;32m"
;;
yellow)
COLOR="\033[1;40;33m"
;;
*)
COLOR="\033[0m"
;;
esac
echo -en "$OFFSET [$COLOR $MSG $NORMAL"
echo "]"
}

configtest() {
echo -n "Configtest $PROG : "
$DAEMON --fpm-config $CONF -t
if [ $? -eq 0 ]; then
color_msg green SUCCESS
else
color_msg red FAILED && exit 1
fi
}

start() {
echo -n "Starting $PROG : "
PROC_PID=$(pgrep -P 1 -u root ^$PROG)
if [ -n "$PROC_PID" ]; then
echo -n "is already running."
color_msg yellow WARNING
else
$DAEMON --fpm-config $CONF >/dev/null 2>&1
if [ $? -eq 0 ]; then
color_msg green SUCCESS && touch $LOCKFILE
else
color_msg red FAILED && exit 1
fi
fi
}

stop() {
echo -n "Stopping $PROG : "
PROC_PID=$(pgrep -P 1 -u root ^$PROG)
if [ -z "$PROC_PID" ]; then
echo -n "is not running."
color_msg yellow WARNING
else
kill -TERM ${PROC_PID} >/dev/null 2>&1
while [ "$STOPTIME" -gt 0 ]; do
kill -0 ${PROC_PID} >/dev/null 2>&1 || break
STOPTIME=$(($STOPTIME-1))
echo -n "." && sleep 0.001s
done
if [ "$STOPTIME" -le 0 ]; then
color_msg red TIMEOUT && exit 1
else
color_msg green SUCCESS
rm -f $PIDFILE $LOCKFILE
fi
fi
}

restart() {
echo -n $"Restart $PROG : "
echo
echo -en "\t" && stop
echo -en "\t" && start
}

reload() {
echo -n "Reload service $PROG : "
PROC_PID=$(pgrep -P 1 -u root ^$PROG)
if [ -z "$PROC_PID" ]; then
echo -n "is not running."
color_msg yellow WARNING
else
kill -USR2 ${PROC_PID}
if [ $? -eq 0 ]; then
color_msg green SUCCESS
else
color_msg red FAILED && exit 1
fi
fi
}

status() {
PROC_PID=$(pgrep -P 1 -u root ^$PROG)
if [ -z "$PROC_PID" ];then
echo "$PROG is stopped"
exit 3
else
echo "$PROG (pid $PROC_PID) is running..."
exit 0
fi
}

quit() {
echo -n "Gracefully shuttding down $PROG : "
PROC_PID=$(pgrep -P 1 -u root ^$PROG)
if [ -z "$PROC_PID" ]; then
echo -n "is not running."
color_msg yellow WARNING
else
kill -QUIT ${PROC_PID}
while [ "$STOPTIME" -gt 0 ]; do
kill -0 ${PROC_PID} >/dev/null 2>&1 || break
STOPTIME=$(($STOPTIME-1))
echo -n "." && sleep 0.001s
done
if [ "$STOPTIME" -le 0 ]; then
color_msg red TIMEOUT && exit 1
else
color_msg green SUCCESS
rm -f $PIDFILE $LOCKFILE
fi
fi
}

logrotate() {
echo -n "Re-opening $PROG log file : "
PROC_PID=$(pgrep -P 1 -u root ^$PROG)
if [ -z "$PROC_PID" ]; then
echo -n "is not running."
color_msg yellow WARNING
else
kill -USR1 ${PROC_PID}
if [ $? -eq 0 ]; then
color_msg green SUCCESS
else
color_msg red FAILED && exit 1
fi
fi
}

case "$1" in
configtest)
configtest
;;
start)
configtest
start
;;
stop)
stop
;;
restart|try-restart)
configtest
restart
;;
reload|force-reload)
configtest
reload
;;
status)
status
;;
quit)
quit
;;
logrotate)
logrotate
;;
*)
echo "Usage: $0 {configtest|start|stop|quit|status|reload|restart|logrotate}"
exit 1
;;
esac

systemd

点击下载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
cat /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=PHP-FPM
Documentation=http://php.net/docs.php
After=syslog.target network.target
Wants=network.target

[Service]
Type=forking
PIDFile=/var/run/php-fpm.pid
ExecStartPre=/usr/local/php/sbin/php-fpm --fpm-config /usr/local/php/etc/php-fpm.conf -t
ExecStart=/usr/local/php/sbin/php-fpm --fpm-config /usr/local/php/etc/php-fpm.conf
ExecStop=/bin/kill -s TERM $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=control-group
Restart=no
TimeoutSec=10

[Install]
WantedBy=multi-user.target

mysql

my.cnf

点击下载

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
93
cat /etc/my.cnf 
[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
socket = /tmp/mysql.sock

#rpl_semi_sync_master_enabled=1
#rpl_semi_sync_master_timeout=1000
#rpl_semi_sync_slave_enabled=1

general-log = 0
general_log_file=/data/logs/mysql/mysql.log

slow-query-log = 1
slow-query-log-file = /data/logs/mysql/slow.log
log-slow-admin-statements
log-slow-slave-statements
long-query-time = 1
log-error = /data/logs/mysql/errors.log
log-warnings = 2

back_log = 512
max_connections =1024
max_connect_errors = 10000
connect_timeout = 60

skip-external-locking
skip-name-resolve
#skip-symbolic-links
#skip-innodb_checksums
#skip-innodb_doublewrite

key_buffer_size = 8M
max_allowed_packet = 32M
table_open_cache = 128
sort_buffer_size = 1M
read_buffer_size = 512K
read_rnd_buffer_size = 2M
myisam_sort_buffer_size = 1M
thread_cache_size = 2

query_cache_size = 4M
query_cache_type = 0

server-id = 1
log-bin = mysql-bin
binlog_format = mixed
sync_binlog = 1
expire-logs-days = 7
max_binlog_size = 256M
sync_binlog=1

transaction_isolation = REPEATABLE-READ
innodb_file_per_table
innodb_data_home_dir = /data/mysql
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /data/mysql
innodb_buffer_pool_size = 128M
innodb_log_file_size = 8M
##innodb_log_file_size = 1300M
##innodb_log_files_in_group = 3
#innodb_file_format = Barracuda
default-storage-engine = InnoDB
innodb_max_dirty_pages_pct = 90
innodb_file_per_table = 1
innodb_flush_method = O_DSYNC
innodb_io_capacity = 500
character-set-server = utf8
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 32M

[mysql]
no-auto-rehash
#safe-updates

[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

zabbix_server

init

点击下载

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
cat /etc/init.d/zabbix_server
#!/bin/bash
# chkconfig: - 95 5

. /etc/init.d/functions

RETVAL=0
prog="Zabbix Server"
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_server"

if [ ! -x ${ZABBIX_BIN} ] ; then
echo -n "${ZABBIX_BIN} not installed! "
exit 5
fi

start() {
echo -n $"Starting $prog: "
daemon $ZABBIX_BIN
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_server
echo
}

stop() {
echo -n $"Stopping $prog: "
killproc $ZABBIX_BIN
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix_server
echo
}

case "$1" in
start)
start
;;
stop)
stop
;;
reload|restart)
stop
sleep 3
start
RETVAL=$?
;;
status)
status $ZABBIX_BIN
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac

exit $RETVAL

systemd

点击下载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cat /usr/lib/systemd/system/zabbix-server.service
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s

[Install]
WantedBy=multi-user.target

zabbix_agent

init

点击下载

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
cat /etc/init.d/zabbix_agentd
#!/bin/bash
#
# /etc/rc.d/init.d/zabbix_agentd
#
# Starts the zabbix_agentd daemon
#
# chkconfig: - 95 5
# description: Zabbix Monitoring Agent
# processname: zabbix_agentd
# pidfile: /tmp/zabbix_agentd.pid

# Modified for Zabbix 2.0.0
# May 2012, Zabbix SIA

# Source function library.

. /etc/init.d/functions

RETVAL=0
prog="Zabbix Agent"
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"
ZABBIX_CONF="/usr/local/zabbix/etc/zabbix_agentd.conf"

if [ ! -x ${ZABBIX_BIN} ] ; then
echo -n "${ZABBIX_BIN} not installed! "
# Tell the user this has skipped
exit 5
fi

start() {
echo -n $"Starting $prog: "
daemon $ZABBIX_BIN -c $ZABBIX_CONF
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_agentd
echo
}

stop() {
echo -n $"Stopping $prog: "
killproc $ZABBIX_BIN
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix_agentd
echo
}

case "$1" in
start)
start
;;
stop)
stop
;;
reload|restart)
stop
sleep 10
start
RETVAL=$?
;;
condrestart)
if [ -f /var/lock/subsys/zabbix_agentd ]; then
stop
start
fi
;;
status)
status $ZABBIX_BIN
RETVAL=$?
;;
*)
echo $"Usage: $0 {condrestart|start|stop|restart|reload|status}"
exit 1
esac

exit $RETVAL

systemd

点击下载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cat /usr/lib/systemd/system/zabbix-agentd.service
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s

[Install]
WantedBy=multi-user.target

install

点击下载

1
cat zabbix_agent_install_centos.sh

zabbix_proxy

init

点击下载

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
cat /etc/init.d/zabbix_proxy
#!/bin/bash
# chkconfig: - 95 5

. /etc/init.d/functions

RETVAL=0
prog="Zabbix Proxy"
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_proxy"

if [ ! -x ${ZABBIX_BIN} ] ; then
echo -n "${ZABBIX_BIN} not installed! "
# Tell the user this has skipped
exit 5
fi

start() {
echo -n $"Starting $prog: "
daemon $ZABBIX_BIN
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_proxy
echo
}

stop() {
echo -n $"Stopping $prog: "
killproc $ZABBIX_BIN
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix_proxy
echo
}

case "$1" in
start)
start
;;
stop)
stop
;;
reload|restart)
stop
sleep 10
start
RETVAL=$?
;;
condrestart)
if [ -f /var/lock/subsys/zabbix_proxy ]; then
stop
start
fi
;;
status)
status $ZABBIX_BIN
RETVAL=$?
;;
*)
echo $"Usage: $0 {condrestart|start|stop|restart|reload|status}"
exit 1
esac

exit $RETVAL

systemd

点击下载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cat /usr/lib/systemd/system/zabbix-proxy.service
[Unit]
Description=Zabbix Proxy
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_proxy.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-proxy
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_proxy.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_proxy -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s

[Install]
WantedBy=multi-user.target