玩转zabbix之源码编译安装,添加主机监控

2020-09-04 17:05:56 浏览数 (1)

作者:老油条IT记 公众号:老油条IT记

详细安装过程

1.初始环境配置 #关闭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]# cat /etc/selinux/config |grep =disabled SELINUX=disabled

2.下载zabbix server源码包

wget https://cdn.zabbix.com/zabbix/sources/stable/4.0/zabbix-4.0.24.tar.gz

3.安装相关依赖包

yum install -y python-paramiko gcc gcc-c dejavu-sans-fonts python-setuptools python-devel sendmail mailx net-snmp net-snmp-devel net-snmp-utils freetype-devel libpng-devel perl unbound libtasn1-devel p11-kit-devel OpenIPMI unixODBC libevent-devel mysql-devel libxml2-devel libssh2-devel OpenIPMI-devel java-1.8.0-openjdk-devel openldap-devel curl-devel unixODBC-devel

4.添加用户组用户

groupadd --system zabbix useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix

5.创建存放目录和解压包

mkdir -p /data/zabbix tar -zxvf zabbix-4.0.4.tar.gz -C /data/zabbix cd /data/zabbix/zabbix-4.0.4/

6.编译安装

./configure --prefix=/data/zabbix --enable-server --enable-agent --enable-java --with-mysql --with-libxml2 --with-unixodbc --with-net-snmp --with-ssh2 --with-openipmi --with-ldap --with-libcurl --with-iconv make make install

安装完之后查看版本信息 /data/zabbix/sbin/zabbix_server -V

7.安装MySQL

wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm rpm -ivh mysql57-community-release-el7-7.noarch.rpm yum install mysql-community-server -y

安装完数据库是需要开启的,默认不开启

[root@zabbix ~]# systemctl start mysqld [root@zabbix ~]# cat /etc/my.cnf #设置密码复杂度 [mysqld] validate_password_policy=LOW [root@zabbix ~]# systemctl restart mysqld

8.创建数据库

#查找出临时密码 grep password /var/log/mysqld.log #登陆 mysql -uroot -p"xxx" #设置新密码 mysql> set password for root@localhost=password('guoke123'); #创建库 mysql>create database zabbix character set utf8 collate utf8_bin; #创建用户并授权 mysql>grant all privileges on zabbix.* to zabbix@localhost identified by 'guoke123'; mysql> flush privileges;

9.导入数据结构

mysql -uzabbix -pguoke123 zabbix < /data/zabbix/zabbix-4.0.24/database/mysql/schema.sql mysql -uzabbix -pguoke123 zabbix < /data/zabbix/zabbix-4.0.24/database/mysql/images.sql mysql -uzabbix -pguoke123 zabbix < /data/zabbix/zabbix-4.0.24/database/mysql/data.sql

10.修改zabbix server配置

vim /data/zabbix/etc/zabbix_server.conf DBPassword=guoke123

11.启动服务

/data/zabbix/sbin/zabbix_server -c /data/zabbix/etc/zabbix_server.conf #查看日志 tailf /tmp/zabbix_server.log

12.增加Zabbix镜像源

rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm

13.安装Zabbix Frontend

yum install zabbix-web-mysql -y

14.配置Zabbix frontend

vim /etc/php.ini #设置时区 date.timezone = Asia/Shanghai

15.启动httpd

systemctl restart httpd.service systemctl status httpd.service

16.访问

http://192.168.186.131/zabbix/setup.php

#填写zabbix用户的密码

#默认登录用户名和密码 Admin zabbix

添加主机监控

#安装zabbix-agent客户端,使用清华源

代码语言:javascript复制
rpm -ivh https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm  #官网

[root@game 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

#安装

[root@game]# yum install zabbix-agent -y

#配置连接服务器

#vim /etc/zabbix/zabbix_agentd.conf Server=192.168.86.137 ServerActive=192.168.86.137 Hostname=game #这里写的主机名和监控添加的要一样

#启动服务

[root@game]# systemctl restart zabbix-agent.service [root@game]# systemctl status zabbix-agent.service

#到前端页面添加监控主机

#关联模板,关联已有的OS Linux模板,已可以自己进行创建

#监控正常显示状态

0 人点赞