debian11-zabbix6.0一键安装脚本:
#!/bin/sh
process()
{
install_date="zabbix_install_$(date +%Y-%m-%d_%H:%M:%S).log"
printf "
#######################################################################
# 欢迎使用Zabbix一键部署脚本 #
# 脚本适配环境debian11、内存2G+ #
# #
#######################################################################
"
while :; do echo
read -p "请输入Mysql数据库root密码: " Dataroot_Password
read -p "请输入Mysql数据库zabbix密码: " Datazabbix_Password
[ -n "$Datazabbix_Password" ] && break
done
echo "#######################################################################"
echo "# #"
echo "# 正在编译Zabbix软件 请稍等~ #"
echo "# #"
echo "#######################################################################"
#去官网下载Zabbix:https://www.zabbix.com/download_sources
wget https://repo.zabbix.com/zabbix/6.0/debian/pool/main/z/zabbix-release/zabbix-release_6.0-1+debian11_all.deb
#安装Zabbix
export PATH=/usr/loca/sbin:/usr/sbin:/sbin:$PATH
dpkg -i zabbix-release_6.0-1+debian11_all.deb
apt update
apt install -y zabbix-server-mysql zabbix-frontend-php zabbix-nginx-conf zabbix-sql-scripts zabbix-agent
#安装Mariadb数据库
echo "#######################################################################"
echo "# #"
echo "# 正在安装Mariadb数据库 请稍等~ #"
echo "# #"
echo "#######################################################################"
apt-get -y install mariadb-server
systemctl start mariadb
systemctl enable mariadb
#配置Mariadb数据库
echo "#######################################################################"
echo "# #"
echo "# 正在配置Mariadb数据库 请稍等~ #"
echo "# #"
echo "#######################################################################"
mysql_secure_installation << EOF
y
y
$Dataroot_Password
$Dataroot_Password
y
y
y
y
EOF
#创建zabbix数据库zabbix用户并配置权限
mysql -uroot -p$Dataroot_Password -e "create database zabbix character set utf8 collate utf8_bin;"
mysql -uroot -p$Dataroot_Password -e "create user zabbix@localhost identified by '$Datazabbix_Password';"
mysql -uroot -p$Dataroot_Password -e "grant all privileges on zabbix.* to zabbix@localhost;"
# zabbix数据库导入
zcat /usr/share/doc/zabbix-sql-scripts/mysql/server.sql.gz | mysql -uzabbix -p$Datazabbix_Password zabbix
systemctl restart mariadb
echo "#######################################################################"
echo "# #"
echo "# 正在修改zabbix配置文件 #"
echo "# #"
echo "#######################################################################"
ipdizhi=$(hostname -I)
sed -ri "s/^# DBPassword=/DBPassword= $Datazabbix_Password/g" /etc/zabbix/zabbix_server.conf
sed -ri 's/^# listen 80/listen 80/g' /etc/nginx/conf.d/zabbix.conf
sed -ri "s/^# server_name example.com/server_name $ipdizhi/g" /etc/nginx/conf.d/zabbix.conf
systemctl restart zabbix-server zabbix-agent nginx php7.4-fpm
systemctl enable zabbix-server zabbix-agent nginx php7.4-fpm
echo "--------------------------- 安装已完成 ---------------------------"
echo " 数据库名 :zabbix"
echo " 数据库用户名:密码 :root:$Dataroot_Password"
echo " 数据库用户名:密码 :zabbix:$Datazabbix_Password"
echo " 网站目录 : /usr/share/zabbix"
echo " Zabbix登录 :http://$ipdizhi"
echo " 安装日志文件 :/var/log/"$install_date
echo "------------------------------------------------------------------"
echo "------------------------------------------------------------------"
}
LOGFILE=/var/log/"zabbix_install_$(date +%Y-%m-%d_%H:%M:%S).log"
touch $LOGFILE
tail -f $LOGFILE &
pid=$!
exec 3>&1
exec 4>&2
exec &>$LOGFILE
process
ret=$?
exec 1>&3 3>&-
exec 2>&4 4>&-
|