说明:一位大学同学所在的公司最近在做监控平台选型,最终定了免费的zabbix监控产品,听他描述,上周在部署过程中遇到了各种坑,所以帮助他整理了一份自动化部署脚本,避免浪费太多的时间在部署上。
步骤一:上传封装好的脚本及依赖文件,并解压,如下图所示:
步骤二:可以看到解压书后的脚本及文件:
步骤三:直接执行脚本安装即可(整改过程全自动部署)
安装完成后可以看到提示,查看自己的ip地址,通过浏览器界面访问即可:
步骤四:使用任意浏览器访问zabbix登陆界面(默认密码zabbix):
登陆后界面如下所示:
到这里就自动部署完成了。
脚本内容如下:
#/bin/bash
###by for ALOM ZABBIX
###SYSTEM_VERSION:CentOS Linux release 7.4 version
###ZABBIX_VERSION:zabbix_server 4.0.0
###MARIADB_VERSION:5.6.41 MySQL Community Server (GPL)
src_home=`pwd`
repo_name=zabbix4.0.0
echo \'Configuring firewalls......\'
firewall-cmd --zone=public --add-port=10051/tcp --permanent > /dev/null 2>&1
firewall-cmd --zone=public --add-port=10050/tcp --permanent > /dev/null 2>&1
firewall-cmd --zone=public --add-port=80/tcp --permanent > /dev/null 2>&1
firewall-cmd --zone=public --add-port=3306/tcp --permanent > /dev/null 2>&1
firewall-cmd --zone=public --add-port=161/udp --permanent > /dev/null 2>&1
firewall-cmd --zone=public --add-port=162/udp --permanent > /dev/null 2>&1
firewall-cmd --complete-reload > /dev/null 2>&1
if [ $? -eq 0 ];then
echo \'Configuring the firewall to complete\'
fi
echo \'Closing SElinux......\'
setenforce 0 > /dev/null 2>&1
sed -i \'s/^SELINUX=.*/SELINUX=disabled/g\' /etc/selinux/config
if [ $? -eq 0 ];then
echo \'SElinux configuration is completed\'
fi
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
if [ $? -eq 0 ];then
echo \'Backup source Yum file is completed\'
fi
echo "Configure the offline Yum source......"
cat > /etc/yum.repos.d/$repo_name.repo << EOF
[zabbix]
name=$repo_name
baseurl=file://$src_home/$repo_name/
enabled=1
gpgcheck=0
EOF
if [ $? -eq 0 ];then
echo \'Configure the offline Yum source is completed\'
fi
echo "Install Zabbix......"
yum clean all > /dev/null 2>&1
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y > /dev/null 2>&1
if [ $? -eq 0 ];then
echo \'Install Zabbix is completed\'
fi
echo "Install Mysql......"
yum install mysql-community-server -y > /dev/null 2>&1
if [ $? -eq 0 ];then
echo \'Install Mysql is completed\'
fi
echo "Start mysql server ......"
systemctl start mysqld > /dev/null 2>&1
if [ $? -eq 0 ];then
echo "Mysql start is completed"
fi
echo "Configure Mysql......"
mysql -e "create database zabbix character set utf8 collate utf8_bin;grant all privileges on zabbix.* to zabbix@localhost identified by \'zabbix\';flush privileges;"
if [ $? -eq 0 ];then
echo \'Zabbix user Create completed\'
fi
zcat /usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz | mysql -uzabbix -pzabbix zabbix
if [ $? -eq 0 ];then
echo \'Zabbix DB Import completed\'
fi
echo "Disable Guests usergroup......"
mysql -e "update zabbix.usrgrp set users_status=1 where name=\'Guests\';"
if [ $? -eq 0 ];then
echo \'Disable Guests usergroup is completed\'
fi
echo "Configuring the ZABBIX configuration file......"
sed -i \'s/.*DBPassword=/DBPassword=zabbix/g\' /etc/zabbix/zabbix_server.conf
if [ $? -eq 0 ];then
echo \'Configuring the ZABBIX configuration file is completed\'
fi
echo "Configuring PHP......"
sed -i \'s/# php_value date.timezone.*/php_value date.timezone Asia\/Shanghai/g\' /etc/httpd/conf.d/zabbix.conf
if [ $? -eq 0 ];then
echo \'Configuring PHP is completed\'
fi
echo "Configuring the Apache root directory......"
sed -i \'s/^DocumentRoot.*/DocumentRoot \"\/usr\/share\/zabbix\"/g\' /etc/httpd/conf/httpd.conf
if [ $? -eq 0 ];then
echo \'Configuring the Apache root directory is completed\'
fi
echo "Configuring zabbix setup web page ......"
setup_page=\'zabbix.conf.php\'
cp $src_home/$repo_name/$setup_page /etc/zabbix/web/
chown apache:apache /etc/zabbix/web/$setup_page
if [ $? -eq 0 ];then
echo \'Configuring zabbix setup web page is completed\'
fi
echo "Graphic and text messy code......"
font_name=\'msyh.ttf\'
cp $src_home/$repo_name/$font_name /usr/share/zabbix/fonts/
chmod 755 /usr/share/zabbix/fonts/$font_name
sed -i \'s/graphfont/msyh/g\' /usr/share/zabbix/include/defines.inc.php
if [ $? -eq 0 ];then
echo \'Graphic and text messy code is completed\'
fi
echo "Start zabbix-server zabbix-agent http......"
systemctl start zabbix-server zabbix-agent httpd > /dev/null 2>&1
if [ $? -eq 0 ];then
echo \'Start zabbix-server zabbix-agent http is completed\'
fi
echo "Set up boot start mysqld zabbix-server zabbix-agent http......"
systemctl enable mysqld zabbix-server zabbix-agent httpd > /dev/null 2>&1
if [ $? -eq 0 ];then
echo \'Set up boot start mysqld zabbix-server zabbix-agent http is completed\'
fi
echo "Restore the yum file......"
rm -rf /etc/yum.repos.d/$repo_name.repo
mv /etc/yum.repos.d/bak/*.repo /etc/yum.repos.d/
yum clean all > /dev/null 2>&1
if [ $? -eq 0 ];then
echo \'Restore the yum file is completed\'
fi
echo "Follow up configuration through the web page http://ip/"
使用中如有问题可随时在下发评论处留言哦,关注我每天分享更多实用的运维知识哦
内容出处:,
声明:本网站所收集的部分公开资料来源于互联网,转载的目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。如果您发现网站上有侵犯您的知识产权的作品,请与我们取得联系,我们会及时修改或删除。文章链接:http://www.yixao.com/tech/17190.html