对于运维人员来说,监控是非常重要的,因为如果想要保证线上业务整体能够稳定运行,那么我们则需要实时关注与其相关的各项指标是否正常,而一个业务系统的背后,往往存在着很多的服务器、网络设备等硬件资源,如果我们想要能够更加方便的、集中的监控他们,我们则需要依靠一些外部的工具,而zabbix就是一个被广泛使用的,可以实现集中监控管理的应用程序。
优化Centos
换相关源
Base源
该文件夹只提供 CentOS 7 与 8,架构仅为 x86_64
。
建议先备份 /etc/yum.repos.d/
内的文件(CentOS 7 及之前为 CentOS-Base.repo
,CentOS 8 为CentOS-Linux-*.repo
)
然后编辑 /etc/yum.repos.d/
中的相应文件,在 mirrorlist=
开头行前面加 #
注释掉;并将 baseurl=
开头行取消注释(如果被注释的话),把该行内的域名(例如mirror.centos.org
)替换为 mirrors.tuna.tsinghua.edu.cn
。
以上步骤可以被下方的命令一步完成
sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo
注意其中的*
通配符,如果只需要替换一些文件中的源,请自行增删。
注意,如果需要启用其中一些 repo,需要将其中的 enabled=0
改为 enabled=1
。
Epel源
yum -y install epel-release
Zabbix源
vim /etc/yum.repos.d/zabbix.repo
[zabbix]
name=zabbix
baseurl=https://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/
gpgcheck=0
enabled=1
yum -y install http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
清除仓库缓存
yum clean all
最后,更新软件包缓存
yum makecache
关闭SeLinux
vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing ##改为disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
关闭防火墙
systemctl stop firewalld; systemctl disable firewalld
开始安装
安装Zabbix Server
yum install zabbix-server-mysql zabbix-get -y
出现报错请查看优化Centos
目录的换源
安装完成上述两个包以后,server即为安装完成,是不是很简单,server端的相关配置我们一会儿再进行。
初始化Zabbix Database
安装并且启动MariaDB
yum install -y mariadb mariadb-server
systemctl enable mariadb;systemctl start mariadb
在/ sr/share/doc/zabbix-server-mysql-3.0.32/
可以看到一个create.sql.gz的包,解压此包即可获得初始化SQL脚本。
cd /usr/share/doc/zabbix-server-mysql-3.0.32/
gunzip create.sql.gz
手动创建Zabbix的数据库
mysql -uroot
create database zabbix charset 'utf8';
grant all on zabbix.* to zabbix@localhost identified by '123123';
flush privileges;
执行对应的SQL初始化脚本
mysql -uzabbix -p -Dzabbix < /usr/share/doc/zabbix-server-mysql-3.0.32/create.sql
查看Zabbix数据库,发现对应的表已经生成
配置Zabbix Server端
Server端已经安装完毕,并且数据库也已经初始化,现在我们开始配置Server端,编辑Zabbix Server端的配置文件。
vim /etc/zabbix/zabbix_server.conf
关键字
ListenPort=10051
SourceIP=
LogType=file
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
DebugLevel=3
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123123
DBSocket=/var/lib/mysql/mysql.sock
DBPort=3306
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
Period=45
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
启动Zabbix服务端
systemctl start zabbix-server.service
ss -tnl
Zabbix Server已经启动,剩下的就是初始化Zabbix设置了;
安装Zabbix Web
lamp环境
yum install httpd php php-mysql php-mbstring php-gd php-bcmath php-ldap php-xml -y
Zabbix Web
yum install zabbix-web zabbix-web-mysql -y
配置httpd
vim /etc/httpd/conf.d/zabbix.conf
<VirtualHost 192.168.145.158:80>
servername 192.168.145.158
documentroot /usr/Share/zabbix
Alias /zabbix /usr/share/zabbix
<Directory "/usr/share/zabbix">
Options FollowSymLinks
AllowOverride None
Require all granted
<IfModule mod_php5.c>
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value max_input_vars 10000
php_value always_populate_raw_post_data -1
php_value date.timezone Asia/Shanghai
# php_value date.timezone Europe/Riga
</IfModule>
</Directory>
<Directory "/usr/share/zabbix/conf">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/app">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/include">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/local">
Require all denied
</Directory>
</VirtualHost>
配置完成后,启动httpd服务;
systemctl start httpd.service
初始化Zabbix 配置
访问192.168.145.158/zabbix
从提示可以看出,初始化配置已经完成;初始化已经完成,点击结束即可。
默认的管理员用户为admin,密码为zabbix
设置中文
修改管理员密码
安装Zabbix Agent
在被监控主机上安装zabbix-agent zabbix-sender
yum install -y zabbix-agent zabbix-sender
vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.145.158
ServerActive=192.168.145.158
Hostname=192.168.145.157
systemctl start zabbix-agent.service
agent端已经安装完毕
2 comments
需要两台虚拟机?
你可以把Docker的两台用来做这个,不影响