期末zabbix
本次实验需要两台虚拟机
服务机IP是192.168.18.137
客户机IP是192.168.18.237
关于这篇实验,书上第七章的顺序和代码都是对的,我推荐你看着书上的顺序,然后直接从本文复制代码粘贴到虚拟机运行即可
1.服务机安装LAMP
换源
wget -P /etc/yum.repos.d http://mirrors.aliyun.com/repo/Centos-7.repo
下载四个服务
yum -y install mariadb mariadb-server php php-mysql httpd
出现进程被占用无法下载,先用这个命令,再yum下载
rm -f /var/run/yum.pid
设置防火墙和SELINUX权限
firewall-cmd --zone=public --add-port=80/tcp --permanent
重启防火墙
firewall-cmd --reload
出现success则正确
启动Apache
systemctl start httpd
systemctl enable httpd
在火狐浏览器输入自己的虚拟机网址出来本页面则成功
启动mariadb数据库
systemctl enable mariadb
systemctl start mariadb
初始化数据库
mysql_secure_installation
这里的配置照着书P278配置,把自己的用户名和密码记住!
mysql -uroot -p123456 -e "create database zabbix default character set utf8 collate utf8_bin;"
这里-u后面是自己的用户名,-p后面是自己的密码
我的用户名为root,密码是123456
-e后面是sql语句,照打
出现
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
要么是u后面的用户名不对,要么是p后面的密码不对
创建新用户zabbix并更改密码
useradd zabbix
passwd zabbix
富裕zabbix以root权限
mysql -uroot -p123456 -e "grant all on zabbix.* to 'zabbix'@'%' identified by 'zabbix';"
测试zabbix用户登录
mysql -uzabbix -p123456
输入命令
show databases; //后面有个分号;看清楚
能看到数据库信息则成功!
2.服务机安装Server端
一、下载3.4.1 rpm
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm
二、服务端安装
yum install zabbix-server-mysql zabbix-web-mysql zabbix-get
红框里面显示下载版本为3.4.15,记住它
三、配置mariadb数据库
1.导入表结构
cd /usr/share/doc/zabbix-server-mysql-3.4.15/
zcat create.sql.gz | mysql -uroot -p123456 zabbix
2.修改配置zabbix_server.conf
vim /etc/zabbix/zabbix_server.conf
DBHost=localhost #去掉前面#
DBName=zabbix #不需要修改
DBUser=zabbix #zabbix修改成自己的用户名
DBPassword=zabbix #去掉前面#,并修改数据库密码
3.修改配置文件zabbix.conf
vim /etc/httpd/conf.d/zabbix.conf
php_value date.timezone Asia/shanghai #修改时区
4.开启
systemctl start zabbix-server
systemctl enable zabbix-server
5.重启Apache
systemctl restart httpd
6.安装
打开火狐浏览器,输入网址http://192.168.18.137/zabbix/setup.php
得到如图所示页面则配置正确
看书P284-P287安装
到登录界面,所有人的登录名和密码都一样
用户名为:Admin
密码为:zabbix
若能登录进去,则至此server配置完成
3.服务端配置Agent
我的服务机IP是192.168.18.137
1.下载agent
yum -y install zabbix-agent
修改配置(服务器三个IP都是配置服务器的IP!)
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.18.137
.....
ServerActive=192.168.18.137
.....
Hostname=192.168.18.137
2.关闭防火墙和SELINUX
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
这时如果输入
systemctl start zabbix-agent
能够启动则直接用3.zabbix-get测试
若启动失败,重启虚拟机
再启动agent
systemctl start zabbix-agent
systemctl enable zabbix-agent
查看状态
systemctl status zabbix-agent
systemctl status zabbix-server
都是绿色即可
3.使用zabbix-get测试
使用zabbix-get返回操作系统名称
zabbix_get -s 192.168.18.137 -k system.uname
获取主机15分钟内的平均负载
zabbix_get -s 192.168.18.137 -k system.cpu.load[all,avg15
成功返回参数则安装成功!
4.客户端配置Agent
用另外一台虚拟机配!
先把IP配完!我的客户机IP是192.168.18.237
关闭防火墙和selinux
systemctl stop firewalld.service
systemctl disable firewalld.service
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
grep SELINUX=disabled /etc/selinux/config
setenforce 0
换源
wget -P /etc/yum.repos.d http://mirrors.aliyun.com/repo/Centos-7.repo
下载3.4.1 rpm
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm
yum -y install mariadb mariadb-server php php-mysql httpd
systemctl start httpd
systemctl enable httpd
下载agent
yum -y install zabbix-agent
修改内容
[root@localhost ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.18.137
.....
ServerActive=192.168.18.137
.....
Hostname=192.168.18.237 #这里换成客户机的IP!
启动agent
systemctl start zabbix-agent
systemctl enable zabbix-agent
不出错则配置成功!
剩下的东西视频讲的很全面,照着视频完善即可。