shell一键部署Zabbix的实现步骤
更新时间:2024年02月19日 09:15:52 作者:M乔木
本文主要介绍了shell一键部署Zabbix的实现步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
上一期我们展示了一键部署Agent端zabbix提升业务效率,本期带来一键部署zabbix的server端的服务脚本!
源码参上
#!/usr/bin/bash # ************************************** # CSDN: M乔木 # qq邮箱: 2776617348@qq.com # 解释器: 这是一个shell脚本 # ************************************** #声明函数 function zabbix_S(){ #环境检测 echo "--------------------------------------------------------" echo "[1]开始检测防火墙Selinux..." f_w=`systemctl status firewalld | awk '/Active:/{print $2}'` s_l=`getenforce` #判断是否关闭 没关闭就结束运行 if [ ${f_w} = "inactive" -a ${s_l} = "Disabled" ];then echo "[2]防火墙SeLinux已关闭..." sleep 1 echo "[3]正在飞速安装zabbix中..." sleep 1 else echo "[2]防火墙SeLinux未关闭..." systemctl disable firewalld &>/dev/null sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config sleep 1 echo "[3]正在关闭..." sleep 1 echo "[4]防火墙SeLinux已关闭 请重启机器生效..." echo "--------------------------------------------------------" exit 0 fi #安装zabbix源 rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm &>/dev/null #安装数据库并清理缓存 echo '[4]准备安装数据库,全程20秒左右,请耐心等待...' sleep 1 echo '[5]开始清理环境...' yum erase mariadb mariadb-server mariadb-libs mariadb-devel -y &>/dev/null userdel -r mysql &>/dev/null rm -rf /etc/my* &>/dev/null rm -rf /var/lib/mysql &>/dev/null rm -rf /usr/bin/mysql &>/dev/null yum -y erase `rpm -qa | egrep "mysql|mariadb"` &>/dev/null echo '[6]正在下载mysqlyum源...' yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm &>/dev/null echo '[7]正在安装mysql...' yum install -y mysql-community-server --enablerepo mysql57-community --disablerepo mysql80-community &>/dev/null yum -y groupinstall "Development Tools" &>/dev/null echo '[8]正在配置mysql...' yum -y install yum-utils &>/dev/null yum-config-manager --disable mysql80-community &>/dev/null yum-config-manager --enable mysql57-community &>/dev/null echo '[9]正在启动mysql...' systemctl start mysqld &>/dev/null echo '[10]正在设置密码,请稍后...' num_az=`awk '/temporary password/{p=$NF}END{print p}' /var/log/mysqld.log` echo 'validate-password=OFF' >> /etc/my.cnf systemctl restart mysqld &>/dev/null read -p '请输入新密码:' passwdx mysqladmin -uroot -p"$num_az" password "$passwdx" &>/dev/null echo "[11]安装完成,密码已设置完成为:$passwdx" echo "[12]密码已保存到/mysql_passwd.txt目录下" echo $passwdx > /mysql_passwd.txt yum clean all &>/dev/null && yum makecache fast &>/dev/null #安装zabbix模块 echo "[13]开始安装zabbix..." yum -y install zabbix-server-mysql zabbix-agent zabbix-get zabbix-sender centos-release-scl &>/dev/null yum -y install yum-utils &>/dev/null rpm -qa | grep yum-utils &>/dev/null if [ $? -eq 1 ];then sleep 1 yum -y install yum-utils &>/dev/null fi yum-config-manager --enable zabbix-frontend &>/dev/null yum -y install zabbix-web-mysql-scl zabbix-nginx-conf-scl centos-release-scl &>/dev/null #建立运行数据库 echo "[14]正在建立运行数据库..." mysql -p"${passwdx}" -e 'create database zabbix character set utf8 collate utf8_bin;' &>/dev/null mysql -p"${passwdx}" -e "create user zabbix@localhost identified by 'admin';" &>/dev/null mysql -p"${passwdx}" -e 'grant all privileges on zabbix.* to zabbix@localhost;' &>/dev/null mysql -p"${passwdx}" -e 'set global log_bin_trust_function_creators = 1;' &>/dev/null mysql -p"${passwdx}" -e 'flush privileges;' &>/dev/null echo "[15]zabbix登录数据库密码为:admin" echo "zabbix登录数据库密码为:admin" >> /zabbix-mysql.txt zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p"admin" zabbix 2>/dev/null #关联数据库 echo "[16]正在改写相关配置文件..." mysql -p"${passwdx}" -e 'set global log_bin_trust_function_creators = 0;' &>/dev/null echo "DBHost=localhost" >> /etc/zabbix/zabbix_server.conf echo "DBPassword=admin" >> /etc/zabbix/zabbix_server.conf echo "DBPort=3306" >> /etc/zabbix/zabbix_server.conf #关联php sed -i '2s/^#//;3s/^#//' /etc/opt/rh/rh-nginx116/nginx/conf.d/zabbix.conf sed -i '38,118d' /etc/opt/rh/rh-nginx116/nginx/nginx.conf sed -i 's/listen.acl_users = apache/listen.acl_users = apache,nginx/' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf sed -i '25d' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf echo 'php_value[date.timezone] = Asia/Shanghai' >> /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf #重启服务 echo "[17]正在重启相关服务..." systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm &>/dev/null systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm &>/dev/null echo "[18]zabbix已部署 后续请登录浏览器安装..." echo "--------------------------------------------------------" } #主界面 zabbix_S
使用方法
touch zabbix-az.sh #新建一个.sh结尾的文件复制上面的源码粘贴进去 sh zabbix-az.sh #运行刚才新建的脚本,根据提示完成部署安装!
到此这篇关于shell一键部署Zabbix的实现步骤的文章就介绍到这了,更多相关shell一键部署Zabbix内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
Cygwin下安装vim后,vim中退格键无法正常使用的解决方法
下面小编就为大家带来一篇Cygwin下安装vim后,vim中退格键无法正常使用的解决方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-02-02
最新评论