在rockylinux 9安装zabbix6.0以及在被监控端安装zabbix agent2
zabbix6.0服务端不再支持Centos7的yum安装,Centos8已停止维护,rockylinux是RHEL的下游免费发行版。
1.安装rockylinux9:阿里云下载地址
#关闭selinux ,防火墙放通http、snmp、zabbix-server(视具体接口而定)并重启防火墙
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=snmp
firewall-cmd --permanent --zone=public --add-service=zabbix-server
firewall-cmd --reload
#查看firewall服务状态
systemctl status firewalld
2.替换rockylinux9的交大源或者阿里源:
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.sjtug.sjtu.edu.cn/rocky|g' \
-i.bak \
/etc/yum.repos.d/[Rr]ocky*.repo
dnf makecache
或
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
-i.bak \
/etc/yum.repos.d/[Rr]ocky*.repo
dnf makecache
3.按照zabbix官方文档安装6.0:
a. Install Zabbix repository,Proceed with installing zabbix repository.
rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/9/x86_64/zabbix-release-6.0-4.el9.noarch.rpm
dnf clean all
b. 安装Zabbix server,Web前端,agent
dnf install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent
c. 创建初始数据库
Make sure you have database server up and running.
本文以Mysql为例
#安装数据库,启动数据库,并开机自启
yum install mariadb-server -y
systemctl enable --now mariadb
#初始化 mariadb 并配置 root 密码
mysql_secure_installation
#直接回车,空
是否设置密码:y
输入设置密码:
再次输入密码:
是否移除anonymous用户:y
是否不允许root远程登录:n
是否移除test数据库:y
是否更新:y
在数据库主机上运行以下代码。(mysql 用户名 zabbix,密码替换password并牢记)
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;
导入初始架构和数据,系统将提示您输入新创建的密码。
zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix
Disable log_bin_trust_function_creators option after importing database schema.
mysql -uroot -p
password
mysql> set global log_bin_trust_function_creators = 0;
mysql> quit;
d. 为Zabbix server配置数据库(前文的password)
编辑配置文件 /etc/zabbix/zabbix_server.conf
DBPassword=password
e. 启动Zabbix server和agent进程
启动Zabbix server和agent进程,并为它们设置开机自启:
systemctl restart zabbix-server zabbix-agent httpd php-fpm
systemctl enable zabbix-server zabbix-agent httpd php-fpm
f. Open Zabbix UI web page
The default URL for Zabbix UI when using Apache web server is http://host/zabbix
配置页面中文语言灰色:
yum install langpacks-zh_CN.noarch
yum install glibc-langpack-zh.x86_64
安装完成后刷新即可选择中文。
4.配置后登录:zabbix默认账户Admin密码zabbix
解决图形界面中文乱码
确认字体路径
cat /usr/share/zabbix/include/defines.inc.php |grep ZBX_FONTPATH
define('ZBX_FONTPATH', realpath('assets/fonts')); // where to search for font (GD > 2.0.18)
进入对应目录,该文件为软链接,指向/etc/alternatives/zabbix-web-font
cd /usr/share/zabbix/assets/fonts
ll
total 0
lrwxrwxrwx. 1 root root 33 Jul 10 23:45 graphfont.ttf -> /etc/alternatives/zabbix-web-font
zabbix-web-font也是软链接,指向字体文件/usr/share/fonts/dejavu-sans-fonts/DejaVuSans.ttf
cd /etc/alternatives
ll
total 0
lrwxrwxrwx. 1 root root 49 Jul 10 23:45 zabbix-web-font -> /usr/share/fonts/dejavu-sans-fonts/DejaVuSans.ttf
进入真正的字体文件目录/usr/share/fonts/dejavu-sans-fonts/、上传C:\Windows\Fonts中的simkai.ttf,备份、替换。
cd /usr/share/fonts/dejavu-sans-fonts
mv DejaVuSans.ttf DejaVuSans.ttf.bak
mv simkai.ttf DejaVuSans.ttf
替换后刷新页面即可。
5.Zabbix-Agent安装
a.在被监控端在线安装agent2
Proceed with installing zabbix repository.
rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/9/x86_64/zabbix-release-6.0-4.el9.noarch.rpm
dnf clean all
Install Zabbix agent2
dnf install zabbix-agent2 zabbix-agent2-plugin-*
vim /etc/zabbix/zabbix_agent2.conf
Server="zabbixserver ip"
Start Zabbix agent2 process
Start Zabbix agent2 process and make it start at system boot.
systemctl restart zabbix-agent2
systemctl enable zabbix-agent2
b.在被监控端源码安装agent
#创建本地源
mkdir /media/centos
mount /dev/cdrom /media/centos
cp -rf /etc/yum.repos.d /etc/yum.repos.d_$(date '+%Y%m%d_%H%M%S')
rm -rf /etc/yum.repos.d/*
vi /etc/yum.repos.d/Media.repo
[base]
name=Media
baseurl=file:///media/centos/
gpgcheck=0
enabled=1
# 清除yum缓存
yum clean all
# 缓存本地yum源
yum makecache
# 测试yum本地源
yum list
#编译安装zabbix agent
groupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
mkdir /usr/local/zabbix
#上传zabbix源代码
cp zabbix-5.0.37.tar.gz /usr/local/zabbix/zabbix-5.0.37.tar.gz
cd /usr/local/zabbix/
tar -zxvf zabbix-5.0.37.tar.gz
cd zabbix-5.0.37
yum -y install pcre*
./configure --prefix=/usr/local/zabbix --enable-agent
make install
#在之前配置源的步骤中使用 --prefix 键,例如 --prefix=/usr/local/zabbix。在这种情况下,守护程序二进制文件将安装在 <prefix>/sbin 下,而实用程序则安装在 <prefix>/bin 下,手册页将安装在 <prefix>/share 下。
#配置文件在Configuration file: <prefix>/etc/zabbix_agentd.conf
vim /usr/local/zabbix/etc/zabbix_agentd.conf
Server="zabbixserver ip"
#ServerActive="zabbixserver ip"
#Hostname="zabbixserver name"
#启动zabbix agent
/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf
c.被监控端防火墙配置
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
cd /usr/lib/firewalld/services
#创建zabbix-agent.xml
vim zabbix-agent.xml
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>Zabbix Agent</short>
<description>Zabbix is a mature and effortless enterprise-class open source monitoring solution for network monitoring and application monitoring of millions of metrics.</description>
<port protocol="tcp" port="10050"/>
</service>
firewall-cmd --permanent --zone=public --add-service=zabbix-agent
firewall-cmd --reload
#查看firewall服务状态
systemctl status firewalld
关于firewall,参考CentOS 7 firewalld 配置详解
#查看防火墙所有区域的设置,包括添加的端口和服务如果要查某区域,加参数--zone=XX
firewall-cmd --list-all
#显示public区域详情
firewall-cmd --zone=public --list-all
#列出全部区域启用的特性
firewall-cmd --list-all-zones
#显示默认区域开启的服务,如果要查某区域,加参数--zone=XX
firewall-cmd --list-services
#firewalld默认配置文件有两个:
/usr/lib/firewalld/
#(系统配置,尽量不要修改)
/etc/firewalld/
#(用户配置地址)
#firewall服务文件保存位置
/usr/lib/firewalld/services/
#注意!!!!!请勿编辑/usr/lib/firewalld/services/ ,只有/etc/firewalld/services的文件可以被编辑。
/etc/firewalld/services
#firewalld将网卡对应到不同的区域(zone),zone 默认共有9个
block dmz drop external home internal public trusted work.
#不同的区域之间的差异是其对待数据包的默认行为不同,根据区域名字我们可以很直观的知道该区域的特征,在CentOS7系统中,默认区域被设置为public.
firewall-cmd --get-default-zone
#默认提供了九个zone配置文件:block.xml、dmz.xml、drop.xml、external.xml、 home.xml、internal.xml、public.xml、trusted.xml、work.xml。他们都保存在“/usr/lib/firewalld/zones/”目录下。默认情况下,在/etc/firewalld/zones下面只有一个public.xml。
/etc/firewalld/zones/public.xml
#如果给另外一个zone做一些改动,并永久保存,那么会自动生成对应的配置文件。比如给work zone增加一个端口:
firewall-cmd --permanent --zone=work --add-port=1000/tcp
#此时就会生成一个work.xml的配置文件
#打开或移除一个服务,类似于将端口可视化,服务需要在配置文件中添加,/etc/firewalld 目录下有services文件
firewall-cmd --zone=public --add-service=smtp
firewall-cmd --zone=public --remove-service=smtp
#重启加载防火墙(以 root 身份输入以下命令,重新加载防火墙,并不中断用户连接,即不丢失状态信息:)
firewall-cmd --reload
#完全重启防火墙 (以 root 身份输入以下命令,重新加载防火墙并中断用户连接,即丢弃状态信息:)
firewall-cmd --complete-reload
#注意:通常在防火墙出现严重问题时,这个命令才会被使用。比如,防火墙规则是正确的,但却出现状态信息问题和无法建立连接。
#firewall-cmd --reload与firewall-cmd --complete-reload两者的区别就是:
#第一个无需断开连接,就是firewalld特性之一动态添加规则,第二个需要断开连接,类似重启服务
#假如你服务器的ftp不使用默认端口,默认ftp的端口21改为1121,但想通过服务的方式操作防火墙。
#复制模版到/etc,以便修改和调用
cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services/
#修改模版配置
vim /etc/firewalld/services/ftp.xml
#把21改为1121
vim /etc/firewalld/zones/public.xml
#public为默认zone,所以要编辑这个,增加一行,以下内容
<service name="ftp"/>
#重新加载防火墙配置
firewall-cmd --reload
d.配置开机自启动服务
#创建服务
vim /usr/lib/systemd/system/zabbix-agentd.service
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-agent
Restart=on-failure
PIDFile=/tmp/zabbix_agentd.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix
[Install]
WantedBy=multi-user.target
#加载服务
systemctl daemon-reload
systemctl list-units -t service --all | grep zabbix-agent
systemctl enable zabbix-agentd.service
systemctl start zabbix-agentd.service
systemctl status zabbix-agentd.service
关于systemd,参考《一篇搞懂》系列之三——systemd
#默认管理服务的脚本文件保存在
/usr/lib/systemd/system/
#管理服务的Target保存在
/etc/systemd/system/
#编写XX Service Unit在服务管理路径
vim /usr/lib/systemd/system/XX.service
[Unit]
Description=My Simple HTTP Service
[Service]
ExecStart=/usr/bin/python -m SimpleHTTPServer 8888
Restart=on-failure
[Install]
WantedBy=multi-user.target
#说明:
Unit -- Description:这个Unit的描述:My Simple HTTP Service
Service -- ExecStart:这个Service的启动命令:直接利用python命令自带的SimpleHTTPServer模块启动一个8888端口的HTTP服务。
Service -- Restart:这个Service的重启策略:当服务出错时自动重启。
Install -- WantedBy:这个Unit被哪些Units所依赖:被multi-user.target依赖,也就是说,系统以联网多用户模式启动时,我们自定义的服务会先于multi-user.target就绪,即开机自启。
把这个文件以/usr/lib/systemd/system/simplehttp.service路径保存起来。
#需加载服务
systemctl daemon-reload
#查看systemd是否读
systemctl list-units -t service --all | grep XX
/usr/lib/systemd/system

浙公网安备 33010602011771号