蔡斯 | Zabbix资深玩家
本文主要讲述如何在国产系统上离线部署Zabbix三大服务组件(Server/Proxy/Agent),同时实现系统级的服务托管。希望给大家带来帮助和参考。
考虑到后期的安全及稳定性,这里选择Zabbix5.0.13 LTS版进行部署演示。
组件 | 端口 |
---|---|
Zabbix Server | 10052 |
Zabbix Proxy | 10051 |
Zabbix Agent | 10050 |
组件 | 实例 | 版本 |
---|---|---|
Zabbix Server | MariaDB | 10.3.9 |
Zabbix Proxy | SQLite3 | 3.36.0 |
# cat /proc/version #银河麒麟v10
Linux version 4.19.90-23.6.ky10.aarch64 (KYLINSOFT@localhost.localdomain) (gcc version 7.3.0 (GCC)) #1 SMP Wed Mar 17 14:45:17 CST 2021
# getconf LONG_BIT
64
# uname -r
4.19.90-23.6.ky10.aarch64
# uname -i
aarch64
# cat /proc/cpuinfo
processor : 0
model name : ARMv8 CPU
BogoMIPS : 200.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma d
cpop asimddp asimdfhm
CPU implementer : 0x48
CPU architecture: 8
CPU variant : 0x1
CPU part : 0xd01
CPU revision : 0
...省略...
因实际演示环境无法连接互联网,估优先使用ISO镜像自带的YUM源或自建YUM源安装依赖软件包;如无法获取,则再进行人工上传二进制包或RPM包安装。
Zabbix Server主要Lib依赖库有:libpcre、libevent、libpthread、zlib、libcurl、libxml2、net-snmp、gnutls、openssl or libressl;Zabbix Agent主要Lib依赖库有:libpcre、openssl;有些属于强制性,有些属于可选,为避免安装过程出问题,建议选择全部安装。具体可参考官网文档。
yum -y install net-snmp-devel libxml2-devel libcurl-devel libevent-devel pcre-devel libxml2-devel openssl-devel zlib-devel
倘若无法使用YUM安装,则需手动编译。如下演示如何安装libevent库。
# wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz #通过浏览器或其他服务器下载
# cd libevent-2.1.12-stable/
# tar xf libevent-2.1.12-stable.tar.gz
# cd libevent-2.1.12
# ./configure --prefix=/usr/local/libevent
# make && make install
# ldconfig -p |grep libevent
libverto-libevent.so.1 (libc6,AArch64) => /lib64/libverto-libevent.so.1
libverto-libevent.so (libc6,AArch64) => /lib64/libverto-libevent.so
libevent_pthreads-2.1.so.7 (libc6,AArch64) => /lib64/libevent_pthreads-2.1.so.7
libevent_pthreads-2.1.so.6 (libc6,AArch64) => /lib64/libevent_pthreads-2.1.so.6
libevent_openssl-2.1.so.7 (libc6,AArch64) => /lib64/libevent_openssl-2.1.so.7
libevent_openssl-2.1.so.6 (libc6,AArch64) => /lib64/libevent_openssl-2.1.so.6
libevent_extra-2.1.so.7 (libc6,AArch64) => /lib64/libevent_extra-2.1.so.7
libevent_extra-2.1.so.6 (libc6,AArch64) => /lib64/libevent_extra-2.1.so.6
libevent_core-2.1.so.7 (libc6,AArch64) => /lib64/libevent_core-2.1.so.7
libevent_core-2.1.so.6 (libc6,AArch64) => /lib64/libevent_core-2.1.so.6
libevent-2.1.so.7 (libc6,AArch64) => /lib64/libevent-2.1.so.7
libevent-2.1.so.6 (libc6,AArch64) => /lib64/libevent-2.1.so.6
监控数据的存储方面,Zabbix Server选择MariaDB、Zabbix Proxy选择SQLite3。
优先查YUM源是否提供MariaDB,若无再离线安装。
# yum search mariadb
Last metadata expiration check: 1:44:58 ago on 2021年07月12日 星期一 15时14分29秒.
======================================= Name Exactly Matched: mariadb =======================================
mariadb.aarch64 : One of the most popular database servers
====================================== Name & Summary Matched: mariadb ======================================
mariadb-server.aarch64 : The MariaDB server
mariadb-connector-c.aarch64 : MariaDB connector library in C
mariadb-connector-c-devel.aarch64 : Mariadb-connector-c library and header files
mariadb-devel.aarch64 : Including header files and library for the developing of mariadb
=========================================== Name Matched: mariadb ===========================================
mariadb-common.aarch64 : It including share config files used by client and server
mariadb-errmessage.aarch64 : It including the error messages files
# yum -y install mariadb mariadb-devel mariadb-server mariadb-connector-c
Last metadata expiration check: 2:04:00 ago on 2021年07月13日 星期二 12时29分29秒.
Package mariadb-connector-c-3.0.6-6.ky10.aarch64 is already installed.
Dependencies resolved.
=============================================================================================================
Package Architecture Version Repository Size
=============================================================================================================
Installing:
mariadb aarch64 3:10.3.9-8.ky10 Kylin 5.9 M
mariadb-devel aarch64 3:10.3.9-8.ky10 Kylin 1.0 M
mariadb-server aarch64 3:10.3.9-8.ky10 Kylin 17 M
Installing dependencies:
mariadb-common aarch64 3:10.3.9-8.ky10 Kylin 28 k
mariadb-connector-c-devel aarch64 3.0.6-6.ky10 Kylin 48 k
mariadb-errmessage aarch64 3:10.3.9-8.ky10 Kylin 196 k
perl-DBD-MySQL aarch64 4.046-6.ky10 Kylin 113 k
perl-DBI aarch64 1.642-2.ky10 Kylin 447 k
Transaction Summary
=============================================================================================================
Install 8 Packages
Total download size: 25 M
Installed size: 140 M
Downloading Packages:
(1/8): mariadb-common-10.3.9-8.ky10.aarch64.rpm 9.6 MB/s | 28 kB 00:00
(2/8): mariadb-connector-c-devel-3.0.6-6.ky10.aarch64.rpm 14 MB/s | 48 kB 00:00
(3/8): mariadb-errmessage-10.3.9-8.ky10.aarch64.rpm 77 MB/s | 196 kB 00:00
(4/8): mariadb-devel-10.3.9-8.ky10.aarch64.rpm 85 MB/s | 1.0 MB 00:00
(5/8): perl-DBD-MySQL-4.046-6.ky10.aarch64.rpm 68 MB/s | 113 kB 00:00
(6/8): perl-DBI-1.642-2.ky10.aarch64.rpm 117 MB/s | 447 kB 00:00
(7/8): mariadb-10.3.9-8.ky10.aarch64.rpm 146 MB/s | 5.9 MB 00:00
(8/8): mariadb-server-10.3.9-8.ky10.aarch64.rpm 231 MB/s | 17 MB 00:00
-------------------------------------------------------------------------------------------------------------
... 省略 ...
Complete!
# mysql -V
mysql Ver 15.1 Distrib 10.3.9-MariaDB, for Linux (aarch64) using readline 5.1
# systemctl enable mariadb && systemctl start mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Sorry, passwords do not match.
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
# mysql -uroot -p<password>
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
MariaDB [(none)]> create user 'zabbix'@'localhost' identified by 'zabbix@pw';
MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'localhost';
MariaDB [(none)]> quit
# cd database/mysql/
# mysql -uzabbix -p<password> zabbix < schema.sql
# mysql -uzabbix -p<password> zabbix < images.sql
# mysql -uzabbix -p<password> zabbix < data.sql
# wget https://www.sqlite.org/2021/sqlite-autoconf-3360000.tar.gz
# tar xf sqlite-autoconf-3360000.tar.gz
# cd sqlite-autoconf-3360000/
# ./configure --prefix=/usr/local/sqlite3 CC=/usr/bin/aarch64-linux-gnu-gcc --host=arm-linux
# make -j8 && make install
# /usr/local/sqlite3/bin/sqlite3 -version
3.36.0 2021-06-18 18:36:39 5c9a6c06871cb9fe42814af9c039eb6da5427a6ec28f187af7ebfb62eafa66e5
# wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.13.tar.gz
# tar xf zabbix-5.0.13.tar.gz
# cd zabbix-5.0.13
# ./configure --prefix=/usr/local/zabbix --enable-server --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-libevent=/usr/local/libevent
# make install
# /usr/local/zabbix/sbin/zabbix_server -V |head -n 1 #验证版本号
zabbix_server (Zabbix) 5.0.13
# ./configure --prefix=/usr/local/zabbix --enable-proxy --with-net-snmp --with-libevent=/usr/local/libevent --with-sqlite3=/usr/local/sqlite3 --with-libcurl --with-openssl
# make install
# /usr/local/zabbix/sbin/zabbix_proxy -V |head -n 1 #验证版本号
zabbix_proxy (Zabbix) 5.0.13
# ./configure --prefix=/usr/local/zabbix --enable-agent --with-net-snmp --with-libcurl --with-openssl
# make install
# cd /usr/local/zabbix/sbin
# /usr/local/zabbix/sbin/zabbix_agentd -V | head -n 1 #验证版本号
zabbix_agentd (daemon) (Zabbix) 5.0.13
# groupadd --system zabbix
# useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
# mkdir -p /data/zabbix/{logs,socket,data}
# chown -R zabbix.zabbix /data/zabbix/
# cd /usr/local/zabbix/etc
# cp zabbix_server.conf zabbix_server.conf.bak
# cat > zabbix_server.conf <<-EOF
ListenPort=10052
LogFile=/data/zabbix/logs/zabbix_server.log
LogFileSize=10
SocketDir=/data/zabbix/socket/
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=<password>
Timeout=30
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
EOF
# cat /usr/local/zabbix/bin/zabbix_server
#!/bin/bash
. /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! "
# Tell the user this has skipped
exit 5
fi
start() {
echo -n $"Starting $prog: "
$ZABBIX_BIN
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_server
echo
}
stop() {
echo -n $"Stopping $prog: "
pids=$(pidof $ZABBIX_BIN)
(test -n "$pids" && kill -15 $pids) || true
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix_server
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload|restart)
stop
sleep 10
start
RETVAL=$?
;;
status)
status $ZABBIX_BIN
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit $RETVAL
EOF
# chmod +x /usr/local/zabbix/bin/zabbix_server
# cat >/usr/lib/systemd/system/zabbix_server.service <<-EOF
[Unit]
Description="Zabbix Server"
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/usr/local/zabbix/bin/zabbix_server start
ExecStop=/usr/local/zabbix/bin/zabbix_server stop
Restart=always
RestartSec=10s
User=zabbix
Group=zabbix
[Install]
WantedBy=multi-user.target
EOF
# systemctl daemon-reload
# systemctl enable zabbix_server.service
# systemctl start zabbix_server.service
# systemctl status zabbix_server.service
● zabbix_server.service - "Zabbix Server"
Loaded: loaded (/usr/lib/systemd/system/zabbix_server.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-07-13 16:13:01 CST; 2min 16s ago
Process: 2065727 ExecStart=/usr/local/zabbix/bin/zabbix_server start (code=exited, status=0/SUCCESS)
Main PID: 2065733 (zabbix_server)
Tasks: 38
Memory: 58.0M
CGroup: /system.slice/zabbix_server.service
├─2065733 /usr/local/zabbix/sbin/zabbix_server
├─2065736 /usr/local/zabbix/sbin/zabbix_server: configuration syncer [synced configuration in 0.03>
├─2065738 /usr/local/zabbix/sbin/zabbix_server: housekeeper [startup idle for 30 minutes]
...省略...
# cd /usr/local/zabbix/etc
# cp zabbix_proxy.conf zabbix_proxy.conf.bak
# cat > zabbix_proxy.conf <<-EOF
ProxyMode=0
Server=<yourserverip>
ServerPort=10052
Hostname=Zabbix-Proxy
LogFile=/data/zabbix/logs/zabbix_proxy.log
LogFileSize=10
SocketDir=/data/zabbix/socket/
DBName=/data/zabbix/data/sqlite3.db
ProxyOfflineBuffer=72
Timeout=30
LogSlowQueries=3000
ConfigFrequency=180
EOF
# cat /usr/local/zabbix/bin/zabbix_proxy
#!/bin/bash
. /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: "
$ZABBIX_BIN
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_proxy
echo
}
stop() {
echo -n $"Stopping $prog: "
pids=$(pidof $ZABBIX_BIN)
(test -n "$pids" && kill -15 $pids) || true
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=$?
;;
status)
status $ZABBIX_BIN
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit $RETVAL
EOF
# chmod +x /usr/local/zabbix/bin/zabbix_proxy
# cat > /usr/lib/systemd/system/zabbix_proxy.service <<-EOF
[Unit]
Description="Zabbix Proxy"
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/usr/local/zabbix/bin/zabbix_proxy start
ExecStop=/usr/local/zabbix/bin/zabbix_proxy stop
Restart=always
RestartSec=10s
User=zabbix
Group=zabbix
[Install]
WantedBy=multi-user.target
EOF
# systemctl daemon-reload
# systemctl enable zabbix_proxy.service
# systemctl start zabbix_proxy.service
# systemctl status zabbix_proxy.service
● zabbix_proxy.service - "Zabbix Proxy"
Loaded: loaded (/usr/lib/systemd/system/zabbix_proxy.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-07-06 19:50:50 CST; 6 days ago
Main PID: 1062629 (zabbix_proxy)
Tasks: 29
Memory: 77.6M
CGroup: /system.slice/zabbix_proxy.service
├─1062629 /usr/local/zabbix/sbin/zabbix_proxy
├─1062631 /usr/local/zabbix/sbin/zabbix_proxy: configuration syncer [synced config 0 bytes in 0.00>
├─1062632 /usr/local/zabbix/sbin/zabbix_proxy: trapper #1 [processed data in 0.000023 sec, waiting>
...省略...
# cd /usr/local/zabbix/etc
# cp zabbix_agentd.conf zabbix_agentd.conf.bak
# cat > zabbix_agentd.conf <<-EOF
LogFile=/data/zabbix/logs/zabbix_agentd.log
LogFileSize=10
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server
HostMetadataItem=system.uname
Timeout=30
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
EOF
# cat /usr/local/zabbix/bin/zabbix_agentd
#!/bin/bash
. /etc/init.d/functions
RETVAL=0
prog="Zabbix Agentd"
ZABBIX_BIN="/usr/local/zabbix/sbin/zabbix_agentd"
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: "
$ZABBIX_BIN
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_agentd
echo
}
stop() {
echo -n $"Stopping $prog: "
pids=$(pidof $ZABBIX_BIN)
(test -n "$pids" && kill -15 $pids) || true
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=$?
;;
status)
status $ZABBIX_BIN
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit $RETVAL
EOF
# chmod +x /usr/local/zabbix/bin/zabbix_agentd
# cat > /usr/lib/systemd/system/zabbix_agentd.service <<-EOF
[Unit]
Description="Zabbix Agentd"
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/usr/local/zabbix/bin/zabbix_agentd start
ExecStop=/usr/local/zabbix/bin/zabbix_agentd stop
Restart=always
RestartSec=10s
User=zabbix
Group=zabbix
[Install]
WantedBy=multi-user.target
EOF
# systemctl daemon-reload
# systemctl enable zabbix_agentd.service
# systemctl start zabbix_agentd.service
# systemctl status zabbix_agentd
● zabbix_agentd.service - "Zabbix Agentd"
Loaded: loaded (/usr/lib/systemd/system/zabbix_agentd.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-07-13 16:52:14 CST; 7s ago
Process: 2071368 ExecStart=/usr/local/zabbix/bin/zabbix_agentd start (code=exited, status=0/SUCCESS)
Main PID: 2071374 (zabbix_agentd)
Tasks: 6
Memory: 7.5M
CGroup: /system.slice/zabbix_agentd.service
├─2071374 /usr/local/zabbix/sbin/zabbix_agentd
├─2071376 /usr/local/zabbix/sbin/zabbix_agentd: collector [idle 1 sec]
├─2071377 /usr/local/zabbix/sbin/zabbix_agentd: listener #1 [waiting for connection]
├─2071378 /usr/local/zabbix/sbin/zabbix_agentd: listener #2 [waiting for connection]
├─2071379 /usr/local/zabbix/sbin/zabbix_agentd: listener #3 [waiting for connection]
└─2071380 /usr/local/zabbix/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
...省略...
# /usr/local/zabbix/bin/zabbix_get -s 127.0.0.1 -k agent.ping
1
# /usr/local/zabbix/bin/zabbix_get -s 127.0.0.1 -k system.uname
Linux localhost 4.19.90-23.6.ky10.aarch64 #1 SMP Wed Mar 17 14:45:17 CST 2021 aarch64
因实际环境上已有Server端,故不再做后续的web配置演示。剩余步骤大家可以参考官网自行摸索,大致也就两步:1)访问web进行setup。2)登录web进行setup。查看仪表盘,看到数据已成功采集。
至此,Zabbix三大组件部署成功!