赞
踩
- #!/bin/bash
- #function:zabbix
- #author:Mr.xie 20230824
- ##########################################
- if
- [ "$USER" != "root" ]
- then
- echo "错误:非root用户,权限不足!"
- exit 0
- fi
- ###############防火墙及SElinux############
- systemctl stop firewalld && systemctl disable firewalld && echo "防火墙已经关闭"
- sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config && echo "关闭selinux"
- ###############测试外网是否通常############
- ping -c 3 www.baidu.com
- if
- [ $? = 0 ]
- then
- echo "网络正常"
- else
- echo "网络异常"
- exit 1
- fi
- ############### 安装必要文件 ###############
- if rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7; then
- if yum install epel-release.noarch wget vim gcc gcc-c++ lsof chrony tree nmap unzip rsync -y; then
- if rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7; then
- echo "安装成功"
- else
- echo "导入CentOS 7的GPG密钥失败,退出脚本。"
- exit 1
- fi
- else
- echo "安装依赖包执行失败,退出脚本。"
- exit 1
- fi
- else
- echo "导入CentOS 7的GPG密钥失败,退出脚本。"
- exit 1
- fi
- ############### 搭建LAMP平台 ###############
- yum install -y httpd mariadb mariadb-server mariadb-client php php-mysql
- if [ $? -eq 0 ];then
- echo "LNMP平台安装成功"
- systemctl start mariadb.service
- mysqladmin -u root password 123456
- if [ $? -eq 0 ];then
- echo "MYSQL启动成功"
- else
- echo "MYSQL启动失败"
- exit 1
- fi
- else
- echo "LAMP安装失败"
- exit 1
- fi
- sleep 2
- ############### 安装zabbix服务 ###############
- if rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm; then
- if rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7; then
- if yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-get zabbix-agent; then
- echo "安装成功"
- else
- echo "导入CentOS 7的GPG密钥失败,退出脚本。"
- exit 1
- fi
- else
- echo "安装zabbix失败,退出脚本。"
- exit 1
- fi
- else
- echo "安装zabbix失败,退出脚本。"
- exit 1
- fi
- ############### 创建zabbix库 ###############
- mysql -u root -p123456 -e "CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;"
- if [ $? -eq 0 ];then
- echo "创建zabbix库成功"
- else
- echo "创建zabbix库失败"
- exit 1
- fi
- ############### 导入数据 ###############
- cd /usr/share/doc/zabbix-server-mysql-3.0.32/
- zcat create.sql.gz | mysql -u root -p123456 zabbix
- ############### 修改zabbix配置 ###############
- ipadd=$(ip a | grep "inet "|grep "ens33" | awk '{print $2}' | awk -F / '{print $1}')
- sed -i '81s/^# *//' /etc/zabbix/zabbix_server.conf
- sed -i '106s/DBUser=zabbix/DBUser=root/' /etc/zabbix/zabbix_server.conf
- sed -i '107iDBPassword=123456' /etc/zabbix/zabbix_server.conf
- sed -i '/<IfModule mod_php5.c>/a php_value date.timezone Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf
- ############### 启动 ###############
- systemctl start httpd
- if [ $? -eq 0 ];then
- echo "http启动成功"
- systemctl start zabbix-server
- if [ $? -eq 0 ];then
- echo "zabbix-server启动成功"
- systemctl start zabbix-agent
- if [ $? -eq 0 ];then
- echo "zabbix-agent启动成功"
- else
- echo "zabbix-agent启动失败"
- exit 1
- fi
- else
- echo "zabbix-server启动失败"
- exit 1
- fi
- else
- echo "http启动失败"
- exit 1
- fi
- echo -e "\n\033[32m-----------------------------------------------\033[0m"
- echo "通过 http://$ipadd/zabbix/ 访问"
- echo "数据库用户:root 数据库密码:123456"
- echo "登入zabbix默认用户:Admin 密码:zabbix"
用户名:root 密码:123456
使用默认的用户名:admin 密码:zabbix
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。