在CentOS7上安装Zabbix3.0

时间:2022-02-08 17:38:08
 #!/bin/bash

 #
# 、配置无人值守的安装,定义安装过程中需要用到的一些信息
#
mysql_root_pw=root_pw
mysql_zabbix_pw=zabbix_pw
DBPassword=$mysql_zabbix_pw
CacheSize=256M
ZBX_SERVER_NAME=My-Zabbix-Server #
# 、配置yum源
# cat /etc/redhat-release |grep -i centos |grep '7.[[:digit:]]' >/dev/null if [[ $? != ]]
then
echo -e "不支持的操作系统,该脚本只适用于CentOS 7.x x86_64 操作系统"
exit
fi rpm -i --force http://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/$(curl -s http://mirrors.aliyun.com/zabbix/zabbix/3.0/rhel/7/x86_64/ |grep release |awk -F '>|<' '{print $3}') &>/dev/null sed -i 's@repo.zabbix.com@mirrors.aliyun.com/zabbix@' /etc/yum.repos.d/zabbix.repo #
# 、使用yum安装Zabbix及必备软件
# yum install -y httpd mariadb-server php gd php-bcmath php-ctype php-xml php-xmlreader php-xmlwriter php-session php-mbstring php-gettext php-ldap OpenIPMI libssh2 fping libcurl libxml2 net-snmp
yum install -y gnutls trousers
yum install -y zabbix-agent zabbix-sender zabbix-get zabbix-server-mysql zabbix-web zabbix-web-mysql #
# 、配置MySQL
# sed -i '/^symbolic-links=0/a character-set-server=utf8\ninnodb_file_per_table=1' /etc/my.cnf
systemctl enable mariadb.service
systemctl start mariadb.service
mysqladmin -uroot password $mysql_root_pw
mysql -h localhost -uroot -p$mysql_root_pw -e "create database zabbix character set utf8;"
mysql -h localhost -uroot -p$mysql_root_pw -e "grant all privileges on zabbix.* to zabbix@localhost identified by '$mysql_zabbix_pw';"
mysql -h localhost -uroot -p$mysql_root_pw -e "flush privileges;" zcat /usr/share/doc/zabbix-server-mysql-3.0.*/create.sql.gz | mysql -uroot -p$mysql_root_pw zabbix #
# 、配置Zabbix
# sed -i "/^# DBPassword=/a DBPassword=$DBPassword" /etc/zabbix/zabbix_server.conf
sed -i "/^# CacheSize=8M/a CacheSize=$CacheSize" /etc/zabbix/zabbix_server.conf sed -i 's/# php_value date.timezone Europe\/Riga/php_value date.timezone Asia\/Shanghai/' /etc/httpd/conf.d/zabbix.conf cp /usr/share/zabbix/conf/zabbix.conf.php.example /etc/zabbix/web/zabbix.conf.php
sed -i "10c \$DB[\"PASSWORD\"] = '$DBPassword';" /etc/zabbix/web/zabbix.conf.php
sed -i "16c \$ZBX_SERVER_NAME = '$ZBX_SERVER_NAME';" /etc/zabbix/web/zabbix.conf.php systemctl enable zabbix-server
systemctl start zabbix-server
systemctl enable httpd
systemctl start httpd firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-port=/tcp
firewall-cmd --permanent --zone=public --add-port=/udp
firewall-cmd --reload setenforce
sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/sysconfig/selinux