IP 主机名
192.168.200.10 client

准备机器,环境初始化
使用“CentOS-7-x86_64-DVD-1511”镜像创建虚拟机,最少2核4G,配置IP和本地yum源

1.关闭防火墙和selinux

  1. # systemctl stop firewalld
  2. # systemctl disable firewalld
  3. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
  4. Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
  5. # setenforce 0
  6. # vi /etc/selinux/config
  7. # cat /etc/selinux/config
  8. # This file controls the state of SELinux on the system.
  9. # SELINUX= can take one of these three values:
  10. # enforcing - SELinux security policy is enforced.
  11. # permissive - SELinux prints warnings instead of enforcing.
  12. # disabled - No SELinux policy is loaded.
  13. SELINUX=disabled
  14. # SELINUXTYPE= can take one of three two values:
  15. # targeted - Targeted processes are protected,
  16. # minimum - Modification of targeted policy. Only selected processes are protected.
  17. # mls - Multi Level Security protection.
  18. SELINUXTYPE=targeted

2.获取zabbix下载源

  1. #rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm

可以看到配置文件zabbix.repo

  1. # ls /etc/yum.repos.d/
  2. CentOS-Base.repo local.repo zabbix.repo

更换zabbix.repo源为阿里的

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

清空缓存,下载zabbix服务端

  1. #yum clean all
  2. #yum makecache --生成缓存

3.安装zabbix服务节点数据库服务和客户节点

  1. yum install -y zabbix-server-mysql zabbix-agent

PS:如果显示有密钥但无法yum成功可尝试以下命令

  1. #rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 --更新检索密钥

4.安装SCL(Software Collection)工具

安装SCL可以在一个系统中安装多个不同版本的软件,同时不会影响到整个系统的依赖环境,会将所有的配置文件都放在/opt/rh/package-name中

  1. #yum install -y centos-release-scl

若无法安装则需要下载阿里源,命令如下

  1. #wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
  2. #sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
  3. #yum makecache

5.修改zabbix-front前端源,修改如下参数

  1. [zabbix-frontend]
  2. name=Zabbix Official Repository frontend - $basearch
  3. baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
  4. enabled=1 #修改此处的参数
  5. gpgcheck=1
  6. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

6.安装zabbix前端环境,且是安装到scl环境下

此时不会直接装在本机,而会装在/opt/rh目录下

  1. #yum install -y zabbix-web-mysql-scl zabbix-apache-conf-scl

7.安装zabbix所需的数据库,mariadb

  1. #yum install -y mariadb-server

8.配置mariadb数据库

设置开机自启

  1. #systemctl enable --now mariadb
  2. Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

9.初始化数据库,设置密码为123456

  1. #mysql_secure_installation
  2. ......
  3. Enter current password for root (enter for none):
  4. ......
  5. Set root password? [Y/n] y
  6. ......
  7. Remove anonymous users? [Y/n] y
  8. ......
  9. Disallow root login remotely? [Y/n] n
  10. ......
  11. Remove test database and access to it? [Y/n] y
  12. ......
  13. Reload privilege tables now? [Y/n] y
  14. ......
  15. Thanks for using MariaDB!

登陆数据库

  1. #mysql -uroot -p
  2. Enter password
  3. MariaDB [(none)]> exit
  4. Bye
  5. [root@client ~]#

10.添加数据库用户,以及zabbix所需的数据库信息

  1. #mysql -uroot -p
  2. Enter password
  3. MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
  4. Query OK1 row offected0.00 sec
  5. MariaDB [(none)]> create user zabbix@client identified by '123456';
  6. Query OK1 row offected0.00 sec
  7. 创建一个新用户账户名是zabbix允许client登陆密码设置为123456
  8. MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
  9. Query OK1 row offected0.00 sec
  10. zabbix用户里所有的表所有权限
  11. MariaDB [(none)]>flush privileges;
  12. 刷新授权表
  13. MariaDB [(none)]> exit
  14. Bye

11.使用zabbix-mysql命令,导入数据库信息

mysql -u用户名 -p 数据库名

  1. #zcat /usr/share/doc/zabbix-server-mysql-5.0.*/create.sql.gz | mysql -uroot -p123456 zabbix
  2. 进入数据库
  3. MariaDB [(none)]> show databases;
  4. +--------------------+
  5. | Database |
  6. +--------------------+
  7. | information_schema |
  8. | mysql |
  9. | performance_schema |
  10. | zabbix |
  11. +--------------------+
  12. MariaDB [(none)]> use zabbix;
  13. Reading table information for completion of table and column names
  14. You can turn off this feature to get a quicker startup with -A
  15. MariaDB [zabbix]> show tables;
  16. +----------------------------+
  17. | Tables_in_zabbix |
  18. +----------------------------+
  19. | acknowledges |
  20. | actions |
  21. | alerts |
  22. | application_discovery |
  23. | application_prototype |
  24. | application_template |
  25. | applications |
  26. | auditlog |
  27. | auditlog_details |
  28. | autoreg_host |
  29. | conditions |
  30. | config |
  31. | config_autoreg_tls |
  32. | corr_condition |
  33. | corr_condition_group |
  34. | corr_condition_tag |
  35. | corr_condition_tagpair |
  36. | corr_condition_tagvalue |
  37. | corr_operation |
  38. | correlation |
  39. | dashboard |
  40. | dashboard_user |
  41. | dashboard_usrgrp |
  42. | dbversion |
  43. | dchecks |
  44. | dhosts |
  45. | drules |
  46. | dservices |
  47. | escalations |
  48. | event_recovery |
  49. | event_suppress |
  50. | event_tag |
  51. | events |
  52. | expressions |
  53. | functions |
  54. | globalmacro |
  55. | globalvars |
  56. | graph_discovery |
  57. | graph_theme |
  58. | graphs |
  59. | graphs_items |
  60. | group_discovery |
  61. | group_prototype |
  62. | history |
  63. | history_log |
  64. | history_str |
  65. | history_text |
  66. | history_uint |
  67. | host_discovery |
  68. | host_inventory |
  69. | host_tag |
  70. | hostmacro |
  71. | hosts |
  72. | hosts_groups |
  73. | hosts_templates |
  74. | housekeeper |
  75. | hstgrp |
  76. | httpstep |
  77. | httpstep_field |
  78. | httpstepitem |
  79. | httptest |
  80. | httptest_field |
  81. | httptestitem |
  82. | icon_map |
  83. | icon_mapping |
  84. | ids |
  85. | images |
  86. | interface |
  87. | interface_discovery |
  88. | interface_snmp |
  89. | item_application_prototype |
  90. | item_condition |
  91. | item_discovery |
  92. | item_preproc |
  93. | item_rtdata |
  94. | items |
  95. | items_applications |
  96. | lld_macro_path |
  97. | lld_override |
  98. | lld_override_condition |
  99. | lld_override_opdiscover |
  100. | lld_override_operation |
  101. | lld_override_ophistory |
  102. | lld_override_opinventory |
  103. | lld_override_opperiod |
  104. | lld_override_opseverity |
  105. | lld_override_opstatus |
  106. | lld_override_optag |
  107. | lld_override_optemplate |
  108. | lld_override_optrends |
  109. | maintenance_tag |
  110. | maintenances |
  111. | maintenances_groups |
  112. | maintenances_hosts |
  113. | maintenances_windows |
  114. | mappings |
  115. | media |
  116. | media_type |
  117. | media_type_message |
  118. | media_type_param |
  119. | module |
  120. | opcommand |
  121. | opcommand_grp |
  122. | opcommand_hst |
  123. | opconditions |
  124. | operations |
  125. | opgroup |
  126. | opinventory |
  127. | opmessage |
  128. | opmessage_grp |
  129. | opmessage_usr |
  130. | optemplate |
  131. | problem |
  132. | problem_tag |
  133. | profiles |
  134. | proxy_autoreg_host |
  135. | proxy_dhistory |
  136. | proxy_history |
  137. | regexps |
  138. | rights |
  139. | screen_user |
  140. | screen_usrgrp |
  141. | screens |
  142. | screens_items |
  143. | scripts |
  144. | service_alarms |
  145. | services |
  146. | services_links |
  147. | services_times |
  148. | sessions |
  149. | slides |
  150. | slideshow_user |
  151. | slideshow_usrgrp |
  152. | slideshows |
  153. | sysmap_element_trigger |
  154. | sysmap_element_url |
  155. | sysmap_shape |
  156. | sysmap_url |
  157. | sysmap_user |
  158. | sysmap_usrgrp |
  159. | sysmaps |
  160. | sysmaps_elements |
  161. | sysmaps_link_triggers |
  162. | sysmaps_links |
  163. | tag_filter |
  164. | task |
  165. | task_acknowledge |
  166. | task_check_now |
  167. | task_close_problem |
  168. | task_data |
  169. | task_remote_command |
  170. | task_remote_command_result |
  171. | task_result |
  172. | timeperiods |
  173. | trends |
  174. | trends_uint |
  175. | trigger_depends |
  176. | trigger_discovery |
  177. | trigger_tag |
  178. | triggers |
  179. | users |
  180. | users_groups |
  181. | usrgrp |
  182. | valuemaps |
  183. | widget |
  184. | widget_field |
  185. +----------------------------+
  186. 166 rows in set (0.00 sec)

若显示无法找到该文件

image.png

解决办法:

  1. 编辑要导入的数据库文件
  2. vim /usr/share/doc/zabbix-server-mysql-4.0.7/create.sql.gz
  3. # 在第一行加上
  4. use zabbix;

若提示数据库拒绝访问
image.png
解决办法:

  1. #进入/etc/my.cnf目录下
  2. vim /etc/my.cnf
  3. #在[mysqld]这个条目下加入 skip-grant-tables 保存退出后重启mysql
  4. [mysqld]
  5. #作用是跳过登录的验证
  6. #skip-grant-tables
  7. port = 3306
  8. basedir=C:\\softwaretool\\mysql-5.7.23-winx64
  9. datadir=C:\\softwaretool\\mysql-5.7.23-winx64\\data
  10. max_connections=200
  11. character-set-server=utf8
  12. default-storage-engine=INNODB
  13. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  14. max_allowed_packet = 20M
  15. [mysql]
  16. default-character-set=utf8
  17. #重启服务
  18. systemctl restart mariadb

12.修改zabbix-server配置文件,修改数据库密码

  1. # vim /etc/zabbix/zabbix_server.conf
  2. 搜索/DBPa 找到DBPassword=行
  3. 删除注释符#改为“DBPassword=123456

13.修改zabbix的php配置文件

  1. #vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
  2. #grep 'timezone' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
  3. php_value[datatimezone] = Asia/shanghai

14.启动zabbix相关服务

  1. #systemctl restart httpd.service

15.访问zabbix入口

192.168.200.10/zabbix
初始账号Admin
初始密码zabbix