执行操作前关闭selinux和firewalld
软件仓库的搭建
执行 rpm -Uvh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
会出现zabbix.repo
vim zabbix.repo
安装zabbix
yum install -y zabbix-server-mysql
安装数据库
yum install mariadb-server -y
systemctl enable --now mariadb
进入数据库:mysql
建立库:create database zabbix character set uft8 collate utf8_bin;
建立用户:create user ‘zabbix’@‘localhost’ identified by ‘westos’;
给予权限:grant all privileges on zabbix.* to ‘zabbix’@‘localhost’;
cd /usr/share/doc/zabbix-server-mysql-4.0.27/
zcat create.sql.gz | mysql -uzabbix -pwestos zabbix
cd /etc/zabbix/
vim zabbix_server.conf
开启zabbix
systemctl enable --now zabbix-server
yum install zabbix-agent -y
systemctl enable --now zabbix-agent
yum install zabbix-web-mysql -y 此时会有错误,原因是因为依赖性,安装php-bcmath和php-mbstring即可(注意版本应安装5.4.16-46)
在阿里云官网上进行下载php-bcmath-5.4.16-46.el7.x86_64.rpm php-mbstring-5.4.16-46.el7.x86_64.rpm
yum install -y zabbix-web-mysql php-bcmath-5.4.16-46.el7.x86_64.rpm php-mbstring-5.4.16-46.el7.x86_64.rpm
安装好之后可以用yun repolist查看
cd /etc/httpd/conf.d
vim zabbix.conf
修改时区:php_value date.timezone Asia/Shanghai
systemctl enable --now httpd
此时在网页中访问172.25.18.1/zabbix就可以看到前端
点击next step 添加密码westos
点击next step 添加名字Zabbix server
用用户Admin密码zabbix登陆
切换中文
此时会看到一些乱码
下载中文简体即可(在172.25.0.250/pub/docs/zabbix中下载simkai.ttf或者在百度上直接下载simkai.ttf(要下载在/usr/share/zabbix/assets/fonts目录下))
vim /usr/share/zabbix/include/defines.inc.php
%s/graphfont/simkai/g
此时就恢复了正常
在server2中
将server1中的软件仓库发送到server2中
yum install -y zabbix-agent
cd /etc/zabbix
vim zabbix_agentd.conf
修改以下内容
Server=172.25.254.1
ServerActive=172.25.254.1
Hostname=server2
systemctl enable --now zabbix-agent
此时查看日志发现没有连接
这时候需要添加server2
手动添加
但是此时可以看到没有监控项等
添加模板即可
选择后一定要点击添加,只有添加后才能生效
此时就添加完成
这是会发现多了一个模板
这是因为模板之间的依赖性
自动发现
在server3中
yum install zabbix-agent -y
cd /etc/zabbix/
vim zabbix_agentd.conf
systemctl enable --now zabbix-agent
此时查看日志可以看到没有找到
添加
此时可以看到server3被添加成功
自动注册
此时在server3中systemctl restart zabbix-agent就可以看到server3
API
获取令牌
检索主机
vim zabbix.api
sh zabbix.api
删除主机server3
vim zabbix.api
sh zabbix.api
此时server3已经被删除
建立主机
vim zabbix.api
sh zabbix.api
此时看到server3被建立
监控服务
在server2上
开启httpd服务
systemctl enable --now httpd
在/var/www/html下生成文件
echo server2 > index.html
此时访问本机可以得到server2
添加http模板
此时就可以监控http服务是否开启
监控nginx
在server上
解压nginx包
安装依赖性
cd nginx-1.18.0/
vim auto/cc/gcc
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd /usr/local/nginx/sbin
作软链接
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
cd /usr/local/nginx/conf
添加监控
vim nginx.conf
检测语法并开启nginx
访问本机
此时访问本机会被记录
在真实主机上测试,访问1000次server3下的index.html
在server3上可以检测到访问次数
cd /etc/zabbix/zabbix_agentd.d/
cp userparameter_mysql.conf userparameter_nginx.conf
vim userparameter_nginx.conf
重启服务
systemctl restart zabbix-agent.service
在server1上
yum install zabbix-get -y
此时在server1上就可以取到server3上nginx.active的值
让其出现在前端
添加成功