环境:centos7.9
网络:外网通
其他:无
两个脚本任选一执行即可
基于nginx,脚本如下:
#!/bin/bash#function:zabbix#author:tommypeng 20220727#####root判断#####if [ "$USER" != "root" ]then echo "错误:非root用户,权限不足!" exit 0fi###############防火墙及SElinux############systemctl stop firewalld && systemctl disable firewalld && echo "防火墙已经关闭"sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config && echo "关闭selinux"###########清理旧版本###########rpm -qa | grep mariadb > /root/888.txtrpm -qa | grep mysql >> /root/888.txtPLIST=$(cat /root/888.txt)for PKGNAME in $PLISTdo rpm -e --nodeps $PKGNAME && echo "老旧包已经清理完毕" donerm -rf /root/888.txt && echo "临时文件已删除"sleep 8##############网络测试##############ping -c 3 www.baidu.comif [ $? = 0 ] then echo "外网通讯良好!" else echo "丫的你在逗我吗?网都没有安装个毛线!" exit 1fi###########安装MDB##############yum -y install mariadb mariadb-server #安装mariadbif [ $? = 0 ] then echo "MDB安装成功!" else echo "MDB安装失败,即将退出!" exit 1fisystemctl start mariadb && systemctl enable mariadb###########php############yum install -y php php-mysqlif [ $? = 0 ] then echo "php安装成功!" else echo "php安装失败,即将退出!" exit 1fi##########php配置###########sed -i '384s/30/300/' /etc/php.inised -i '394s/60/300/' /etc/php.inised -i '672s/8/16/' /etc/php.inised -i '878adate.timezone = Asia/Shanghai' /etc/php.ini###########zabbix仓库#########rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpmif [ $? = 0 ] then echo "zabbix仓库安装成功!" else echo "zabbix仓库安装失败,即将退出!" exit 1fi###########zabbix安装###########yum install -y zabbix-server-mysql zabbix-get zabbix-web zabbix-web-mysql zabbix-agent zabbix-senderif [ $? = 0 ] then echo "zabbix安装成功!" else echo "zabbix安装失败,即将退出!" exit 1fi############配置数据库##########echo "create database zabbix character set utf8 collate utf8_bin;" |mysqlmysql -e "grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix';"mysql -e "flush privileges;"sleep 4cd /usr/share/doc/zabbix-server-mysql-3.4.15/ && gunzip create.sql.gzmysql -e "use zabbix;source create.sql;"sleep 5############配置zabbix############sed -i '91s/#/ /' /etc/zabbix/zabbix_server.confsed -i '124aDBPassword=zabbix' /etc/zabbix/zabbix_server.confsleep 3systemctl start zabbix-server.service &&systemctl enable zabbix-server.service ##########安装nginx###########yum -y install yum-utilscat >> /etc/yum.repos.d/nginx.repo <> /etc/nginx/conf.d/default.conf << EOF location = /favicon.ico { log_not_found off; access_log off; }EOFsystemctl start nginx && systemctl enable nginxsystemctl start php-fpm && systemctl enable php-fpm###########图形界面设置##########IP=$(ip a | grep "inet "|grep "ens33" | awk '{print $2}'| awk -F / '{print $1}')echo "使用浏览器访问http://$IP/zabbix/setup.php"echo " zabbix服务web登录账号为:Admin 密码为zabbix zabbix服务配套数据库账号和密码均为:zabbix "
基于apache,脚本如下(由我的学生尹斌同学提供,表扬):
#!/bin/bash#function:zabbix#author:yinbin 20220727if [ $(id -u) -ne 0 ];thenecho -e "必须以root用户运行本脚本"exit 1fisystemctl stop firewalld.service &&systemctl disable firewalld.service &&systemctl status firewalld &> /dev/nullsed -i '/SELINUX/{s/enforcing/disabled/}' /etc/selinux/config echo "防火墙等配置已关闭"echo "正在安装zabbix_repo源..."rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpmif [ $? -eq 0 ];thenecho "zabbix 源安装完毕"fiyum -y install epel-release if [ $? -eq 0 ];thenecho "epel扩展源安装完成"fiecho "正在安装zabbix...."yum install zabbix-server-mysql zabbix-web-mysql -y if [ $? -eq 0 ];thenecho "zabbix-server安装完成"fiecho "正在安装数据库.."yum install mariadb-server mariadb -ysystemctl start mariadb && systemctl enable mariadb if [ $? -eq 0 ];thenecho "数据库启动成功"fiecho "正在执行mysql语句,创建zabbix数据库,授权zabbix访问数据库"mysql -e "create database zabbix character set utf8;grant all privileges on zabbix.* to zabbix@'localhost' identified by 'zabbix';grant all privileges on zabbix.* to zabbix@'127.0.0.1' identified by 'zabbix';flush privileges;"if [ $? -eq 0 ];thenecho "数据库初始化完成"fizcat /usr/share/doc/zabbix-server-mysql-3.4.15/create.sql.gz | mysql -uzabbix -pzabbix zabbix if [ $? -eq 0 ];thenecho "数据导入完成"fi echo "正在配置zabbix配置文件...."cd /etc/zabbixsed -i '/# DBHost=localhost/a\DBHost=localhost' zabbix_server.conf sed -i '/# DBPassword=/a\DBPassword=zabbix' zabbix_server.conf if [ $? -eq 0 ];then echo "zabbix配置完毕!"fisystemctl start zabbix-server && systemctl enable zabbix-server &> /dev/nullif [ $? -eq 0 ];thenecho "zabbix-server 服务已经启动"fiecho "正在进行最后的zabbix Install ,php参数修改....."sed -i '/^;date.timezone/a\date.timezone = Asia/Shanghai' /etc/php.ini &> /dev/nullsystemctl start httpd && systemctl enable httpd &> /dev/nullif [ $? -eq 0 ];thenecho "Apache 服务已经启动"fi ######################################################## IP=$(ip a | grep "inet "|grep "ens33" | awk '{print $2}'| awk -F / '{print $1}')echo "Zabbix服务部署完成,请在游览器输入http://$IP/zabbix进行访问"echo "Zabbix 账号密码都为zabbix"echo "zabbix服务web登录账号为:Admin 密码为zabbix"
来源地址:https://blog.csdn.net/qq_28608175/article/details/126019973