zabbix 分布式部署
wget https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591-EL5
rpm —import RPM-GPG-KEY-ZABBIX-A14FE591-EL5
touch /etc/yum.repos.d/zabbix-aliyun.repo
cat >/etc/yum.repos.d/zabbix-aliyun.repo << EOF
[zabbix]
name=Zabbix-aliyun
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591-EL5
EOF
组件:
zabbix-server | 192.168.11.160 | 服务端 zabbix-server-mysql |
zabbix-server-db | 192.168.11.161 | 数据库 mariadb-server.x86_64 mariadb.x86_64 |
zabbix-ui | 192.168.11.162 | 前端 zabbix-web-mysql-scl zabbix-nginx-conf-scl |
zabbix-server-proxy | 192.168.11.163 | 代理 zabbix-agent2.x86_64 |
[root@riyimei ~]# uname -ra
Linux riyimei 3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[root@riyimei ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@riyimei ~]#
a. 安装 数据库
# rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
# yum clean all
b. Install Zabbix server and agent
# yum install zabbix-server-mysql zabbix-agent
c. Install Zabbix frontend
Enable Red Hat Software Collections
# yum-config-manager --enable rhel-server-rhscl-7-rpms
编辑配置文件 /etc/yum.repos.d/zabbix.repo and enable zabbix-frontend repository.
[zabbix-frontend]
...
enabled=1
...
Install Zabbix frontend packages.
# yum install zabbix-web-mysql-scl zabbix-nginx-conf-scl
d. 创建初始数据库
在数据库主机上运行以下代码。
# mysql -uroot -p
password
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> quit;
导入初始架构和数据,系统将提示您输入新创建的密码。
# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
e. 为Zabbix server配置数据库
编辑配置文件 /etc/zabbix/zabbix_server.conf
DBPassword=password
f. 为Zabbix前端配置PHP
编辑配置文件 /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf, uncomment and set 'listen' and 'server_name' directives.
# listen 80;
# server_name example.com;
编辑配置文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf, add nginx to listen.acl_users directive.
listen.acl_users = apache,nginx
Then uncomment and set the right timezone for you.
; php_value[date.timezone] = Europe/Riga
g. 启动Zabbix server和agent进程
启动Zabbix server和agent进程,并为它们设置开机自启:
# systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
# systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
h. 配置Zabbix前端
连接到新安装的Zabbix前端: http://server_ip_or_name
根据Zabbix文件里步骤操作: Installing frontend
1 安装server端
yum install zabbix-server-mysql -y
2 安装数据库
yum install mariadb-server.x86_64 mariadb.x86_64 -y
3 安装前端
yum install yum-utils -yyum-config-manager —enable rhel-server-rhscl-7-rpmsyum install zabbix-web-mysql-scl zabbix-nginx-conf-scl
修改yum源
[root@zabbix-server-ui ~]# cat /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/debuginfo/
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
gpgcheck=1
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
[root@zabbix-server-ui ~]#
修改nginx配置文件:
[root@prod-zabbix-gui ~]# ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'
364M
[root@prod-zabbix-gui ~]# ps -ylC php-fpm --sort:rss
S UID PID PPID C PRI NI RSS SZ WCHAN TTY TIME CMD
S 48 166022 166021 0 80 0 7580 83562 inet_c ? 00:00:00 php-fpm
S 48 166023 166021 0 80 0 7580 83562 inet_c ? 00:00:00 php-fpm
S 48 166024 166021 0 80 0 7580 83562 inet_c ? 00:00:00 php-fpm
S 48 166025 166021 0 80 0 7580 83562 inet_c ? 00:00:00 php-fpm
S 48 166026 166021 0 80 0 7584 83562 inet_c ? 00:00:00 php-fpm
S 0 166021 1 0 80 0 13524 83056 ep_pol ? 00:07:01 php-fpm
S 48 249765 166021 0 80 0 551208 219605 skb_wa ? 03:09:53 php-fpm
S 48 249791 166021 0 80 0 551404 219780 skb_wa ? 03:09:51 php-fpm
S 48 250880 166021 0 80 0 551488 219620 skb_wa ? 03:09:43 php-fpm
S 48 175307 166021 0 80 0 554748 220539 skb_wa ? 03:11:51 php-fpm
S 48 166030 166021 0 80 0 557204 221167 skb_wa ? 03:12:22 php-fpm
S 48 166028 166021 0 80 0 557208 221135 skb_wa ? 03:11:59 php-fpm
S 48 166029 166021 0 80 0 557632 221179 skb_wa ? 03:12:02 php-fpm
S 48 166048 166021 0 80 0 557808 221288 skb_wa ? 03:12:30 php-fpm
S 48 166159 166021 0 80 0 558432 221417 skb_wa ? 03:12:23 php-fpm
S 48 166031 166021 0 80 0 558464 221487 skb_wa ? 03:12:45 php-fpm
S 48 166027 166021 0 80 0 559232 221599 skb_wa ? 03:12:23 php-fpm
S 48 166134 166021 0 80 0 559524 221616 skb_wa ? 03:12:14 php-fpm
[root@prod-zabbix-gui ~]#
systemctl restart rh-php72-php-fpm.service
4 Zabbix对接Grafana
清理旧版本信息
rm -rf /var/lib/grafana
rm -rf /var/log/grafana
rm -rf /var/cache/yum/grafana
rm -rf /usr/share/grafana
rm -rf /usr/share/grafana/conf/defaults.ini
rm -rf /usr/share/grafana/public/app/plugins/datasource/grafana
rm -rf /etc/grafana
unzip alexanderzobnin-zabbix-app-4.0.1.zip -d /var/lib/grafana/plugins/
https://grafana.com/docs/grafana/latest/installation/rpm/
https://github.com/alexanderzobnin/grafana-zabbix/tags
手动部署插件
unzip alexanderzobnin-zabbix-app-4.0.1.zip -d /var/lib/grafana/plugins/
systemctl restart grafana-server