AI智能
改变未来

shell一键安装zabbix

shell 一键部署zabbix服务

(注:脚本当中要注意标点符号的中英文切换)

!/bin/bash

#关闭防火墙,关闭selinux

systemctl stop firewalld

setenforce 0

#配置yum源

rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm

if [ -e /etc/yum.repos.d/zabbix.repo ];then

echo \"已存在\"

#安装zabbix组件

yum - y install zabbix-server-mysql zabbix-web-mysql zabbix=agent mariadb mariadb-server

else

echo \"不存在\"exit

fi

systemctl start mariadb

netstat -lnpt |grep 3306

if [ $?-eq 0 ];then

echo \"service is started\"

else

echo \"service not started\"

fi

#数据库的操作

mysql_exec(){

#创建数据库

mysql -e \"create database if not exists zabbix charset utf8;\"

#建立本地账户

mysql -e \"grant all on zabbix.* to \'zabbix\'@\'localhost\' identified by \'123\';\"

#刷新权限

mysql -e \"flush privileges;\"

}

mysql_exec

count=

mysql -e \"use zabbix; shoow tables;\" |grep -v TABLES |grep -v Tables_in_zabbix |wc -l

if [ $count -gt 0];then

echo \"tables is exists\"

elses

#导入数据库

zcat /usr/share/doc/zabbix-server-mysql-4.0.14/create.sql.gz |mysql -uzabbix -p123 zabbix

fi

#修改配置文件

sed -i ‘s/# DBPassword=/DBPassword=123/’ /etc/zabbix/zabbix_server.conf’

#编辑php文件

sed -i ‘s/;date.timezone =/date.timezone = Asia/Shanghai/’ /etc/php.ini

#启动服务

systemctl start httpd zabbix-agent zabbix-server

#验证端口是否存在

netstat -lnpt | grep \” httpd | zabbix |mysql\”

#!/bin/bash#关闭防火墙,关闭selinuxsystemctl stop firewalldsetenforce 0#配置yum源rpm -ivh http://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpmif [ -e /etc/yum.repos.d/zabbix.repo ];thenecho \"已存在\"#安装zabbix组件yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent mariadb mariadb-serverelseecho \"不存在\"exitfisystemctl start mariadbnetstat -lnpt |grep 3306if [ $? -eq 0 ];thenecho \"service is started\"elseecho \"service not started\"fi#数据库的操作mysql_exec(){#创建数据库mysql -e \"create database if not exists zabbix charset utf8;\"#授权mysql -e \"grant all on zabbix.* to zabbix@localhost identified by \'123\';\"#刷新权限mysql -e \"flush privileges;\"}mysql_execcount=`mysql -e \"use zabbix; show tables;\" |grep -v TABLES |grep -v Tables_in_zabbix |wc -l`if [ $count -gt 0 ];thenecho \"tables is exists\"else#导入初始数据库zcat /usr/share/doc/zabbix-server-mysql-4.0.14/create.sql.gz |mysql -uzabbix -p123  zabbixfi#修改配置文件sed -i \'s/# DBPassword=/DBPassword=123/\' /etc/zabbix/zabbix_server.conf#编辑php文件sed -i \'s/\\;date.timezone =/date.timezone = Asia\\/Shanghai/\' /etc/php.ini#启动服务systemctl start httpd zabbix-agent zabbix-server#验证端口是否存在netstat -lnpt | egrep \"httpd|zabbix|mysql\"
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » shell一键安装zabbix