首页 > 其他分享 >脚本之一键安装zabbix监控端

脚本之一键安装zabbix监控端

时间:2022-10-08 23:31:54浏览次数:53  
标签:脚本 MYSQL ZABBIX echo zabbix 监控 mysql ID

ZABBIX_VER=5.0
URL="https://mirror.tuna.tsinghua.edu.cn/zabbix"
FONT=msyhbd.ttc

MYSQL_HOST=localhost
#MYSQL_HOST=10.0.0.100
MYSQL_ZABBIX_USER="zabbix@localhost"
#MYSQL_ZABBIX_USER="zabbix@'10.0.0.%'"

MYSQL_ZABBIX_PASS='123456'
MYSQL_ROOT_PASS='123456'

ZABBIX_IP=`hostname -I|awk '{print $1}'`
GREEN="echo -e \E[32;1m"
END="\E[0m"

. /etc/os-release


color () {
RES_COL=60
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \E[0m"
echo -n "$1" && $MOVE_TO_COL
echo -n "["
if [ $2 = "success" -o $2 = "0" ] ;then
${SETCOLOR_SUCCESS}
echo -n $" OK "
elif [ $2 = "failure" -o $2 = "1" ] ;then
${SETCOLOR_FAILURE}
echo -n $"FAILED"
else
${SETCOLOR_WARNING}
echo -n $"WARNING"
fi
${SETCOLOR_NORMAL}
echo -n "]"
echo
}

install_mysql () {
[ $MYSQL_HOST != "localhost" ] && return
if [ $ID = "centos" -o $ID = "rocky" ] ;then
VERSION_ID=`echo $VERSION_ID | cut -d . -f1`
if [ ${VERSION_ID} == "8" ];then
yum -y install mysql-server
systemctl enable --now mysqld
elif [ ${VERSION_ID} == "7" ];then
yum -y install mariadb-server
systemctl enable --now mariadb
else
color "不支持的操作系统,退出" 1
fi
else
apt update
apt -y install mysql-server
[ $? -eq 0 ] || { color "安装MySQL失败,退出!" 1 ; exit ; }
sed -i "/^bind-address.*/c bind-address = 0.0.0.0" /etc/mysql/mysql.conf.d/mysqld.cnf
systemctl restart mysql
fi
mysqladmin -uroot password $MYSQL_ROOT_PASS
mysql -uroot -p$MYSQL_ROOT_PASS <<EOF
create database zabbix character set utf8 collate utf8_bin;
create user $MYSQL_ZABBIX_USER identified by "$MYSQL_ZABBIX_PASS";
grant all privileges on zabbix.* to $MYSQL_ZABBIX_USER;
quit
EOF
if [ $? -eq 0 ];then
color "MySQL数据库准备完成" 0
else
color "MySQL数据库配置失败,退出" 1
exit
fi
}

install_zabbix () {
if [ $ID = "centos" -o $ID = "rocky" ] ;then
rpm -Uvh $URL/zabbix/${ZABBIX_VER}/rhel/${VERSION_ID}/x86_64/zabbix-release-${ZABBIX_VER}-1.el${VERSION_ID}.noarch.rpm
if [ $? -eq 0 ];then
color "YUM仓库准备完成" 0
else
color "YUM仓库配置失败,退出" 1
exit
fi
sed -i "s#http://repo.zabbix.com#$URL#" /etc/yum.repos.d/zabbix.repo
if [ ${VERSION_ID} == "8" ];then
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-agent2 zabbix-get langpacks-zh_CN
else
yum -y install zabbix-server-mysql zabbix-agent2 zabbix-get
yum -y install centos-release-scl
rpm -q yum-utils || yum -y install yum-utils
yum-config-manager --enable zabbix-frontend
yum -y install zabbix-web-mysql-scl zabbix-apache-conf-scl
fi
else
wget $URL/zabbix/${ZABBIX_VER}/ubuntu/pool/main/z/zabbix-release/zabbix-release_${ZABBIX_VER}-1+${UBUNTU_CODENAME}_all.deb
if [ $? -eq 0 ];then
color "APT仓库准备完成" 0
else
color "APT仓库配置失败,退出" 1
exit
fi
dpkg -i zabbix-release_${ZABBIX_VER}-1+${UBUNTU_CODENAME}_all.deb
sed -i "s#http://repo.zabbix.com#$URL#" /etc/apt/sources.list.d/zabbix.list
apt update
apt -y install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-agent2 zabbix-get language-pack-zh-hans
fi
}
config_mysql_zabbix () {
if [ -f $FONT ] ;then
mv /usr/share/zabbix/assets/fonts/graphfont.ttf{,.bak}
cp $FONT /usr/share/zabbix/assets/fonts/graphfont.ttf
else
color "缺少字体文件!" 1
fi
if [ $MYSQL_HOST = "localhost" ];then
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p$MYSQL_ZABBIX_PASS -h$MYSQL_HOST zabbix
fi
sed -i -e "/.*DBPassword=.*/c DBPassword=$MYSQL_ZABBIX_PASS" -e "/.*DBHost=.*/c DBHost=$MYSQL_HOST" /etc/zabbix/zabbix_server.conf
if [ $ID = "centos" -o $ID = "rocky" ];then
if [ ${VERSION_ID} == "8" ];then
sed -i -e "/.*date.timezone.*/c php_value[date.timezone] = Asia/Shanghai" -e "/.*upload_max_filesize.*/c php_value[upload_max_filesize] = 20M" /etc/php-fpm.d/zabbix.conf
systemctl enable --now zabbix-server zabbix-agent2 httpd php-fpm
else
sed -i "/.*date.timezone.*/c php_value[date.timezone] = Asia/Shanghai" /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
systemctl restart zabbix-server zabbix-agent2 httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent2 httpd rh-php72-php-fpm
fi
else
sed -i "/date.timezone/c php_value date.timezone Asia/Shanghai" /etc/apache2/conf-available/zabbix.conf
chown -R www-data.www-data /usr/share/zabbix/
systemctl enable zabbix-server zabbix-agent2 apache2
systemctl restart zabbix-server zabbix-agent2 apache2
fi
if [ $? -eq 0 ];then
echo
color "ZABBIX-${ZABBIX_VER}安装完成!" 0
echo "-------------------------------------------------------------------"
${GREEN}"请访问: http://$ZABBIX_IP/zabbix"${END}
else
color "ZABBIX-${ZABBIX_VER}安装失败!" 1
exit
fi
}

install_mysql
install_zabbix
config_mysql_zabbix

标签:脚本,MYSQL,ZABBIX,echo,zabbix,监控,mysql,ID
From: https://blog.51cto.com/dayu/5738786

相关文章

  • 脚本之一键安装zabbix-agent被监控端
    1、安装zabbix-agent2脚本ZABBIX_SERVER=zabbix.wang.orgZABBIX_VER=5.0URL="https://mirror.tuna.tsinghua.edu.cn/zabbix"./etc/os-releasecolor(){RES_COL=60......
  • shell脚本实例分析1
    1、#!/bin/ksh#name:testdirecho$0program=`basename$0`program_dir=`dirname$0`echo"program=$program"echo"program_dir=$program_dir"if[`echo"$0"|grep......
  • Shell脚本实现自动化安装
    在Linux环境下,实现多个软件包的自动化安装步骤:1、找到软件包,提取软件包的名字建立解压路径(为了让我们更清楚的找到我们的文件)pkg=`find${PACKAGE_PATH}-name*BIN*.tar.gz......
  • 此系统上禁止运行脚本 问题
    参考https://blog.csdn.net/qq_34516746/article/details/123615008  win10 使用管理员打开powershell敲入以下命令后,输入Yset-executionpolicyremotesigned......
  • RabbitMQ 集群迁移与监控
    一、集群迁移RabbitMQ中的集群迁移更多的是用来解决集群故障不可短时间内修复而将所有的数据、客户端连接等迁移到新的集群中,以确保服务的可用性。迁移过程包括元数......
  • Linux 简单的Java sh脚本启动jar包
    123projectName="你的项目名"45#提醒功能6help(){7echo"help:sh${projectName}.sh[start|stop|restart]"8exit19}1011#判断项......
  • 泛在电力物联网下的远程抄表和设备监控维护
    随着工业化自动化的发展,物联网技术取得了蓬勃的发展。在电力能源领域,受到广泛的应用与关注,资料显示,国家电网系统接入的终端设备超过5亿只(其中4.5亿只电表,各类保护、采集、......
  • ZABBIX警告常见问题集锦
    一、磁盘1、告警:Diskread/writerequestresponsesaretoohigh表达式解释为:最近15分钟的对应磁盘的Diskreadrequestavgwaitingtime(r_await)大于20m......
  • Grafana监控java应用以及vCenter的方法
    Grafana监控java应用以及vCenter的方法背景最开始弄过vCenter的监控.但是发现很多地方已经不合适了.今天看了下jmx监控java的应用.顺便监控了下vCenter.这里简单记录一下,......
  • 在vscode中用tsc编译ts文件的时候报错,tsc : 无法加载文件,因为在此系统上禁止运行脚本;S
    1. TypeScript安装成功,在C盘的Administrator目录下,运行 tsc-v 也可看到TypeScript的版本。  2. 但在vscode中的时候运行tsc 编译ts文件的时候......