当前位置:   article > 正文

Ubuntu 20.04 LTS 安装zabbix监控部署_ubuntu20.04安装zabbix

ubuntu20.04安装zabbix

一、准备环境直接开搞

(1)准备一台虚拟机或者云服务器,本文环境云服务器

操作系统:Ubuntu 20.04 LTS

zabbix官网:下载Zabbixicon-default.png?t=N7T8https://www.zabbix.com/cn/download

(2)找到官网zabbix安装手册,选择对应的zabbix版本,我这里选择zabbix 6.0

二、话不多说直接进行zabbix server安装操作

(1)下载zabbix安装包

 wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4+ubuntu20.04_all.deb

  1. root@10-7-81-96:~# wget https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4+ubuntu18.04_all.deb
  2. --2024-07-02 11:27:34-- https://repo.zabbix.com/zabbix/6.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.0-4+ubuntu18.04_all.deb
  3. Resolving repo.zabbix.com (repo.zabbix.com)... 178.128.6.101, 2604:a880:2:d0::2062:d001
  4. Connecting to repo.zabbix.com (repo.zabbix.com)|178.128.6.101|:443... connected.
  5. HTTP request sent, awaiting response... 200 OK
  6. Length: 3672 (3.6K) [application/octet-stream]
  7. Saving to: ‘zabbix-release_6.0-4+ubuntu20.04_all.deb’
  8. zabbix-release_6.0-4+ubuntu18.04_all.de 100%[==============================================================================>] 3.59K --.-KB/s in 0s
  9. 2024-07-02 11:27:35 (702 MB/s) - ‘zabbix-release_6.0-4+ubuntu20.04_all.deb’ saved [3672/3672]
  10. root@10-7-81-96:~#

(2) 进行zabbix安装,如果使用root用户则不会报错,使用Ubuntu用户直接安装会报错(如下图一),权限不足,使用sudo命令提权

sudo dpkg -i zabbix-release_6.0-4+ubuntu20.04_all.deb

  1. ubuntu@10-7-81-96:~$ dpkg -i zabbix-release_6.0-4+ubuntu18.04_all.deb
  2. dpkg: error: requested operation requires superuser privilege
  3. ubuntu@10-7-81-96:~$
  4. ubuntu@10-7-81-96:~$ sudo dpkg -i zabbix-release_6.0-4+ubuntu18.04_all.deb
  5. Selecting previously unselected package zabbix-release.
  6. (Reading database ... 95416 files and directories currently installed.)
  7. Preparing to unpack zabbix-release_6.0-4+ubuntu18.04_all.deb ...
  8. Unpacking zabbix-release (1:6.0-4+ubuntu18.04) ...
  9. Setting up zabbix-release (1:6.0-4+ubuntu18.04) ...
  10. ubuntu@10-7-81-96:~$ ls
  1. root@10-7-81-96:~# dpkg -i zabbix-release_6.0-4+ubuntu18.04_all.deb
  2. Selecting previously unselected package zabbix-release.
  3. (Reading database ... 95416 files and directories currently installed.)
  4. Preparing to unpack zabbix-release_6.0-4+ubuntu18.04_all.deb ...
  5. Unpacking zabbix-release (1:6.0-4+ubuntu18.04) ...
  6. Setting up zabbix-release (1:6.0-4+ubuntu18.04) ...
  7. root@10-7-81-96:~#

(3)更新Ubuntu源,更新之后最好reboot重新一下系统,使系统安装包已经内核生效

apt update 

  1. root@10-7-81-96:~$ apt update
  2. Hit:1 http://mirrors.ucloud.cn/ubuntu bionic InRelease
  3. Get:2 http://mirrors.ucloud.cn/ubuntu bionic-security InRelease [102 kB]
  4. Get:3 http://mirrors.ucloud.cn/ubuntu bionic-updates InRelease [102 kB]
  5. Get:4 http://mirrors.ucloud.cn/ubuntu bionic-backports InRelease [102 kB]
  6. Get:5 http://mirrors.ucloud.cn/ubuntu bionic-proposed InRelease [251 kB]
  7. Get:6 http://mirrors.ucloud.cn/ubuntu bionic-security/main Sources [301 kB]
  8. Get:7 http://mirrors.ucloud.cn/ubuntu bionic-security/multiverse Sources [12.2 kB]
  9. Get:8 http://mirrors.ucloud.cn/ubuntu bionic-security/restricted Sources [32.4 kB]
  10. Get:9 http://mirrors.ucloud.cn/ubuntu bionic-security/universe Sources [337 kB]
  11. Get:10 http://mirrors.ucloud.cn/ubuntu bionic-security/main i386 Packages [1,379 kB]
  12. Get:11 http://mirrors.ucloud.cn/ubuntu bionic-security/main amd64 Packages [2,717 kB]
  13. Get:12 http://mirrors.ucloud.cn/ubuntu bionic-security/main Translation-en [467 kB]
  14. Get:13 http://mirrors.ucloud.cn/ubuntu bionic-security/restricted i386 Packages [33.0 kB]
  15. Get:14 http://mirrors.ucloud.cn/ubuntu bionic-security/restricted amd64 Packages [1,317 kB]
  16. ......中间省略......
  17. Get:63 https://repo.zabbix.com/zabbix/6.0/ubuntu bionic/main all Packages [18.2 kB]
  18. Get:64 https://repo.zabbix.com/zabbix/6.0/ubuntu bionic/main amd64 Packages [85.5 kB]
  19. Fetched 22.9 MB in 5s (4,805 kB/s)
  20. Reading package lists... Done
  21. Building dependency tree
  22. Reading state information... Done
  23. 277 packages can be upgraded. Run 'apt list --upgradable' to see them.
  24. root@10-7-81-96:~$

(4)安装Zabbix server,Web前端,agent

apt install zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-sql-scripts zabbix-agent

  1. root@10-7-81-96:~$ apt install zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-sql-scripts zabbix-agent
  2. Reading package lists... Done
  3. Building dependency tree
  4. Reading state information... Done
  5. The following additional packages will be installed:
  6. fontconfig-config fonts-dejavu fonts-dejavu-core fonts-dejavu-extra fping libaio1 libfontconfig1 libgd3 libjbig0 libjpeg-turbo8 libjpeg8 libmysqlclient20
  7. libnginx-mod-http-geoip libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream libodbc1 libopenipmi0
  8. libpcre2-8-0 libsensors4 libsnmp-base libsnmp30 libsodium23 libssh-4 libtiff5 libwebp6 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxpm4 libxslt1.1
  9. mysql-client mysql-client-5.7 mysql-client-core-5.7 mysql-common nginx nginx-common nginx-core php-bcmath php-common php-fpm php-gd php-ldap php-mbstring
  10. php-mysql php-xml php7.2-bcmath php7.2-cli php7.2-common php7.2-fpm php7.2-gd php7.2-json php7.2-ldap php7.2-mbstring php7.2-mysql php7.2-opcache
  11. php7.2-readline php7.2-xml snmpd
  12. Suggested packages:
  13. libgd-tools libmyodbc odbc-postgresql tdsodbc unixodbc-bin lm-sensors snmp-mibs-downloader fcgiwrap nginx-doc ssl-cert php-pear snmptrapd
  14. zabbix-apache-conf virtual-mysql-server
  15. The following NEW packages will be installed:
  16. fontconfig-config fonts-dejavu fonts-dejavu-core fonts-dejavu-extra fping libaio1 libfontconfig1 libgd3 libjbig0 libjpeg-turbo8 libjpeg8 libmysqlclient20
  17. libnginx-mod-http-geoip libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter libnginx-mod-mail libnginx-mod-stream libodbc1 libopenipmi0
  18. libpcre2-8-0 libsensors4 libsnmp-base libsnmp30 libsodium23 libssh-4 libtiff5 libwebp6 libx11-6 libx11-data libxau6 libxcb1 libxdmcp6 libxpm4 libxslt1.1
  19. mysql-client mysql-client-5.7 mysql-client-core-5.7 mysql-common nginx nginx-common nginx-core php-bcmath php-common php-fpm php-gd php-ldap php-mbstring
  20. php-mysql php-xml php7.2-bcmath php7.2-cli php7.2-common php7.2-fpm php7.2-gd php7.2-json php7.2-ldap php7.2-mbstring php7.2-mysql php7.2-opcache
  21. php7.2-readline php7.2-xml snmpd zabbix-agent zabbix-frontend-php zabbix-nginx-conf zabbix-server-mysql zabbix-sql-scripts
  22. 0 upgraded, 67 newly installed, 0 to remove and 277 not upgraded.
  23. Need to get 38.7 MB of archives.
  24. After this operation, 166 MB of additional disk space will be used.
  25. Do you want to continue? [Y/n] y #这里选择yes 进行下载安装

(5)创建初始数据库,如果进入数据库失败报错如下,重新安装mysql

apt install mysql-server

  1. root@10-7-81-96:~# mysql -uroot -p
  2. Enter password:
  3. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
  4. root@10-7-81-96:~#
  5. 检查MySQL是否启动,看到MySQL并没有启动,连命令都没有找到
  6. root@10-7-81-96:~# systemctl status mysql
  7. Unit mysql.service could not be found.
  8. root@10-7-81-96:~# systemctl status mysql.service
  9. Unit mysqld.service could not be found.
  10. 重装一下mysql-server
  11. root@10-7-81-96# apt install mysql-server
  12. Reading package lists... Done
  13. Building dependency tree
  14. Reading state information... Done
  15. The following additional packages will be installed:
  16. libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl
  17. libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl
  18. liblwp-mediatypes-perl libmecab2 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils
  19. mysql-server-8.0 mysql-server-core-8.0
  20. Suggested packages:
  21. libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx tinyca
  22. The following NEW packages will be installed:
  23. libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-perl
  24. libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl
  25. liblwp-mediatypes-perl libmecab2 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-server
  26. mysql-server-8.0 mysql-server-core-8.0
  27. 0 upgraded, 22 newly installed, 0 to remove and 322 not upgraded.
  28. Need to get 31.8 MB of archives.
  29. After this operation, 244 MB of additional disk space will be used.
  30. Do you want to continue? [Y/n] y
  31. ......
  32. 安装完成后,检查MySQL是否启动
  33. root@10-7-81-96:~# systemctl status mysql
  34. ● mysql.service - MySQL Community Server
  35. Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
  36. Active: active (running) since Wed 2024-07-03 14:32:41 HKT; 22s ago
  37. Main PID: 12386 (mysqld)
  38. Status: "Server is operational"
  39. Tasks: 38 (limit: 4389)
  40. Memory: 365.5M
  41. CGroup: /system.slice/mysql.service
  42. └─12386 /usr/sbin/mysqld
  43. Jul 03 14:32:40 10-7-81-96 systemd[1]: Starting MySQL Community Server...
  44. Jul 03 14:32:41 10-7-81-96 systemd[1]: Started MySQL Community Server.

(6)正常启动MySQL,再次创建数据库

mysql -uroot -p
password
mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
mysql> create user zabbix@localhost identified by 'password';
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> set global log_bin_trust_function_creators = 1;
mysql> quit;

  1. root@10-7-81-96:~# mysql -uroot -p
  2. Enter password:password #默认是password
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 8
  5. Server version: 8.0.37-0ubuntu0.20.04.3 (Ubuntu)
  6. Copyright (c) 2000, 2024, Oracle and/or its affiliates.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
  12. Query OK, 1 row affected (0.01 sec)
  13. mysql> create user zabbix@localhost identified by 'password';
  14. Query OK, 0 rows affected (0.01 sec)
  15. mysql> grant all privileges on zabbix.* to zabbix@localhost;
  16. Query OK, 0 rows affected (0.01 sec)
  17. mysql> set global log_bin_trust_function_creators = 1;
  18. Query OK, 0 rows affected, 1 warning (0.00 sec)
  19. mysql> quit;
  20. Bye

(7)导入初始架构和数据,输入新创建的密码。

zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix

  1. root@10-7-81-96:~# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix
  2. Enter password:
  3. root@10-7-81-96:~#

(8)导入数据库架构后禁用log_bin_trust_function_creators选项。

  1. root@10-7-81-96:~# mysql -uroot -p
  2. Enter password:
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 10
  5. Server version: 8.0.37-0ubuntu0.20.04.3 (Ubuntu)
  6. Copyright (c) 2000, 2024, Oracle and/or its affiliates.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql> set global log_bin_trust_function_creators = 0;
  12. Query OK, 0 rows affected, 1 warning (0.00 sec)
  13. mysql> quit;
  14. Bye

(9)配置Zabbix server数据库密码,找到DBpassword这行,取消注释填写密码

vim /etc/zabbix/zabbix_server.conf

  1. ### Option: DBPassword
  2. # Database password.
  3. # Comment this line if no password is used.
  4. #
  5. # Mandatory: no
  6. # Default:
  7. # DBPassword=
  8. DBPassword=password

(10)配置Zabbix前端PHP,编辑配置文件,将这两行注释取消即可

vim /etc/zabbix/nginx.conf

  1. server {
  2. listen 8080;
  3. server_name example.com;

(11)重启启动zabbix server和agent进程,并设置开机自启动

systemctl restart zabbix-server zabbix-agent nginx php7.4-fpm
systemctl enable zabbix-server zabbix-agent nginx php7.4-fpm

  1. root@10-7-81-96:~# systemctl restart zabbix-server zabbix-agent nginx php7.4-fpm
  2. root@10-7-81-96:~# systemctl enable zabbix-server zabbix-agent nginx php7.4-fpm
  3. Synchronizing state of zabbix-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
  4. Executing: /lib/systemd/systemd-sysv-install enable zabbix-server
  5. Synchronizing state of zabbix-agent.service with SysV service script with /lib/systemd/systemd-sysv-install.
  6. Executing: /lib/systemd/systemd-sysv-install enable zabbix-agent
  7. Synchronizing state of nginx.service with SysV service script with /lib/systemd/systemd-sysv-install.
  8. Executing: /lib/systemd/systemd-sysv-install enable nginx
  9. Synchronizing state of php7.4-fpm.service with SysV service script with /lib/systemd/systemd-sysv-install.
  10. Executing: /lib/systemd/systemd-sysv-install enable php7.4-fpm
  11. Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-server.service → /lib/systemd/system/zabbix-server.service.
  12. root@10-7-81-96:~#

注意:云服务器需要在防火墙开启对应的端口,例如3306,8080端口!!不然直接外网IP访问会失败!!

三、zabbix前端网页访问

(1)网页访问进行zabbix:http://ip:8080/即可,如下图,一直点击下一步即可

(2)都是正常的即可下一步

(3)需要输入zabbix数据库密码(步骤11配置的),数据库端口根据需求定义即可

(4)设置主机名,根据自己情况定义即可

(5)检查一下用户,密码都没有问题之后即可

(6)出现下面界面,说明zabbix前端已经配置
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/881787

推荐阅读
相关标签