- 1.关闭防火墙和selinux
- 2.获取zabbix下载源
- 3.安装zabbix服务节点数据库服务和客户节点
- 4.安装SCL(Software Collection)工具
- 5.修改zabbix-front前端源,修改如下参数
- 6.安装zabbix前端环境,且是安装到scl环境下
- 7.安装zabbix所需的数据库,mariadb
- 8.配置mariadb数据库
- 9.初始化数据库,设置密码为123456
- 10.添加数据库用户,以及zabbix所需的数据库信息
- 11.使用zabbix-mysql命令,导入数据库信息
- 12.修改zabbix-server配置文件,修改数据库密码
- 13.修改zabbix的php配置文件
- 14.启动zabbix相关服务
- 15.访问zabbix入口
IP | 主机名 |
---|---|
192.168.200.10 | client |
准备机器,环境初始化
使用“CentOS-7-x86_64-DVD-1511”镜像创建虚拟机,最少2核4G,配置IP和本地yum源
1.关闭防火墙和selinux
# systemctl stop firewalld
# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
# setenforce 0
# vi /etc/selinux/config
# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
2.获取zabbix下载源
#rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
可以看到配置文件zabbix.repo
# ls /etc/yum.repos.d/
CentOS-Base.repo local.repo zabbix.repo
更换zabbix.repo源为阿里的
#sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
# cat /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/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=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/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=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
清空缓存,下载zabbix服务端
#yum clean all
#yum makecache --生成缓存
3.安装zabbix服务节点数据库服务和客户节点
yum install -y zabbix-server-mysql zabbix-agent
PS:如果显示有密钥但无法yum成功可尝试以下命令
#rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 --更新检索密钥
4.安装SCL(Software Collection)工具
安装SCL可以在一个系统中安装多个不同版本的软件,同时不会影响到整个系统的依赖环境,会将所有的配置文件都放在/opt/rh/package-name中
#yum install -y centos-release-scl
若无法安装则需要下载阿里源,命令如下:
#wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo
#sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
#yum makecache
5.修改zabbix-front前端源,修改如下参数
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1 #修改此处的参数
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
6.安装zabbix前端环境,且是安装到scl环境下
此时不会直接装在本机,而会装在/opt/rh目录下
#yum install -y zabbix-web-mysql-scl zabbix-apache-conf-scl
7.安装zabbix所需的数据库,mariadb
#yum install -y mariadb-server
8.配置mariadb数据库
设置开机自启
#systemctl enable --now mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
9.初始化数据库,设置密码为123456
#mysql_secure_installation
......
Enter current password for root (enter for none):
......
Set root password? [Y/n] y
......
Remove anonymous users? [Y/n] y
......
Disallow root login remotely? [Y/n] n
......
Remove test database and access to it? [Y/n] y
......
Reload privilege tables now? [Y/n] y
......
Thanks for using MariaDB!
登陆数据库
#mysql -uroot -p
Enter password:
MariaDB [(none)]> exit
Bye
[root@client ~]#
10.添加数据库用户,以及zabbix所需的数据库信息
#mysql -uroot -p
Enter password:
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK,1 row offected(0.00 sec)
MariaDB [(none)]> create user zabbix@client identified by '123456';
Query OK,1 row offected(0.00 sec)
创建一个新用户账户名是zabbix允许client登陆密码设置为123456
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
Query OK,1 row offected(0.00 sec)
给zabbix用户里所有的表所有权限
MariaDB [(none)]>flush privileges;
刷新授权表
MariaDB [(none)]> exit
Bye
11.使用zabbix-mysql命令,导入数据库信息
mysql -u用户名 -p 数据库名
#zcat /usr/share/doc/zabbix-server-mysql-5.0.*/create.sql.gz | mysql -uroot -p123456 zabbix
进入数据库
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| zabbix |
+--------------------+
MariaDB [(none)]> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
| conditions |
| config |
| config_autoreg_tls |
| corr_condition |
| corr_condition_group |
| corr_condition_tag |
| corr_condition_tagpair |
| corr_condition_tagvalue |
| corr_operation |
| correlation |
| dashboard |
| dashboard_user |
| dashboard_usrgrp |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| event_recovery |
| event_suppress |
| event_tag |
| events |
| expressions |
| functions |
| globalmacro |
| globalvars |
| graph_discovery |
| graph_theme |
| graphs |
| graphs_items |
| group_discovery |
| group_prototype |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| host_tag |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| hstgrp |
| httpstep |
| httpstep_field |
| httpstepitem |
| httptest |
| httptest_field |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| interface_snmp |
| item_application_prototype |
| item_condition |
| item_discovery |
| item_preproc |
| item_rtdata |
| items |
| items_applications |
| lld_macro_path |
| lld_override |
| lld_override_condition |
| lld_override_opdiscover |
| lld_override_operation |
| lld_override_ophistory |
| lld_override_opinventory |
| lld_override_opperiod |
| lld_override_opseverity |
| lld_override_opstatus |
| lld_override_optag |
| lld_override_optemplate |
| lld_override_optrends |
| maintenance_tag |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows |
| mappings |
| media |
| media_type |
| media_type_message |
| media_type_param |
| module |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opinventory |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| problem |
| problem_tag |
| profiles |
| proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| rights |
| screen_user |
| screen_usrgrp |
| screens |
| screens_items |
| scripts |
| service_alarms |
| services |
| services_links |
| services_times |
| sessions |
| slides |
| slideshow_user |
| slideshow_usrgrp |
| slideshows |
| sysmap_element_trigger |
| sysmap_element_url |
| sysmap_shape |
| sysmap_url |
| sysmap_user |
| sysmap_usrgrp |
| sysmaps |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| tag_filter |
| task |
| task_acknowledge |
| task_check_now |
| task_close_problem |
| task_data |
| task_remote_command |
| task_remote_command_result |
| task_result |
| timeperiods |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| trigger_tag |
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemaps |
| widget |
| widget_field |
+----------------------------+
166 rows in set (0.00 sec)
解决办法:
编辑要导入的数据库文件
vim /usr/share/doc/zabbix-server-mysql-4.0.7/create.sql.gz
# 在第一行加上
use zabbix;
若提示数据库拒绝访问
解决办法:
#进入/etc/my.cnf目录下
vim /etc/my.cnf
#在[mysqld]这个条目下加入 skip-grant-tables 保存退出后重启mysql
[mysqld]
#作用是跳过登录的验证
#skip-grant-tables
port = 3306
basedir=C:\\softwaretool\\mysql-5.7.23-winx64
datadir=C:\\softwaretool\\mysql-5.7.23-winx64\\data
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_allowed_packet = 20M
[mysql]
default-character-set=utf8
#重启服务
systemctl restart mariadb
12.修改zabbix-server配置文件,修改数据库密码
# vim /etc/zabbix/zabbix_server.conf
搜索/DBPa 找到DBPassword=行
删除注释符#改为“DBPassword=123456”
13.修改zabbix的php配置文件
#vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
#grep 'timezone' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
php_value[data,timezone] = Asia/shanghai
14.启动zabbix相关服务
#systemctl restart httpd.service
15.访问zabbix入口
192.168.200.10/zabbix
初始账号Admin
初始密码zabbix