Centos7一键安装zabbix5脚本

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
简介: 脚本安装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可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
7天前
|
SQL 存储 Linux
从配置源到数据库初始化一步步教你在CentOS 7.9上安装SQL Server 2019
【11月更文挑战第8天】本文介绍了在 CentOS 7.9 上安装 SQL Server 2019 的详细步骤,包括系统准备、配置安装源、安装 SQL Server 软件包、运行安装程序、初始化数据库以及配置远程连接。通过这些步骤,您可以顺利地在 CentOS 系统上部署和使用 SQL Server 2019。
|
8天前
|
SQL 存储 Linux
从配置源到数据库初始化一步步教你在CentOS 7.9上安装SQL Server 2019
【11月更文挑战第7天】本文介绍了在 CentOS 7.9 上安装 SQL Server 2019 的详细步骤,包括系统要求检查与准备、配置安装源、安装 SQL Server 2019、配置 SQL Server 以及数据库初始化(可选)。通过这些步骤,你可以成功安装并初步配置 SQL Server 2019,进行简单的数据库操作。
|
1月前
|
Linux 网络安全 数据安全/隐私保护
Linux系统之Centos7安装cockpit图形管理界面
【10月更文挑战第12天】Linux系统之Centos7安装cockpit图形管理界面
69 1
Linux系统之Centos7安装cockpit图形管理界面
|
15天前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比
本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比。通过具体案例,读者可以了解如何准备环境、下载源码、编译安装、配置服务及登录 MySQL。编译源码安装虽然复杂,但提供了更高的定制性和灵活性,适用于需要高度定制的场景。
49 3
|
16天前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比。
本文介绍了在 CentOS 7 中通过编译源码安装 MySQL 数据库的详细步骤,并与使用 RPM 包安装进行了对比。内容涵盖准备工作、下载源码、编译安装、配置服务、登录设置及实践心得,帮助读者根据需求选择最适合的安装方法。
31 2
|
18天前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。
本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。同时,文章还对比了编译源码安装与使用 RPM 包安装的优缺点,帮助读者根据需求选择最合适的方法。通过具体案例,展示了编译源码安装的灵活性和定制性。
60 2
|
22天前
|
Linux 知识图谱
Centos7安装killall,fuser, killall,pstree和pstree.x11
通过上述步骤,您已在CentOS 7系统中成功部署了killall、fuser、pstree以及pstree.x11,为高效管理系统进程打下了坚实基础。更多关于服务器管理与优化的知识,获取全面技术支持与解决方案。
28 1
|
22天前
|
监控 安全 Linux
CentOS7下安装配置ntp服务的方法教程
通过以上步骤,您不仅能在CentOS 7系统中成功部署NTP服务,还能确保其配置合理、运行稳定,为系统时间的精确性提供保障。欲了解更多高级配置或遇到特定问题,提供了丰富的服务器管理和优化资源,可作为进一步学习和求助的平台。
49 1
|
4天前
|
存储 安全 Linux
VMware安装CentOS7
【11月更文挑战第11天】本文详细介绍了在 VMware 中安装 CentOS 7 的步骤,包括准备工作、创建虚拟机、配置虚拟机硬件和安装 CentOS 7。具体步骤涵盖下载 CentOS 7 镜像文件、安装 VMware 软件、创建和配置虚拟机硬件、启动虚拟机并进行安装设置,最终完成 CentOS 7 的安装。在安装过程中,需注意合理设置磁盘分区、软件选择和网络配置,以确保系统的性能和功能满足需求。
|
1月前
|
NoSQL Linux Redis
Docker学习二(Centos):Docker安装并运行redis(成功运行)
这篇文章介绍了在CentOS系统上使用Docker安装并运行Redis数据库的详细步骤,包括拉取Redis镜像、创建挂载目录、下载配置文件、修改配置以及使用Docker命令运行Redis容器,并检查运行状态和使用Navicat连接Redis。
233 3