zabbix 服务端一键安装脚本
#!/bin/bash
#Zabbix-Server 5.0
#mariadb 10.5
#set -eou
trap "on_ERR;" ERR
on_ERR() {
local ret=$? cmd="$BASH_COMMAND" f="${BASH_SOURCE:--}" lino="${BASH_LINENO[0]}"
printf >&2 "ERROR: %s:%s: \033[7m%s\033[0m exit with code %s.\n" "$f" "$lino" "$cmd" "$ret"
echo ""
echo -e "\033[41;37m 请检查报错信息,确认是否终止安装,y/n \033[0m"
read -p : i
case $i in
y)
exit "$ret"
;;
n)
echo "继续执行"
;;
*)
echo "请输入 y或n"
;;
esac
}
#安装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
#添加Maria源
cat <<EOF > /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/10.5/centos7-amd64/
gpgkey = https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1
EOF
#清除并重建yum缓存
yum clean all
yum makecache
#安装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 'grant all privileges on zabbix.* to zabbix@localhost identified by "Blueking@2023";'
mysql -e 'flush privileges;'
#导入数据
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz|mysql -uzabbix -pBlueking@2023 -Dzabbix
#配置zabbixserver连接mysql
sed -i.bak '/^# DBPassword=*/i DBPassword=Blueking@2023' /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 mariadb.service
systemctl enable httpd
systemctl enable zabbix-server
#输出信息
echo "
mariadb zabix用户密码:Blueking@2023
"
echo "浏览器访问 http://`hostname -I|awk '{print $1}'`/zabbix"
![](https://img-blog.csdnimg.cn/img_convert/8adefdac019b4c7a52a5ec560d1314ff.png)
![](https://img-blog.csdnimg.cn/img_convert/96e84822102dffa7b0681e6cf85504da.png)
![](https://img-blog.csdnimg.cn/img_convert/b7717600cb1b557a1547ff2dad30b1e9.png)
![](https://img-blog.csdnimg.cn/img_convert/4ecf110e962d73252a7825c76a7eebc2.png)
![](https://img-blog.csdnimg.cn/img_convert/d4135205433235987037218be05c6f08.png)
修改界面语言
![](https://img-blog.csdnimg.cn/img_convert/c40dabd1379e4a06613be23cf8e58db3.png)
修改登录密码
![](https://img-blog.csdnimg.cn/img_convert/d9d4c60b811e1cdf6d0c93a865bd1f14.png)
zabbix客户端一键安装脚本
#!/bin/bash
#Zabbix-Agent 5.0
echo "请输入 Zabbix_Service_IP:"
read Zabbix_Service
if ! echo ${Zabbix_Service} | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}.[0-9]\{1,3\}\.[0-9]\{1,3\}' &> /dev/null;then
echo "ERROR:${Zabbix_Service}这不是一个合法的IP!!!" && exit
fi
#Zabbix_Service=192.168.63.20
#安装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
#安装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"