#!/bin/bash
#关闭防火墙和selinux
systemctl stop firewalld && setenforce 0 &>/dev/null
#yum安装mysql5.7.43
#下载安装mysql源
yum -y install https://dev.mysql.com/get/mysql80-community-release-el7-11.noarch.rpm &>/dev/null
#打开5.7.43源关闭8.0的源
yum -y install yum-utils &>/dev/null
if [ $? -eq 0 ];then
echo "工具包安装成功"
else
echo "工具包安装失败"
exit 1
fi
yum-config-manager --disable mysql80-community &>/dev/null
yum-config-manager --enable mysql57-community &>/dev/null
#安装mysql
yum -y install mysql-community-server &>/dev/null
#启动mysql数据库
systemctl start mysqld &>/dev/null
#修改mysql数据库密码
mysqladmin -uroot -p"$(awk '/temporary password/{p=$NF}END{print p}' /var/log/mysqld.log)" password "QQqq123@123" &>/dev/null
if [ $? -eq 0 ];then
echo "mysql数据库密码修改成功"
else
echo "mysql数据库密码修改失败"
exit 2
fi
#安装Zabbix存储库
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm &>/dev/null
yum clean all &>/dev/null
#安装Zabbix server,Web前端,agent
install_bag="zabbix-server-mysql zabbix-agent centos-release-scl"
for i in $install_bag
do
yum -y install $i &>/dev/null
if [ $? -eq 0 ];then
echo "$i 安装成功"
else
echo "$i 安装失败"
exit 3
fi
done
#编辑配置文件 /etc/yum.repos.d/zabbix.repo
sed -i "11s/enabled=0/enabled=1/g" /etc/yum.repos.d/zabbix.repo &>/dev/null
#安装Zabbix前端软件包
zabbix_bag="zabbix-web-mysql-scl zabbix-nginx-conf-scl"
for j in $zabbix_bag
do
yum -y install $j &>/dev/null
if [ $? -eq 0 ];then
echo "$j 安装成功"
else
echo "$j 安装失败"
exit 4
fi
done
#创建初始数据库
mysql -u root -p'QQqq123@123' -e "create database zabbix character set utf8 collate utf8_bin" &>/dev/null
mysql -u root -p'QQqq123@123' -e "create user zabbix@localhost identified by 'QQqq123@123'" &>/dev/null
mysql -u root -p'QQqq123@123' -e "grant all privileges on zabbix.* to zabbix@localhost;flush privileges" &>/dev/null
mysql -u root -p'QQqq123@123' -e "set global log_bin_trust_function_creators = 1" &>/dev/null
#导入初始架构和数据,系统将提示您输入新创建的密码
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p'QQqq123@123' zabbix &>/dev/null
if [ $? -eq 0 ];then
echo "zabbix数据导入成功"
else
echo "zabbix数据导入失败"
exit 5
fi
#导入数据库架构后禁用log_bin_trust_function_creators选项
mysql -uroot -p'QQqq123@123' -e "set global log_bin_trust_function_creators = 0" &>/dev/null
#为Zabbix server配置数据库,编辑配置文件 /etc/zabbix/zabbix_server.conf
sed -i '125 i DBPassword=QQqq123@123' /etc/zabbix/zabbix_server.conf
#修改php-fpm服务启动用户
cat > /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf <<EOF
[zabbix]
user = nginx
group = nginx
listen = /var/opt/rh/rh-php72/run/php-fpm/zabbix.sock
listen.acl_users = nginx
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 200
php_value[session.save_handler] = files
php_value[session.save_path] = /var/opt/rh/rh-php72/lib/php/session/
php_value[max_execution_time] = 300
php_value[memory_limit] = 128M
php_value[post_max_size] = 16M
php_value[upload_max_filesize] = 2M
php_value[max_input_time] = 300
php_value[max_input_vars] = 10000
php_value[date.timezone] = Asia/Shanghai
EOF
#修改文件权限
chown .nginx /var/opt/rh/rh-php72/lib/php/session/
chown nginx.nginx -R /etc/zabbix/web/
#将配置文件中的server模块删除掉
sed -i '37,118d' /etc/opt/rh/rh-nginx116/nginx/nginx.conf
#启动Zabbix server和agent进程,并为它们设置开机自启
systemctl restart zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm &&\
systemctl enable zabbix-server zabbix-agent rh-nginx116-nginx rh-php72-php-fpm &>/dev/null
if [ $? -eq 0 ];then
echo "zabbix5.0安装成功"
else
echo "zabbix5.0安装失败"
fi
One thought on “centos7安装zabbix5.0(nginx)shell小脚本”
Comments are closed.