Centos7一键安装zabbix5脚本

本文涉及的产品
检索分析服务 Elasticsearch 版,2核4GB开发者规格 1个月
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,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可以用于搜索各种文档。它提供可扩展的搜索,具有接近实时的搜索,并支持多租户。
相关文章
|
2天前
|
运维 安全 Linux
如何在CentOS7一键安装宝塔面板并实现固定地址访问内网宝塔进行管理
如何在CentOS7一键安装宝塔面板并实现固定地址访问内网宝塔进行管理
|
2天前
|
Linux 测试技术 数据安全/隐私保护
CentOS安装MeterSphere并实现无公网IP远程访问本地测试平台
CentOS安装MeterSphere并实现无公网IP远程访问本地测试平台
|
3天前
|
Linux Docker 容器
centos7安装docker图文详解
该文档提供了在CentOS上安装Docker的步骤:检查系统内核版本(需大于3.10),更新yum,卸载旧版Docker,安装yum-utils和依赖包,设置Docker仓库,列出并选择Docker版本,安装Docker,最后启动并设置Docker开机启动,通过`docker version`验证安装是否成功。
|
4天前
|
关系型数据库 MySQL 应用服务中间件
centos7在线安装jdk1.8+tomcat+mysql8+nginx+docker
现在,你已经成功在CentOS 7上安装了JDK 1.8、Tomcat、MySQL 8、Nginx和Docker。你可以根据需要配置和使用这些服务。请注意,安装和配置这些服务的详细设置取决于你的具体需求。
20 2
|
5天前
|
NoSQL Linux 网络安全
【专栏】如何在 RHEL 8 或者 CentOS 8 上安装 MongoDB?
【4月更文挑战第28天】本文档介绍了如何在RHEL或CentOS 8上安装MongoDB,包括环境准备(系统更新、依赖安装、硬件需求和sudo用户)、导入MongoDB GPG公钥、创建Yum仓库、安装MongoDB社区版,以及后续的基本配置和验证(启动服务、防火墙设置和连接验证)。通过这些步骤,用户可以顺利安装并运行MongoDB,以处理非结构化数据和扩展技术栈。
|
6天前
|
安全 Linux 网络安全
【专栏】如何进行 CentOS 8 最小安装
【4月更文挑战第28天】本文介绍了如何进行CentOS 8的最小安装,包括准备工作(确认硬件兼容性、下载ISO镜像、制作启动盘及备份数据)和安装步骤(选择语言、最小环境、网络设置、安全策略、分区、用户设置及开始安装)。安装后需进行基础配置,如系统更新、SELinux设置、防火墙配置、安装必要软件包和服务优化。最小安装提供了一个精简高效的环境,便于用户根据需求自定义和管理服务器。
|
7天前
|
存储 Linux 持续交付
【docker】CentOS 7上安装Docker的详细过程
【docker】CentOS 7上安装Docker的详细过程
|
9天前
|
Java Shell 应用服务中间件
centos7_tomcat开机自启的shell脚本参考
centos7_tomcat开机自启的shell脚本参考
11 0
|
9天前
|
安全 关系型数据库 Linux
centos7_安装mysql8(局域网访问navicat连接)
centos7_安装mysql8(局域网访问navicat连接)
14 1
|
9天前
|
Linux 云计算 Perl
centos7_安装虚拟机工具
centos7_安装虚拟机工具
16 0

热门文章

最新文章