zabbix 分布式部署

https://www.zabbix.com/cn
image.png

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

  1. cat >/etc/yum.repos.d/zabbix-aliyun.repo << EOF
  2. [zabbix]
  3. name=Zabbix-aliyun
  4. baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/
  5. enabled=1
  6. gpgcheck=1
  7. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591-EL5
  8. 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
  1. [root@riyimei ~]# uname -ra
  2. 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
  3. [root@riyimei ~]# cat /etc/redhat-release
  4. CentOS Linux release 7.7.1908 (Core)
  5. [root@riyimei ~]#
  1. a. 安装 数据库
  2. # rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
  3. # yum clean all
  4. b. Install Zabbix server and agent
  5. # yum install zabbix-server-mysql zabbix-agent
  6. c. Install Zabbix frontend
  7. Enable Red Hat Software Collections
  8. # yum-config-manager --enable rhel-server-rhscl-7-rpms
  9. 编辑配置文件 /etc/yum.repos.d/zabbix.repo and enable zabbix-frontend repository.
  10. [zabbix-frontend]
  11. ...
  12. enabled=1
  13. ...
  14. Install Zabbix frontend packages.
  15. # yum install zabbix-web-mysql-scl zabbix-nginx-conf-scl
  16. d. 创建初始数据库
  17. 在数据库主机上运行以下代码。
  18. # mysql -uroot -p
  19. password
  20. mysql> create database zabbix character set utf8 collate utf8_bin;
  21. mysql> create user zabbix@localhost identified by 'password';
  22. mysql> grant all privileges on zabbix.* to zabbix@localhost;
  23. mysql> quit;
  24. 导入初始架构和数据,系统将提示您输入新创建的密码。
  25. # zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
  26. e. Zabbix server配置数据库
  27. 编辑配置文件 /etc/zabbix/zabbix_server.conf
  28. DBPassword=password
  29. f. Zabbix前端配置PHP
  30. 编辑配置文件 /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf, uncomment and set 'listen' and 'server_name' directives.
  31. # listen 80;
  32. # server_name example.com;
  33. 编辑配置文件 /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf, add nginx to listen.acl_users directive.
  34. listen.acl_users = apache,nginx
  35. Then uncomment and set the right timezone for you.
  36. ; php_value[date.timezone] = Europe/Riga
  37. g. 启动Zabbix serveragent进程
  38. 启动Zabbix serveragent进程,并为它们设置开机自启:
  39. # systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
  40. # systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm
  41. h. 配置Zabbix前端
  42. 连接到新安装的Zabbix前端: http://server_ip_or_name
  43. 根据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 -y
yum-config-manager —enable rhel-server-rhscl-7-rpms
yum install zabbix-web-mysql-scl zabbix-nginx-conf-scl
修改yum源

  1. [root@zabbix-server-ui ~]# cat /etc/yum.repos.d/zabbix.repo
  2. [zabbix]
  3. name=Zabbix Official Repository - $basearch
  4. baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/
  5. enabled=1
  6. gpgcheck=1
  7. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
  8. [zabbix-frontend]
  9. name=Zabbix Official Repository frontend - $basearch
  10. baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontend
  11. enabled=1
  12. gpgcheck=1
  13. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
  14. [zabbix-debuginfo]
  15. name=Zabbix Official Repository debuginfo - $basearch
  16. baseurl=http://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/debuginfo/
  17. enabled=0
  18. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
  19. gpgcheck=1
  20. [zabbix-non-supported]
  21. name=Zabbix Official Repository non-supported - $basearch
  22. baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
  23. enabled=1
  24. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
  25. gpgcheck=1
  26. [root@zabbix-server-ui ~]#

修改nginx配置文件:

  1. [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") }'
  2. 364M
  3. [root@prod-zabbix-gui ~]# ps -ylC php-fpm --sort:rss
  4. S UID PID PPID C PRI NI RSS SZ WCHAN TTY TIME CMD
  5. S 48 166022 166021 0 80 0 7580 83562 inet_c ? 00:00:00 php-fpm
  6. S 48 166023 166021 0 80 0 7580 83562 inet_c ? 00:00:00 php-fpm
  7. S 48 166024 166021 0 80 0 7580 83562 inet_c ? 00:00:00 php-fpm
  8. S 48 166025 166021 0 80 0 7580 83562 inet_c ? 00:00:00 php-fpm
  9. S 48 166026 166021 0 80 0 7584 83562 inet_c ? 00:00:00 php-fpm
  10. S 0 166021 1 0 80 0 13524 83056 ep_pol ? 00:07:01 php-fpm
  11. S 48 249765 166021 0 80 0 551208 219605 skb_wa ? 03:09:53 php-fpm
  12. S 48 249791 166021 0 80 0 551404 219780 skb_wa ? 03:09:51 php-fpm
  13. S 48 250880 166021 0 80 0 551488 219620 skb_wa ? 03:09:43 php-fpm
  14. S 48 175307 166021 0 80 0 554748 220539 skb_wa ? 03:11:51 php-fpm
  15. S 48 166030 166021 0 80 0 557204 221167 skb_wa ? 03:12:22 php-fpm
  16. S 48 166028 166021 0 80 0 557208 221135 skb_wa ? 03:11:59 php-fpm
  17. S 48 166029 166021 0 80 0 557632 221179 skb_wa ? 03:12:02 php-fpm
  18. S 48 166048 166021 0 80 0 557808 221288 skb_wa ? 03:12:30 php-fpm
  19. S 48 166159 166021 0 80 0 558432 221417 skb_wa ? 03:12:23 php-fpm
  20. S 48 166031 166021 0 80 0 558464 221487 skb_wa ? 03:12:45 php-fpm
  21. S 48 166027 166021 0 80 0 559232 221599 skb_wa ? 03:12:23 php-fpm
  22. S 48 166134 166021 0 80 0 559524 221616 skb_wa ? 03:12:14 php-fpm
  23. [root@prod-zabbix-gui ~]#

systemctl restart rh-php72-php-fpm.service

4 Zabbix对接Grafana

清理旧版本信息

  1. rm -rf /var/lib/grafana
  2. rm -rf /var/log/grafana
  3. rm -rf /var/cache/yum/grafana
  4. rm -rf /usr/share/grafana
  5. rm -rf /usr/share/grafana/conf/defaults.ini
  6. rm -rf /usr/share/grafana/public/app/plugins/datasource/grafana
  7. rm -rf /etc/grafana
  8. 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

http://10.201.100.96/api_jsonrpc.php
用户 密码

image.png