扩展cat e.txt | awk ‘NR==2{print $1}’
-------开始--------
关闭防火墙:
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
systemctl disable --now firewalld
获取zabbix下载源:
rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
ls /etc/yum.repos.d/
vi /etc/yum.repos.d/zabbix.repo #查看
更换源:
sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
清空缓存下载zabbix服务端:
yum clean all
yum makecache
yum install zabbix-server-mysql zabbix-agent -y
安装工具,可以在机器上使用多个版本软件斌不会影响到整个系统的依赖环境:
yum install centos-release-scl -y
修改zabbix-front前端源,修改如下参数:
vim /etc/yum.repos.d/zabbix.repo
[zabbix-frontend]
enabled=1 #由0改为1
安装zabbix前端环境,且是安装到scl环境下:
yum install zabbix-web-mysql-scl zabbix-apache-conf-scl -y
安装zabbix所需数据库:
yum install mariadb-server -y
配置数据库开机启动:
systemctl enable --now mariadb
初始化数据库:chaoge666
mysql_secure_installation
添加数据库用户以及zabbix所需的数据库信息:
#进入数据库
create database zabbix character set utf8 collate utf8_bin;
create user zabbix@localhost identified by 'chaoge666';
grant all privileges on zabbix.* to zabbix@localhost;
#退出数据库
使用zabbix-mysql命令,导入数据库信息:
#mysql -u用户名 -p 数据库名 密码
zcat /usr/share/doc/zabbix-server-mysql-5.0.37/create.sql.gz | mysql -uzabbix -p zabbix
修改zabbix server配置文件,修改数据库密码
vim /etc/zabbix/zabbix_server.conf
DBPassword=chaoge666 #搜索DBPassword更改
grep '^DBPa' /etc/zabbix/zabbix_server.conf
修改zabbix的php配置文件:
vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
#修改为php_value[date.timezone] = Asia/Shanghai
#且去掉注释符号
grep 'timezone' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
启动zabbix相关服务:
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
服务端安装完成!
部署客户端--------
注意时间:(服务端也要)
yum install ntpdate -y
ntpdate -u ntp.aliyun.com
时区统一配置:(服务端也要)
mv /etc/localtime{,.bak}
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
zabbix-agent2部署流程:
#配置zabbix的yum源(原服务机有配,现在这个新客户机没配)
rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
sed -i 's#http://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
yum install zabbix-agent2 -y
查看配置文件:
vim /etc/zabbix/zabbix_agent2.conf
查看启动命令:
ll /usr/sbin/zabbix_agent2
启动客户端:
systemctl enable zabbix-agent2 --now
修改agent2配置文件,查看配置信息:
grep -Ev '^#|^$' /etc/zabbix/zabbix_agent2.conf
命令意思问:查找并显示配置文件中所有不是注释或非空行的内容
# 排除#和$开头的行,-E使用扩展正则表达式,-v选择不匹配模式的行
# ^#|^$ 是一个正则表达式,表示以 # 或 $ 字符开头
重启zabbix-agent2:
systemctl restart zabbix-agent2
验证zabbix-agent2的连通性:
1.服务端139主动获取数据:
首先在服务端装一个客户端的命令:(主动去客户端拿数据)
yum install zabbix-get -y
zabbix_get -s '192.168.236.136' -p 10050 -k 'agent.ping'
zabbix_get -s '192.168.236.136' -p 10050 -k 'system.hostname'
解决zabbix-server图形查看的乱码问题问题:
安装字体
yum -y install wqy-microhei-fonts
复制字体:
\cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf