作者:老油条IT记 公众号:老油条IT记
#1.初始配置
#centos7添加阿里云镜像
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#安装epel源
yum install epel-release -y
#关闭iptables
systemctl stop firewalld.service
systemctl disable firewalld.service
#关闭selinux
#在线设置
[root@zabbix ~]# setenforce 0
#修改配置文件方式,需要系统才能生效
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@zabbix yum.repos.d]# cat /etc/selinux/config |grep =disabled
SELINUX=disabled
#安装常用的开发组件
yum groups install "Development Tools" -y
yum groups info "Development Tools" -y #查看安装开发组件相关包
#2.安装zabbix
#增加Zabbix镜像源
wget https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
#安装,官网的地址
rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
#如果官网的下载有问题,可以替换官网的地址为清华源的
[root@zabbix yum.repos.d]# cat zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=0
#替换两处地方,vim替换方法:%s###g
:%s#gpgcheck=1#gpgcheck=0#g
:%s#repo.zabbix.....#https://mirrors.tuna.tsinghua.edu.cn/zabbix/#g
#安装Zabbix Server服务端和zabbix-web前端
yum install zabbix-server-mysql -y
yum install zabbix-web-mysql -y
#提示:数据库有mysql和pgsql
[root@zabbix yum.repos.d]# rpm -qa zabbix-server-mysql
zabbix-server-mysql-4.0.21-2.el7.x86_64
[root@zabbix yum.repos.d]# rpm -qa zabbix-web-mysql
zabbix-web-mysql-4.0.21-2.el7.noarch
#列出相关配置文件
[root@zabbix yum.repos.d]# rpm -ql zabbix-server-mysql
/etc/logrotate.d/zabbix-server
/etc/zabbix/zabbix_server.conf
......
#3.安装mysql
#提示:可以rpm安装,可以编译安装
#编译安装可参考自己写的博客:https://www.cnblogs.com/guoke-boy/p/12431850.html
wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm #下载rpm包
#rpm -qpl mysql57-community-release-el7-7.noarch.rpm
rpm -ivh mysql57-community-release-el7-7.noarch.rpm
yum install mysql-community-server -y #安装MySQL
#安装完数据库是需要开启的,默认不开启
[root@zabbix ~]# systemctl start mysqld
#设置密码复杂度
[root@zabbix ~]# cat /etc/my.cnf
[mysqld]
validate_password_policy=LOW
[root@zabbix ~]# systemctl restart mysqld
[root@zabbix ~]# grep password /var/log/mysqld.log #找出密码
2020-06-13T03:50:58.807080Z 1 [Note] A temporary password is generated for root@localhost: c:kQvcj*3B)e
[root@zabbix ~]# mysql -uroot -p"c:kQvcj*3B)e" #进行登录
#设置新密码
mysql> set password for root@localhost=password('guoke123');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> create database zabbix character set utf8 collate utf8_bin; #创建库
Query OK, 1 row affected (0.00 sec)
#创建管理用户
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'guoke123';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges; #刷新
Query OK, 0 rows affected (0.00 sec)
#导入数据结构
[root@zabbix ~]# zcat /usr/share/doc/zabbix-server-mysql-4.0.21/create.sql.gz | mysql -uzabbix -p"guoke123" zabbix
#4.配置zabbix
#配置Zabbix Serve
vim /etc/zabbix/zabbix_server.conf
DBPassword=guoke123
#启动Zabbix Server
systemctl restart zabbix-server.service
systemctl status zabbix-server.service
#查看日志
more /var/log/zabbix/zabbix_server.log
#设置时区
配置Zabbix frontend
#vim /etc/php.ini
max_execution_time = 300
post_max_size = 16M
max_input_time = 300
max_input_vars = 10000
always_populate_raw_post_data = -1
date.timezone = Asia/Shanghai
#启动http服务
systemctl restart httpd.service
systemctl status httpd.service
#5.访问 http://192.168.86.137/zabbix
#设置用户密码
#默认登录用户名和密码 Admin zabbix
#zabbix server自己作为客户端监控本机
[root@zabbix yum.repos.d]# yum install zabbix-agent.x86_64 -y [root@zabbix ~]# systemctl start zabbix-agent.service #启动 #查看监听端口 [root@zabbix ~]# netstat -untpl |grep 10050 tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 40392/zabbix_agentd tcp6 0 0 :::10050 :::* LISTEN 40392/zabbix_agentd
#查看效果