zabbix一键部署脚本----亲测可用

环境:centos7.9

网络:外网通

其他:无

两个脚本任选一执行即可

基于nginx,脚本如下:

#!/bin/bash
#function:zabbix
#author:tommypeng  20220727
#####root判断#####
if
  [  "$USER"  != "root"   ]
then
   echo "错误:非root用户,权限不足!"
  exit  0
fi
###############防火墙及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.txt
rpm -qa | grep mysql  >>  /root/888.txt
PLIST=$(cat  /root/888.txt)
for  PKGNAME   in    $PLIST
do
      rpm -e --nodeps   $PKGNAME   &&  echo  "老旧包已经清理完毕" 
done
rm -rf  /root/888.txt  &&  echo "临时文件已删除"
sleep 8
##############网络测试##############
ping   -c  3  www.baidu.com
if
  [ $? = 0 ]
  then
    echo "外网通讯良好!"
  else
    echo  "丫的你在逗我吗?网都没有安装个毛线!"
   exit  1
fi
###########安装MDB##############
yum -y install mariadb mariadb-server #安装mariadb
if
  [ $? = 0 ]
  then
    echo "MDB安装成功!"
  else
    echo  "MDB安装失败,即将退出!"
   exit  1
fi
systemctl start mariadb   &&  systemctl enable mariadb
###########php############
yum install -y php php-mysql
if
  [ $? = 0 ]
  then
    echo "php安装成功!"
  else
    echo  "php安装失败,即将退出!"
   exit  1
fi
##########php配置###########
sed -i '384s/30/300/'  /etc/php.ini
sed -i '394s/60/300/'  /etc/php.ini
sed -i '672s/8/16/'  /etc/php.ini
sed -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.rpm
if
  [ $? = 0 ]
  then
    echo "zabbix仓库安装成功!"
  else
    echo  "zabbix仓库安装失败,即将退出!"
   exit  1
fi
###########zabbix安装###########
yum install -y zabbix-server-mysql zabbix-get zabbix-web zabbix-web-mysql zabbix-agent zabbix-sender
if
  [ $? = 0 ]
  then
    echo "zabbix安装成功!"
  else
    echo  "zabbix安装失败,即将退出!"
   exit  1
fi
############配置数据库##########
echo  "create database zabbix character set utf8 collate utf8_bin;" |mysql
mysql -e "grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix';"
mysql -e "flush privileges;"
sleep  4
cd /usr/share/doc/zabbix-server-mysql-3.4.15/  &&  gunzip create.sql.gz
mysql -e "use zabbix;source create.sql;"
sleep 5
############配置zabbix############
sed -i  '91s/#/ /'    /etc/zabbix/zabbix_server.conf
sed  -i  '124aDBPassword=zabbix'  /etc/zabbix/zabbix_server.conf
sleep 3
systemctl  start zabbix-server.service   &&systemctl  enable zabbix-server.service 
##########安装nginx###########
yum -y install yum-utils
cat >> /etc/yum.repos.d/nginx.repo <>  /etc/nginx/conf.d/default.conf  << EOF
 location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
EOF
systemctl start nginx  &&  systemctl enable nginx
systemctl 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 20220727
if [  $(id -u)  -ne 0  ];then
	echo -e "必须以root用户运行本脚本"
	exit 1
fi



	systemctl stop firewalld.service &&
	systemctl disable firewalld.service &&
	systemctl status firewalld &> /dev/null
	sed -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.rpm
if [ $? -eq 0 ];then
	echo  "zabbix 源安装完毕"
fi
yum -y install epel-release 
if [ $? -eq 0 ];then
	echo  "epel扩展源安装完成"
fi
echo  "正在安装zabbix...."
yum install zabbix-server-mysql zabbix-web-mysql -y 
if [ $? -eq 0 ];then
	echo  "zabbix-server安装完成"
fi
echo  "正在安装数据库.."
yum install mariadb-server mariadb -y
systemctl start mariadb && systemctl enable mariadb 
if [ $? -eq 0 ];then
	echo  "数据库启动成功"
fi
echo "正在执行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 ];then
	echo  "数据库初始化完成"
fi
zcat /usr/share/doc/zabbix-server-mysql-3.4.15/create.sql.gz | mysql -uzabbix -pzabbix zabbix 
if [ $? -eq 0 ];then
	echo  "数据导入完成"
fi
 
echo  "正在配置zabbix配置文件...."
cd /etc/zabbix
sed -i '/# DBHost=localhost/a\DBHost=localhost' zabbix_server.conf 
sed -i '/# DBPassword=/a\DBPassword=zabbix' zabbix_server.conf  
if [ $? -eq 0 ];then
        echo  "zabbix配置完毕!"
fi
systemctl start zabbix-server && systemctl enable zabbix-server  &> /dev/null
if [ $? -eq 0 ];then
	echo  "zabbix-server 服务已经启动"
fi
echo  "正在进行最后的zabbix Install ,php参数修改....."
sed -i '/^;date.timezone/a\date.timezone =  Asia/Shanghai' /etc/php.ini  &> /dev/null
systemctl start httpd && systemctl enable httpd   &> /dev/null
if [ $? -eq 0 ];then
	echo  "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"

你可能感兴趣的:(php,开发语言,运维,centos,服务器)