Centos7一键安装zabbix5脚本

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
简介: 脚本安装zabbix5,方便实用

!/bin/sh

ip=ip addr |grep inet |egrep -v "inet6|127.0.0.1" |awk '{print $2}' |awk -F "/" '{print $1}'
printf "

欢迎使用Zabbix一键部署脚本

避免软件包产生冲突建议使用纯净的操作系统进行安装!

"

while :; do echo

read -p "c(centos) or u(ubuntu): " system_type
[ -n "$system_type" ] && break

done
if [ $system_type = 'c' ];then
release=cat /etc/redhat-release | awk '{print $4}' | awk -F '.' '{print $1}'
echo "#######################################################################"
echo "# #"
echo "# 正在关闭SElinux策略及防火墙 请稍等~ #"
echo "# #"
echo "#######################################################################"
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
systemctl stop firewalld && systemctl disable firewalld
if [ $release = '7' ];then
echo "系统版本为CentOS 7,只能安装Zabbix 5.0"
cat < /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - &dollar;basearch
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/&dollar;basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/rhel/7/&dollar;basearch/frontend
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - &dollar;basearch
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/7/&dollar;basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
EOF
echo "添加源gpgkey"
curl https://mirror.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
curl https://mirror.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
curl https://mirror.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
curl https://mirror.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
yum -y install mariadb-server centos-release-scl epel-release
yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-web-mysql-scl zabbix-apache-conf-scl zabbix-agent vim
elif [ $release = '8' ];then
while :; do echo

read -p "zabbix版本选择(5.0 or 5.2 or 5.4) " zbx_v
[ -n "$zbx_v" ] && break

done
cat < /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - &dollar;basearch
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/$zbx_v/rhel/8/\$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - &dollar;basearch
baseurl=https://mirror.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/8/&dollar;basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
EOF
echo "添加源gpgkey"
curl https://mirror.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
curl https://mirror.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
curl https://mirror.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
curl https://mirror.tuna.tsinghua.edu.cn/zabbix/RPM-GPG-KEY-ZABBIX \
-o /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
dnf -y install mariadb-server zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-agent vim
fi
elif [ $system_type = 'u' ];then
release=cat /etc/issue | grep Ubuntu | awk '{print $2}' | awk -F '.' '{print $1"."$2}'
while :; do echo

read -p "zabbix版本选择(5.0 or 5.2 or 5.4) " zbx_v
[ -n "$zbx_v" ] && break
done

if [ $zbx_v = '5.0' ];then
if [ $release = '18.04' ];then
wget https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+bionic_all.deb
dpkg -i zabbix-release_5.0-1+bionic_all.deb
apt update
elif [ $release = '20.04'];then
wget https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+focal_all.deb
dpkg -i zabbix-release_5.0-1+focal_all.deb
apt update
fi
else
wget https://mirror.tuna.tsinghua.edu.cn/zabbix/zabbix/$zbx_v/ubuntu/pool/main/z/zabbix-release/zabbix-release_$zbx_v-1+ubuntu"$release"_all.deb
dpkg -i zabbix-release_"$zbx_v"-1+ubuntu"$release"_all.deb
apt update
fi
apt -y install zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-agent mariadb-server
fi

echo "#######################################################################"
echo "# #"
echo "# 正在启动及配置Mariadb数据库 请稍等~ #"
echo "# #"
echo "#######################################################################"
systemctl start mariadb && systemctl enable mariadb
while :; do echo

read -p "设置Mysql数据库root密码(建议使用字母+数字): " Database_Password
[ -n "$Database_Password" ] && break

done

mysqladmin -u root password "$Database_Password"
echo "create database zabbix default charset utf8 COLLATE utf8_bin;" | mysql -uroot -p$Database_Password
echo "grant all privileges on zabbix.* to zabbix@'localhost' identified by '$Database_Password';" | mysql -uroot -p$Database_Password
echo "flush privileges;" | mysql -uroot -p$Database_Password
echo "#######################################################################"
echo "# #"
echo "# 正在导入zabbix数据库架构文件,请稍等~ #"
echo "# #"
echo "#######################################################################"
release=zabbix_server -V | grep zabbix_server | awk '{print $3}' | awk -F '.' '{print $1"."$2}'
if [ $release = '5.0' ];then
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p$Database_Password zabbix
elif [ $release = '5.2' ];then
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p$Database_Password zabbix
elif [ $release = '5.4' ];then
if [ $system_type = 'c' ];then
dnf -y install zabbix-sql-scripts
elif [ $system_type = 'u' ];then
apt -y install zabbix-sql-scripts
fi
zcat /usr/share/doc/zabbix-sql-scripts/mysql/create.sql.gz | mysql -uzabbix -p$Database_Password zabbix
fi
echo "#######################################################################"
echo "# #"
echo "# 正在修改Zabbix配置文件,请稍等~ #"
echo "# #"
echo "#######################################################################"
sed -i 's/# DBPassword=/DBPassword='$Database_Password'/' /etc/zabbix/zabbix_server.conf
if [ $system_type = 'c' ];then
release=cat /etc/redhat-release | awk '{print $4}' | awk -F '.' '{print $1}'
if [ $release = '7' ];then
echo "php_value[date.timezone] = Asia/Shanghai" >> /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
systemctl enable zabbix-server zabbix-agent httpd rh-php72-php-fpm
elif [ $release = '8' ];then
if [ $zbx_v = '5.0' ];then
echo "php_value[date.timezone] = Asia/Shanghai" >> /etc/php-fpm.d/zabbix.conf
elif [ $zbx_v = '5.2' ];then
echo "5.2以上php无需调整"
elif [ $zbx_v = '5.4' ];then
echo "5.2以上php无需调整"
fi
systemctl restart zabbix-server zabbix-agent httpd php-fpm
systemctl enable zabbix-server zabbix-agent httpd php-fpm
fi
elif [ $system_type = 'u' ];then
release=zabbix_server -V | grep zabbix_server | awk '{print $3}' | awk -F '.' '{print $1"."$2}'
if [ $release = '5.0' ];then
sed -i 's/\#\ php_value date.timezone Europe/\Riga/php_value date.timezone Asia/\Shanghai/g' /etc/zabbix/apache.conf
systemctl restart zabbix-server zabbix-agent apache2 mariadb
systemctl enable zabbix-server zabbix-agent apache2 mariadb
elif [ $release = '5.2' ];then
systemctl restart zabbix-server zabbix-agent apache2 mariadb
systemctl enable zabbix-server zabbix-agent apache2 mariadb
elif [ $release = '5.4' ];then
systemctl restart zabbix-server zabbix-agent apache2 mariadb
systemctl enable zabbix-server zabbix-agent apache2 mariadb
fi
fi
echo "开始配置前端"
while :; do echo

read -p "设置前端名称: " front_name
[ -n "$front_name" ] && break

done
while :; do echo

read -p "数据库名称: " db_name
[ -n "$db_name" ] && break

done
while :; do echo

read -p "数据库用户: " db_user
[ -n "$db_user" ] && break

done
while :; do echo

read -p "数据库密码: " db_passwd
[ -n "$db_passwd" ] && break

done
if [ $zbx_v = '5.0' ];then
cat < /etc/zabbix/web/zabbix.conf.php
<?php
// Zabbix GUI configuration file.

&dollar;DB['TYPE'] = 'MYSQL';
&dollar;DB['SERVER'] = 'localhost';
&dollar;DB['PORT'] = '0';
&dollar;DB['DATABASE'] = '$db_name';
&dollar;DB['USER'] = '$db_user';
&dollar;DB['PASSWORD'] = '$db_passwd';

// Schema name. Used for PostgreSQL.
&dollar;DB['SCHEMA'] = '';

// Used for TLS connection.
&dollar;DB['ENCRYPTION'] = false;
&dollar;DB['KEY_FILE'] = '';
&dollar;DB['CERT_FILE'] = '';
&dollar;DB['CA_FILE'] = '';
&dollar;DB['VERIFY_HOST'] = false;
&dollar;DB['CIPHER_LIST'] = '';

// Use IEEE754 compatible value range for 64-bit Numeric (float) history values.
// This option is enabled by default for new Zabbix installations.
// For upgraded installations, please read database upgrade notes before enabling this option.
&dollar;DB['DOUBLE_IEEE754'] = true;

&dollar;ZBX_SERVER = 'localhost';
&dollar;ZBX_SERVER_PORT = '10051';
&dollar;ZBX_SERVER_NAME = '$front_name';

&dollar;IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

// Uncomment this block only if you are using Elasticsearch.
// Elasticsearch url (can be string if same url is used for all types).
//&dollar;HISTORY['url'] = [
// 'uint' => 'http://localhost:9200',
// 'text' => 'http://localhost:9200'
//];
// Value types stored in Elasticsearch.
//&dollar;HISTORY['types'] = ['uint', 'text'];

// Used for SAML authentication.
// Uncomment to override the default paths to SP private key, SP and IdP X.509 certificates, and to set extra settings.
//&dollar;SSO['SP_KEY'] = 'conf/certs/sp.key';
//&dollar;SSO['SP_CERT'] = 'conf/certs/sp.crt';
//&dollar;SSO['IDP_CERT'] = 'conf/certs/idp.crt';
//&dollar;SSO['SETTINGS'] = [];
EOF
else
cat < /etc/zabbix/web/zabbix.conf.php
<?php
// Zabbix GUI configuration file.

&dollar;DB['TYPE'] = 'MYSQL';
&dollar;DB['SERVER'] = 'localhost';
&dollar;DB['PORT'] = '0';
&dollar;DB['DATABASE'] = '$db_name';
&dollar;DB['USER'] = '$db_user';
&dollar;DB['PASSWORD'] = '$db_passwd';

// Schema name. Used for PostgreSQL.
&dollar;DB['SCHEMA'] = '';

// Used for TLS connection.
&dollar;DB['ENCRYPTION'] = false;
&dollar;DB['KEY_FILE'] = '';
&dollar;DB['CERT_FILE'] = '';
&dollar;DB['CA_FILE'] = '';
&dollar;DB['VERIFY_HOST'] = false;
&dollar;DB['CIPHER_LIST'] = '';

// Vault configuration. Used if database credentials are stored in Vault secrets manager.
&dollar;DB['VAULT_URL'] = '';
&dollar;DB['VAULT_DB_PATH'] = '';
&dollar;DB['VAULT_TOKEN'] = '';

// Use IEEE754 compatible value range for 64-bit Numeric (float) history values.
// This option is enabled by default for new Zabbix installations.
// For upgraded installations, please read database upgrade notes before enabling this option.
&dollar;DB['DOUBLE_IEEE754'] = true;

&dollar;ZBX_SERVER = 'localhost';
&dollar;ZBX_SERVER_PORT = '10051';
&dollar;ZBX_SERVER_NAME = '$front_name';

&dollar;IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

// Uncomment this block only if you are using Elasticsearch.
// Elasticsearch url (can be string if same url is used for all types).
//&dollar;HISTORY['url'] = [
// 'uint' => 'http://localhost:9200',
// 'text' => 'http://localhost:9200'
//];
// Value types stored in Elasticsearch.
//&dollar;HISTORY['types'] = ['uint', 'text'];

// Used for SAML authentication.
// Uncomment to override the default paths to SP private key, SP and IdP X.509 certificates, and to set extra settings.
//&dollar;SSO['SP_KEY'] = 'conf/certs/sp.key';
//&dollar;SSO['SP_CERT'] = 'conf/certs/sp.crt';
//&dollar;SSO['IDP_CERT'] = 'conf/certs/idp.crt';
//&dollar;SSO['SETTINGS'] = [];
EOF
fi
echo "#######################################################################"
echo "# 安装已经完成 请移步浏览器 "
echo "# 登录地址为http://$ip/zabbix "
echo "# 数据库密码为$Database_Password,尽情享用吧! "
echo "#######################################################################"

相关实践学习
使用阿里云Elasticsearch体验信息检索加速
通过创建登录阿里云Elasticsearch集群,使用DataWorks将MySQL数据同步至Elasticsearch,体验多条件检索效果,简单展示数据同步和信息检索加速的过程和操作。
ElasticSearch 入门精讲
ElasticSearch是一个开源的、基于Lucene的、分布式、高扩展、高实时的搜索与数据分析引擎。根据DB-Engines的排名显示,Elasticsearch是最受欢迎的企业搜索引擎,其次是Apache Solr(也是基于Lucene)。 ElasticSearch的实现原理主要分为以下几个步骤: 用户将数据提交到Elastic Search 数据库中 通过分词控制器去将对应的语句分词,将其权重和分词结果一并存入数据 当用户搜索数据时候,再根据权重将结果排名、打分 将返回结果呈现给用户 Elasticsearch可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
11天前
|
存储 安全 Linux
CentOS安装SeaweedFS
通过上述步骤,您应该能够在CentOS系统上成功安装并启动SeaweedFS。记住,根据实际部署规模和需求,可能还需要进一步调整配置参数和优化网络布局。SeaweedFS的灵活性和扩展性意味着随着使用深入,您可能需要探索更多高级配置和管理策略。
94 64
|
12天前
|
存储 安全 Linux
CentOS安装SeaweedFS
通过上述步骤,您应该能够在CentOS系统上成功安装并启动SeaweedFS。记住,根据实际部署规模和需求,可能还需要进一步调整配置参数和优化网络布局。SeaweedFS的灵活性和扩展性意味着随着使用深入,您可能需要探索更多高级配置和管理策略。
100 61
|
5天前
|
Linux 网络安全 数据安全/隐私保护
Linux系统之Centos7安装cockpit图形管理界面
【10月更文挑战第12天】Linux系统之Centos7安装cockpit图形管理界面
24 1
Linux系统之Centos7安装cockpit图形管理界面
|
11天前
|
NoSQL 数据可视化 Linux
redis学习四、可视化操作工具链接 centos redis,付费Redis Desktop Manager和免费Another Redis DeskTop Manager下载、安装
本文介绍了Redis的两个可视化管理工具:付费的Redis Desktop Manager和免费的Another Redis DeskTop Manager,包括它们的下载、安装和使用方法,以及在使用Another Redis DeskTop Manager连接Redis时可能遇到的问题和解决方案。
36 1
redis学习四、可视化操作工具链接 centos redis,付费Redis Desktop Manager和免费Another Redis DeskTop Manager下载、安装
|
8天前
|
NoSQL Linux Redis
Docker学习二(Centos):Docker安装并运行redis(成功运行)
这篇文章介绍了在CentOS系统上使用Docker安装并运行Redis数据库的详细步骤,包括拉取Redis镜像、创建挂载目录、下载配置文件、修改配置以及使用Docker命令运行Redis容器,并检查运行状态和使用Navicat连接Redis。
64 3
|
8天前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤
本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置服务等,并与使用 RPM 包安装进行了对比,帮助读者根据需求选择合适的方法。编译源码安装虽然复杂,但提供了更高的定制性和灵活性。
64 2
|
10天前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤
【10月更文挑战第7天】本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。同时,文章还对比了编译源码安装与使用 RPM 包安装的优缺点,帮助读者根据自身需求选择合适的方法。
19 3
|
14天前
|
安全 Linux 编译器
Centos 7.9如何使用源码编译安装curl最新版本
通过上述步骤,您就能在CentOS 7.9上成功地从源代码编译并安装curl的最新版本。这种方法不仅提供了灵活性,允许您定制编译选项,还确保了软件的最新功能和安全更新得到应用。
26 1
|
9天前
|
安全 Linux 数据库连接
CentOS 7环境下DM8数据库的安装与配置
【10月更文挑战第16天】本文介绍了在 CentOS 7 环境下安装与配置达梦数据库(DM8)的详细步骤,包括安装前准备、创建安装用户、上传安装文件、解压并运行安装程序、初始化数据库实例、配置环境变量、启动数据库服务、配置数据库连接和参数、备份与恢复、以及安装后的安全设置、性能优化和定期维护等内容。通过这些步骤,可以顺利完成 DM8 的安装与配置。
|
13天前
|
缓存 Linux 编译器
【C++】CentOS环境搭建-安装log4cplus日志组件包及报错解决方案
通过上述步骤,您应该能够在CentOS环境中成功安装并使用log4cplus日志组件。面对任何安装或使用过程中出现的问题,仔细检查错误信息,对照提供的解决方案进行调整,通常都能找到合适的解决之道。log4cplus的强大功能将为您的项目提供灵活、高效的日志管理方案,助力软件开发与维护。
32 0