此脚本是Zabbix_Server安装脚本,有需要朋友可以参考,脚本内容如下:
系统环境:CentOS 7.9文章源自小柒网-https://www.yangxingzhen.cn/6695.html
软件版本:4.4.3文章源自小柒网-https://www.yangxingzhen.cn/6695.html
[root@localhost ~]# vim auto_install_zabbix_server.sh文章源自小柒网-https://www.yangxingzhen.cn/6695.html
#!/bin/bash
#2020-3-12 09:28:53
#By Author YangXingZhen
#Auto Install Zabbix_Server And Zabbix_Agent
#Define Zabbix path variables
ZABBIX_URL=http://mirrors.yangxingzhen.com/zabbix
ZABBIX_FILES=zabbix-4.4.3.tar.gz
ZABBIX_FILES_DIR=zabbix-4.4.3
ZABBIX_PREFIX=/usr/local/zabbix
function Install_Zabbix (){
#Install Zabbix_Server
if [ ! -d ${ZABBIX_PREFIX} ];then
#Install Package
yum -y install net-snmp net-snmp-devel perl-DBI curl curl-devel libevent libevent-devel wget gcc gcc-c++ mysql-devel pcre pcre-devel
wget -c ${ZABBIX_URL}/${ZABBIX_FILES}
tar xf ${ZABBIX_FILES}
cd ${ZABBIX_FILES_DIR}
./configure --prefix=${ZABBIX_PREFIX} --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl
if [ $? -eq 0 ];then
make && make install
echo -e "\033[32mThe Zabbix_Server Install Sussess...\033[0m"
else
echo -e "\033[31mThe Zabbix_Server Install Failed...\033[0m"
exit 1
fi
else
echo -e "\033[31mThe Zabbix_Server already Install...\033[0m"
exit 1
fi
#Backup Configuration File
\cp ${ZABBIX_PREFIX}/etc/zabbix_server.conf ${ZABBIX_PREFIX}/etc/zabbix_server.conf.bak
ln -sf ${ZABBIX_PREFIX}/sbin/zabbix_* /usr/local/sbin/
#Config Zabbix_Server File
cat >${ZABBIX_PREFIX}/etc/zabbix_server.conf <<EOF
LogFile=/tmp/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=www.yangxingzhen.cn
Timeout=30
LogSlowQueries=3000
EOF
#Configuring system services
\cp misc/init.d/tru64/zabbix_server /etc/init.d/zabbix_server
chmod o+x /etc/init.d/zabbix_server
#Create zabbix user
useradd -s /sbin/nologin zabbix >/dev/null 2>&1
#Configure power on self start
grep -qw "/etc/init.d/zabbix_server" /etc/rc.d/rc.local
if [ $? -ne 0 ];then
echo "/etc/init.d/zabbix_server start" >>/etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
fi
}
function Config_Zabbix_DB (){
stty erase '^H'
Code=""
while true
do
read -p "$(echo -e "\033[32m请输入Zabbix_Server连接的数据库IP(Default:localhost):\033[0m")" DB_Host
if [ -z "${DB_Host}" ];then
echo -e "\033[31m输入错误,数据库IP不能为空...\033[0m"
elif [ "${DB_Host}" = "q" -o "${DB_Host}" = "Q" ];then
Code="break"
else
sed -i "s/DBHost=.*/DBHost=${DB_Host}/" ${ZABBIX_PREFIX}/etc/zabbix_server.conf
while true
do
read -p "$(echo -e "\033[32m请输入Zabbix_Server连接的数据库名(Default:zabbix): \033[0m")" DB_Name
if [ "${DB_Name}" = "q" -o "${DB_Name}" = "Q" ];then
Code="break"
elif [ -z "${DB_Name}" ];then
echo -e "\033[31m输入错误,数据库名不能为空...\033[0m"
else
sed -i "s/DBName=.*/DBName=${DB_Name}/" ${ZABBIX_PREFIX}/etc/zabbix_server.conf
while true
do
read -p "$(echo -e "\033[32m请输入Zabbix_Server连接的数据库用户名(Default:zabbix): \033[0m")" DB_User
if [ "${DB_User}" = "q" -o "${DB_User}" = "Q" ];then
Code="break"
elif [ -z "${DB_User}" ];then
echo -e "\033[31m输入错误,数据库用户名不能为空...\033[0m"
else
sed -i "s/DBUser=.*/DBUser=${DB_User}/" ${ZABBIX_PREFIX}/etc/zabbix_server.conf
while true
do
read -p "$(echo -e "\033[32m请输入Zabbix_Server连接的数据库密码(Default:www.yangxingzhen.cn): \033[0m")" DB_Passwd
if [ "${DB_Passwd}" = "q" -o "${DB_Passwd}" = "Q" ];then
Code="break"
elif [ -z "${DB_Passwd}" ];then
echo -e "\033[31m输入错误,数据库密码不能为空...\033[0m"
else
sed -i "s/DBPassword=.*/DBPassword=${DB_Passwd}/" ${ZABBIX_PREFIX}/etc/zabbix_server.conf
[ -f /usr/bin/mysql ] || yum -y install mysql >/dev/null
echo -e "\033[32m正在测试数据库连接...\033[0m"
mysql -h${DB_Host} -u${DB_User} -p${DB_Passwd} -e "show databases;" >/dev/null 2>&1
if [ $? -eq 0 ];then
echo -e "\033[32mMysql连接测试结果:Sussess\033[0m"
echo -e "\033[32m正在导入Zabbix初始数据...\033[0m"
mysql -h${DB_Host} -u${DB_User} -p${DB_Passwd} ${DB_Name} <database/mysql/schema.sql
mysql -h${DB_Host} -u${DB_User} -p${DB_Passwd} ${DB_Name} <database/mysql/images.sql
mysql -h${DB_Host} -u${DB_User} -p${DB_Passwd} ${DB_Name} <database/mysql/data.sql
echo -e "\033[32m正在启动Zabbix_Server服务...\033[0m"
/etc/init.d/zabbix_server start
Code="break"
else
echo -e "\033[31mMysql测试结果:Failed...\033[0m"
Config_Zabbix_DB
fi
fi
${Code}
done
fi
${Code}
done
fi
${Code}
done
fi
${Code}
done
}
function Main (){
Install_Zabbix
Config_Zabbix_DB
}
Main
脚本执行方式:文章源自小柒网-https://www.yangxingzhen.cn/6695.html
[root@localhost ~]# sh auto_install_zabbix_server.sh文章源自小柒网-https://www.yangxingzhen.cn/6695.html
文章源自小柒网-https://www.yangxingzhen.cn/6695.html
文章源自小柒网-https://www.yangxingzhen.cn/6695.html
若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!
继续阅读
Wechat
微信扫一扫,加我!
![weinxin](https://www.yangxingzhen.com/images/weixin.jpg)
我的微信
微信公众号
微信扫一扫,关注我!
![weinxin](https://www.yangxingzhen.com/images/weixingongzhonghao.png)
我的公众号
评论