Zabbix_Proxy自动化安装脚本

devtools/2024/11/20 4:41:30/

Zabbix Proxy Shell 安装脚本

脚本说明

  • 机器必须要能上网,这样仓库才能下载Zabbix proxy等组件
  • 我的Linux版本是CentOS8 Stream
  • 数据库我用的是mysql8.0版本
  • Zabbix Server的版本是6.0LTS
  • 需要提前下载并上传到服务器上的mysql8.0 tar包到/opt目录下,文件命令为mysql8.0.3.tar即可,脚本会自动解压并安装MySQL
  • 欢迎各位大佬批评指正!!!
shell">#!/usr/bin/env bash#-------------------------------------------------------
# This script is used to install the Proxy
# @ By Eleven
# @ Date 2024-06-16
#-------------------------------------------------------# Zabbix Databse Name
zabbix_db_name=zabbix_proxy# Zabbix user password
zabbix_password=zabbix_py3# Zabbix username
zabbix_username=zabbix_py3# MySQL Databse Password
mysql_password=mysqlwx_123# Function about install http server
InstallHttpServer(){yum -y install httpd &>> /dev/nullsystemctl start httpd.service &>> /dev/nullhttp_status=$(systemctl is-active httpd.service)if [ $http_status = "active" ];thensystemctl enable httpd.service &>> /dev/nullelseecho -e "\033[31mError: Http Server is starting fail!\033[0m"exitfiecho -e "\033[32mMsg: Http Server installed success!\033[0m"
}# Function about install database of MySQL
InstallMySQL(){# temporarily closed Selinux 0 setenforce 0 # tar mysql file and rpm installinstall_status=0if test -f "/opt/mysql8.0.3.tar";thentar -xvf /opt/mysql8.0.3.tar &>> /dev/nullcd /opt/mysql8.0.3/# 1.Install mysql-community-common-8.3.0-1.el8.x86_64one_mark=$(rpm -q "mysql-community-common-8.3.0-1.el8.x86_64" | awk '{print($NF)}')if [ $one_mark != 'installed' ];thenecho -e "\033[32mMsg: [mysql-community-common] package already install\033[0m"elserpm -ivh mysql-community-common-8.3.0-1.el8.x86_64.rpm &>> /dev/nullif [ $? -eq 0 ];thenecho -e "\033[32mMsg: [mysql-community-common] package installed success!\033[0m"elseinstall_status=1echo -e "\033[31mError: [mysql-community-common] package installed fail!\033[0m" fifi# 2.Install mysql-community-client-plugins-8.3.0-1.el8.x86_64tow_mark=$(rpm -q "mysql-community-client-plugins-8.3.0-1.el8.x86_64" | awk '{print($NF)}')if [ $tow_mark != 'installed' ];thenecho -e "\033[32mMsg: [mysql-community-client-plugins] package already install\033[0m"elserpm -ivh mysql-community-client-plugins-8.3.0-1.el8.x86_64.rpm &>> /dev/nullif [ $? -eq 0 ];thenecho -e "\033[32mMsg: [mysql-community-client-plugins] package installed success!\033[0m"elseinstall_status=1echo -e "\033[31mError: [mysql-community-client-plugins] package installed fail!\033[0m" fifi  # 3.Install mysql-community-libs-8.3.0-1.el8.x86_64 three_mark=$(rpm -q "mysql-community-libs-8.3.0-1.el8.x86_64" | awk '{print($NF)}')if [ $three_mark != 'installed' ];thenecho -e "\033[32mMsg: [mysql-community-libs] package already install\033[0m"elserpm -ivh mysql-community-libs-8.3.0-1.el8.x86_64.rpm &>> /dev/nullif [ $? -eq 0 ];thenecho -e "\033[32mMsg: [mysql-community-libs] package installed success!\033[0m"elseinstall_status=1echo -e "\033[31mError: [mysql-community-libs] package installed fail!\033[0m" fifi# 4.Install mysql-community-client-8.3.0-1.el8.x86_64four_mark=$(rpm -q "mysql-community-client-8.3.0-1.el8.x86_64" | awk '{print($NF)}')if [ $four_mark != 'installed' ];thenecho -e "\033[32mMsg: [mysql-community-client] package already install\033[0m"elserpm -ivh mysql-community-client-8.3.0-1.el8.x86_64.rpm &>> /dev/nullif [ $? -eq 0 ];thenecho -e "\033[32mMsg: [mysql-community-client] package installed success!\033[0m"elseinstall_status=1echo -e "\033[31mError: [mysql-community-client] package installed fail!\033[0m" fifi# 5.Install mysql-community-icu-data-files-8.3.0-1.el8.x86_64five_mark=$(rpm -q "mysql-community-icu-data-files-8.3.0-1.el8.x86_64" | awk '{print($NF)}')if [ $five_mark != 'installed' ];thenecho -e "\033[32mMsg: [mysql-community-icu-data-files] package already install\033[0m"elserpm -ivh mysql-community-icu-data-files-8.3.0-1.el8.x86_64.rpm &>> /dev/nullif [ $? -eq 0 ];thenecho -e "\033[32mMsg: [mysql-community-icu-data-files] package installed success!\033[0m"elseinstall_status=1echo -e "\033[31mError: [mysql-community-icu-data-files] package installed fail!\033[0m" fifi# 6.Install mysql-community-server-8.3.0-1.el8.x86_64six_mark=$(rpm -q "mysql-community-server-8.3.0-1.el8.x86_64" | awk '{print($NF)}')if [ $six_mark != 'installed' ];thenecho -e "\033[32mMsg: [mysql-community-server] package already install\033[0m"elserpm -ivh mysql-community-server-8.3.0-1.el8.x86_64.rpm &>> /dev/nullif [ $? -eq 0 ];thenecho -e "\033[32mMsg: [mysql-community-server] package installed success!\033[0m"elseinstall_status=1echo -e "\033[31mError: [mysql-community-server] package installed fail!\033[0m" fifielseecho -e "\033[31mError: MySQL installation package not found!\033[0m"echo -e "\033[31mError: Please Put the MySQL installation package in the 【/opt】 directory\033[0m"exitfiif [ $install_status -eq 1 ];thenecho -e "\033[31mMsg: MySQL Database installed fail!\033[0m"exitelseecho -e "\033[32mMsg: MySQL Database installed success!\033[0m" fi}# Function about init Database of MySQL
InitMySQL(){pwd_status=0mysqld --initialize &>> /dev/nullsleep 10  chown -R mysql:mysql /var/lib/mysql &>> /dev/null chmod -R 755 /var/lib/mysql &>> /dev/null			systemctl start mysqld.service &>> /dev/null		mysql_status=$(systemctl is-active mysqld.service)if [ $mysql_status = "active" ];thensystemctl enable mysqld.service &>> /dev/nullecho -e "\033[32mMsg: MySQL Server is starting success!\033[0m"elseecho -e "\033[31mError: MySQL Server is starting fail!\033[0m"exitfitemporarily_password=$(cat /var/log/mysqld.log | grep root@localhost | awk '{print($NF)}')mysql -uroot -p"$temporarily_password" -e "quit"mysql --connect-expired-password -uroot -p"$temporarily_password" <<EOF
ALTER USER 'root'@'localhost' identified by '$mysql_password';
quit;
EOFif [ $? -eq 0 ];thenecho -e "\033[32mMsg: MySQL password changed success!\033[0m"elseecho -e "\033[31mMsg: MySQL password changed fail!\033[0m"pwd_status=1exitfiif [ $pwd_status -eq 0 ];thenecho -e "\033[32mMsg: Init MySQL Server is success!\033[0m"elseecho -e "\033[31mMsg: Init MySQL Server is fail!\033[0m"exitfi}# Function about install Proxy
InstallProxy() {yum -y install zabbix-proxy-mysql zabbix-sql-scripts zabbix-selinux-policy &>> /dev/nullif [ $? -eq 0 ];thenecho -e "\033[32mMsg: Zabbix Proxy install success!\033[0m"elseecho -e "\033[31mMsg: Zabbix Proxy install fail!\033[0m"fimysql -uroot -p$mysql_password <<EOF
create database $zabbix_db_name character set utf8mb4 collate utf8mb4_bin;
create user '$zabbix_username'@'localhost' identified with mysql_native_password by '$zabbix_password';
grant all privileges on $zabbix_db_name.* to $zabbix_username@localhost;
set global log_bin_trust_function_creators = 1;
quit;
EOFcat /usr/share/zabbix-sql-scripts/mysql/proxy.sql | mysql --default-character-set=utf8mb4 -u$zabbix_username -p$zabbix_password $zabbix_db_nameif [ $? -eq 0 ];thenecho -e "\033[32mMsg: zabbix mysql upload success\033[0m"elseecho -e "\033[31mMsg: zabbix mysql upload fail\033[0m"  fimysql -uroot -p$mysql_password <<EOF
set global log_bin_trust_function_creators = 0;
quit;
EOF# set proxy servicesystemctl restart zabbix-proxy &>> /dev/nullproxy_status=$(systemctl is-active zabbix-proxy)if [ $proxy_status = "active" ];thensystemctl enable zabbix-proxy &>> /dev/nullecho -e "\033[32mMsg: Zabbix Proxy status is starting success!\033[0m"elseecho -e "\033[31mError: Zabbix Proxy status is starting fail!\033[0m"Proxy_start_status=1exitfi}# Function about open firewalld port and service
OpenPort(){# open 10051 161 httpfirewall-cmd --zone=public --add-port=10050/tcp --permanent &>> /dev/nullfirewall-cmd --zone=public --add-port=10051/tcp --permanent &>> /dev/nullfirewall-cmd --zone=public --add-port=161/tcp --permanent &>> /dev/nullfirewall-cmd --zone=public --add-service=http  --permanen &>> /dev/nullfirewall-cmd --reload &>> /dev/nullecho -e "\033[32mMsg: Firewalld Port is opening!\033[0m"
}# Function about set Unified time zone
Time_synchronization(){#judgment chrony install? Complete=$(yum -y install chrony | grep Complete!)if [ $Complete = "Complete!" ];thenecho -e "\033[32mMsg: chrony is already install!\033[0m"elseecho ">>>>>> start install chrony!"yum -y install chronyif [ $? -eq 0 ];thenecho -e "\033[32mMsg: chrony install success\033[0m"systemctl enable chronyd --now elseecho -e "\033[31mMsg: chrony install fail\033[0m" fifiecho ">>>>>> start synchronization time"sed -i '/pool 2.centos.pool.ntp.org iburst/a\server 192.168.95.8 iburst' /etc/chrony.confsystemctl restart chronydecho -e "\033[32mMsg: synchronization time success\033[0m" 
}echo ">>>>>> Check the local repository configuration"
yum -y install vim &>>/dev/null
if [ $? -ne 0 ];thenecho -e "\033[31mError: Please check the configuration of your local repository\033[0m"exit
elseecho -e "\033[32mMsg: Local repository check success!\033[0m"
fiecho ">>>>>> Install the necessary components"
tools_status=$( rpm -q net-tools | awk '{print($NF)}')
if [ $tools_status = "installed" ];thenyum -y install net-tools &>> /dev/null
fiperl_status=$( rpm -q perl | awk '{print($NF)}')
if [ $perl_status = "installed" ];thenyum -y install perl &>> /dev/null
fi
echo -e "\033[32mMsg: Check components success!\033[0m"echo ">>>>>> Starting install http service"
InstallHttpServerecho ">>>>>> Starting install MySQL server"
InstallMySQLecho ">>>>>> Starting init MySQL server"
InitMySQLecho ">>>>>> Starting install zabbix proxy server "
InstallProxyecho ">>>>>> Starting open firewalld port"
OpenPortecho ">>>>>> Set Time synchronization"
Time_synchronizationecho -e "\033[32mExecuted Success! Over\033[0m"

http://www.ppmy.cn/devtools/104738.html

相关文章

经验笔记:Hadoop

Hadoop经验笔记 一、Hadoop概述 Hadoop是一个开源软件框架&#xff0c;用于分布式存储和处理大规模数据集。其设计目的是为了在商用硬件上运行&#xff0c;具备高容错性和可扩展性。Hadoop的核心是Hadoop Distributed File System (HDFS) 和YARN (Yet Another Resource Negot…

C++ TinyWebServer项目总结(13. 多进程编程)

本章讨论Linux多进程编程的以下内容&#xff1a; 复制进程映像的fork系统调用和替换进程映像的exec系列系统调用。僵尸进程以及如何避免僵尸进程。进程间通信&#xff08;Inter Process Communication&#xff0c;IPC&#xff09;最简单的方式&#xff1a;管道。三种System V进…

this.$nextTick() 是 Vue.js 提供的一个方法

this.$nextTick() 是 Vue.js 提供的一个方法&#xff0c;用于在 DOM 更新完成后执行指定的代码。它的作用主要是确保在 Vue.js 完成 DOM 更新后&#xff0c;再执行某些依赖于更新的操作。这个方法通常用于处理需要在视图更新后立即进行的操作&#xff0c;如获取最新的 DOM 元素…

常用Numpy操作(笔记整理)

目录 一、常用&#xff08;自查&#xff09; 1. 创建数组&#xff08;array&#xff09; 2. 数组形状&#xff08;shape&#xff09; 3. 数组维度&#xff08;ndim&#xff09; 4. 数组⼤⼩&#xff08;size&#xff09; 5. 数组数据类型&#xff08;dtype&#xff09; …

论文速读|ReKep:空间时间理论的关系关键点约束,用于机器人操作

项目地址&#xff1a;ReKep | Spatio-Temporal ReasoningReKep | Spatio-Temporal Reasoning of Relational Keypoint Constraints for Robotic ManipulationReKep | Spatio-Temporal Reasoning ReKep&#xff08;Relational Keypoint Constraints&#xff09;是一种基于视觉的…

微信小程序遇到的问题

wx.redirectTo 跳转闪屏 wx.redirectTo 是让当前页面出栈&#xff0c;在加载新的页面&#xff0c;&#xff0c;&#xff0c;&#xff0c;当我的当前页是这个栈的唯一页面的时候&#xff0c;就会出现闪屏 想要像wx.navigateTo那样有过渡效果&#xff0c;可以先getCurrentPages(…

Web3前端开发:重塑互联网的未来

随着技术的飞速发展&#xff0c;互联网正逐步从Web 2.0向Web3迈进。这一转变不仅带来了技术层面的革新&#xff0c;更在商业模式、用户体验以及数据所有权方面引发了深刻的变革。作为这一变革的前沿阵地&#xff0c;Web3前端开发正成为开发者们探索新领域、实现创新应用的关键。…

代码随想录算法训练营第四十天| 背包问题(二维)、LeetCode416.分割等和子集

#背包问题&#xff08;二维&#xff09; #背包问题&#xff08;二维&#xff09;&#xff1a;带你学透0-1背包问题&#xff01;| 关于背包问题&#xff0c;你不清楚的地方&#xff0c;这里都讲了&#xff01;| 动态规划经典问题 | 数据结构与算法_哔哩哔哩_bilibili 动态规划五…