Linux一键安装Zabbix5.0脚本

linux版本:CentOS-7-x86_64-DVD-1908


#!/bin/bash
# Zabbix-Server  5.0

#关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service

#禁用SELINUX
setenforce 0

#安装zabbix源、修改为aliyun源
cd /etc/yum.repos.d/
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
sed -i.bak 's#repo.zabbix.com#mirrors.aliyun.com/zabbix#' zabbix.repo
sed -i 's#enabled=0#enabled=1#' zabbix.repo
yum clean all

#安装zabbix
yum -y install zabbix-server-mysql zabbix-agent
yum -y install centos-release-scl
yum -y install zabbix-web-mysql-scl zabbix-apache-conf-scl

#安装启动 mariadb数据库
yum -y install mariadb mariadb-server httpd
systemctl start mariadb.service

#创建数据库
mysql -e 'create database zabbix character set utf8 collate utf8_bin;'
mysql -e 'create user zabbix@localhost identified by "zabbix"' 
mysql -e 'grant all privileges on zabbix.* to zabbix@localhost;'
mysql -e 'flush privileges;'

#导入数据
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -pzabbix -Dzabbix 

#为Zabbix server配置数据库
sed -i.bak '/^# DBPassword=*/i DBPassword=zabbix' /etc/zabbix/zabbix_server.conf

#添加时区
sed -i.bak '/^; php_value[date.timezone]*/i php_value[date.timezone] = Asia/Shanghai' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf

#解决中文乱码
yum -y install wqy-microhei-fonts
\cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf

#开机自启动
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm

#输出信息
echo "浏览器访问 http://`hostname -I|awk '{print $1}'`/zabbix"

# 查看zabbix错误日志
# cat /var/log/zabbix/zabbix_server.log
  • 保存为Zabbix.sh,再运行命令:sh Zabbix.sh
  • 或者直接复制粘贴到linux中

image001.png
  • 点击Next Step到如下位置


    image004.png
  • 数据库名,账户密码都填zabbix
  • 继续Next Step,没有问题的话应该到了登录界面,如下:


    image009.png

    *账户默认是Admin(首字母大写),密码是zabbix


安装后重新服务器之后可能会出现无法访问的问题,是由于重启后防火墙,LINUXSE重新开启导致的。将以下命令保存为xxx.sh,设置为开机自启动即可。

# setenforce 0
# systemctl stop firewalld.service
# systemctl disable firewalld.service
# systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
# systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm

Zabbix-agent的安装

#!/bin/bash
#Zabbix-Agent  5.0
 
Zabbix_Service=176.114.12.94 #修改为自己的Ip地址
 
#安装zabbix源、aliyun YUM源
cd /etc/yum.repos.d/
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
sed -i.bak 's#repo.zabbix.com#mirrors.aliyun.com/zabbix#' zabbix.repo
sed -i 's#enabled=0#enabled=1#' zabbix.repo
yum clean all

#安装zabbix
yum -y install zabbix-agent
 
#修改配置文件
sed -i.bak "s/^Server=127.0.0.1/Server=$Zabbix_Service/" /etc/zabbix/zabbix_agentd.conf
sed -i "s/^ServerActive=127.0.0.1/ServerActive=$Zabbix_Service/" /etc/zabbix/zabbix_agentd.conf
sed -i "/^Hostname=/c Hostname=$(echo `hostname`)" /etc/zabbix/zabbix_agentd.conf
 
#开启zabbix-agent服务 10050 端口
systemctl start zabbix-agent
 
#设置开机自启
systemctl enable zabbix-agent
 
#输出提示
echo -e "Now you can use \033[32mnetstat -tnlp\033[0m check \033[33mport:10050\033[0m"

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容