shell脚本安装OpenResty

openresty_install.sh

#!/bin/bash
## version 2.0
## author:wuzw

# 判断系统有无nginx用户组
user=nginx
group=nginx
egrep "^$group" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
    sudo groupadd $group
fi
sleep 2
# 判断系统有无nginx用户
egrep "^$user" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
    sudo useradd -g $user -s /sbin/nologin -M $group
fi
sleep 2

# 判断rpm目录
if [ ! -d /usr/local/rpm ]; then
	sudo mkdir -p /usr/local/rpm
	sudo chown -R teld:teld /usr/local/rpm
		echo  "<<<<<<<<<<<<<<<<<<<<Directoty /usr/local/rpm created success.>>>>>>>>>>>>>>>>>>>>"
	cd /usr/local/rpm
else
	echo "<<<<<<<<<<<<<<<<<<<<Directoty /usr/local/rpm already exist.>>>>>>>>>>>>>>>>>>>>"
	sudo chown -R teld:teld /usr/local/rpm
	cd /usr/local/rpm
fi
sleep 2

# 创建日志目录,与日志文件
sudo mkdir -p /mnt/data/openresty/logs
sudo chown -R teld:teld /mnt/data/openresty
touch /mnt/data/openresty/logs/access.log
touch /mnt/data/openresty/logs/grafana_2021.log
sleep 2

# 判断repo文件
if [ ! -f "openresty.repo" ]; then
	echo "<<<<<<<<<<<<<<<<<<<<File openresty.repo Not exist, downloading...>>>>>>>>>>>>>>>>>>>>"
	wget https://openresty.org/package/rhel/openresty.repo
	mv openresty.repo /etc/yum.repos.d/
else
	rm -f /usr/local/rpm/openresty.repo
	echo "<<<<<<<<<<<<<<<<<<<<File openresty.repo already exist. deleted ,downloading...>>>>>>>>>>>>>>>>>>>>"
	wget wget https://openresty.org/package/rhel/openresty.repo
	mv openresty.repo /etc/yum.repos.d/
fi
sleep 2

# 更新yum,与安装
echo "<<<<<<<<<<<<<<<<<<<<yum updating...>>>>>>>>>>>>>>>>>>>>"
sudo yum check-update

read -p "Are you sure install openresty?[y/n]" input
echo $input
if [ $input="y" ]; then
	echo "installing..."
	sudo yum install openresty -y
else
	exit 0
fi
sleep 2


# 判断nginx文件
sudo chown -R teld:teld /usr/local/openresty 
cd /usr/local/openresty/nginx/conf

if [ ! -f "nginx.conf" ]; then
	echo "<<<<<<<<<<<<<<<<<<<<File openresty.repo Not exist, touching...>>>>>>>>>>>>>>>>>>>>"
	touch nginx.conf
	sudo chown teld:teld nginx.conf
else
	mv /usr/local/openresty/nginx/conf/nginx.conf /usr/local/openresty/nginx/conf/nginx.conf.bak
	touch nginx.conf
	sudo chown teld:teld nginx.conf
	echo "<<<<<<<<<<<<<<<<<<<<File openresty.repo already exist. renamed ,touching...>>>>>>>>>>>>>>>>>>>>"
fi
sleep 3

# 写入nginx 配置
sudo chmod 666 /usr/local/openresty/nginx/conf/nginx.conf
cat > /usr/local/openresty/nginx/conf/nginx.conf << EOF

# 根据需求填入


EOF
echo "<<<<<<<<<<<<<<<<<<<<nginx.conf file created success>>>>>>>>>>>>>>>>>>>>"
sleep 3

# 写入grafana配置文件

touch /usr/local/openresty/nginx/conf/grafana.conf
sudo chmod 666 /usr/local/openresty/nginx/conf/grafana.conf
cat > /usr/local/openresty/nginx/conf/grafana.conf << EOF

# 根据需求填入

EOF
echo "<<<<<<<<<<<<<<<<<<<<grafana.conf file created success>>>>>>>>>>>>>>>>>>>>"
sleep 3


# 写入lua
mkdir /usr/local/openresty/nginx/conf/script
cd /usr/local/openresty/nginx/conf/script
touch query.lua
sudo chmod 644 /usr/local/openresty/nginx/conf/script/query.lua
cat > /usr/local/openresty/nginx/conf/script/query.lua << EOF

# 根据需要填入

EOF
echo "<<<<<<<<<<<<<<<<<<<<query.lua file created success>>>>>>>>>>>>>>>>>>>>"
sleep 3

# 反向代理设置grafana,追加配置
sudo sed -i '$a [server]' /etc/grafana/grafana.ini
sudo sed -i '$a domain = grafana.teld.net' /etc/grafana/grafana.ini
sudo sed -i '$a root_url = https://grafana.teld.net:443' /etc/grafana/grafana.ini
echo "<<<<<<<<<<<<<<<<<<<<grafana.ini configured success>>>>>>>>>>>>>>>>>>>>"
sleep 3

# 判断证书
if [ ! -d /etc/pki/tls/certs/nginx/ ]; then
	echo  "<<<<<<<<<<<<<<<<<<<<Directoty /etc/pki/tls/certs/nginx/ not exist.>>>>>>>>>>>>>>>>>>>>"
else
	echo "<<<<<<<<<<<<<<<<<<<<Directoty /etc/pki/tls/certs/nginx/ exist.>>>>>>>>>>>>>>>>>>>>"
fi
sleep 3

# 启动openresty
sudo systemctl start openresty

# 查看openresty状态
sudo systemctl status openresty |grep Active| awk '{print $3}' | cut -d "(" -f2 |cut -d ")" -f1
echo "<<<<<<<<<<<<<<<<<<<<Openresty status is ↓↓↓>>>>>>>>>>>>>>>>>>>>"
sleep 3

# 重启grafana
sudo systemctl restart grafana-server
echo "<<<<<<<<<<<<<<<<<<<<Openresty status is ↓↓↓>>>>>>>>>>>>>>>>>>>>"
sudo systemctl status grafana-server |grep Active| awk '{print $3}' | cut -d "(" -f2 |cut -d ")" -f1
sleep 3


echo "<<<<<<<<<<<<<<<<<<<<All things done.>>>>>>>>>>>>>>>>>>>>"

根据实际修改

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Energet!c

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值