openresty_install.sh
#!/bin/bash
user=nginx
group=nginx
egrep "^$group" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
sudo groupadd $group
fi
sleep 2
egrep "^$user" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
sudo useradd -g $user -s /sbin/nologin -M $group
fi
sleep 2
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
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
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
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
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
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
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
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
sudo systemctl start openresty
sudo systemctl status openresty |grep Active| awk '{print $3}' | cut -d "(" -f2 |cut -d ")" -f1
echo "<<<<<<<<<<<<<<<<<<<<Openresty status is ↓↓↓>>>>>>>>>>>>>>>>>>>>"
sleep 3
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.>>>>>>>>>>>>>>>>>>>>"
根据实际修改