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"
2
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#!/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; show tables;" | grep - v TABLES | grep - v Tables_in_zabbix | wc -l` if [ $count -gt 0 ]; then echo "tables is exists" else #导入初始数据库 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 | egrep "httpd|zabbix|mysql" |