centos安装python/supervisor/nginx脚本
"""命令有风险,运行需谨慎"""
1、安装python38
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel gcc
mkdir /tmp/python38
cd /tmp/python38
yum -y install wget
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tar.xz
xz -d Python-3.8.0.tar.xz
tar -xvf Python-3.8.0.tar
cd Python-3.8.0
mkdir /usr/local/python38
./configure --with-ssl --prefix=/usr/local/python38
make && make install
ln -s /usr/local/python38/bin/python3.8 /usr/bin/python3
ln -s /usr/local/python38/bin/python3.8 /usr/bin/python
ln -s /usr/local/python38/bin/pip3.8 /usr/bin/pip3
pip3 install --upgrade pip
if [ -f "/usr/bin/python2" ];then
sed -i "1c #! /usr/bin/python2" /usr/bin/yum
fi
cd .
rm -rf /tmp/python38
2、安装supervisor
#!/usr/bin/env bash
python -m pip install supervisor
systemctl enable supervisor
cp /usr/local/python38/bin/*supervisor* /usr/bin
echo_supervisord_conf > /etc/supervisord.conf
while true; do
read -r -p "请输入supervisor要运行的程序名称(为空表示结束): " run_excute
if [ "$run_excute" == "" ]; then
break
fi
read -r -p "请输入执行命令(如 python /home/test.py >>log.log 2>&1 &): " run_cmd
read -r -p "请输入启动时长(默认5): " run_start_time
if [ "$run_start_time" == "" ]; then
run_start_time="5"
fi
read -r -p "请输入启动失败时的重启次数(默认3): " restart_time
if [ "$restart_time" == "" ]; then
restart_time="3"
fi
res_string="
[program:$run_excute]
command=$run_cmd
startsecs=$run_start_time
startretries=$restart_time
"
echo "$res_string" >> /etc/supervisord.conf
done
while true; do
read -r -p "是否重启supervisor? [y/n]" yes_no
if [ "$yes_no" == "y" ]; then
supervisorctl restart all
break
else
if [ "$yes_no" == "n" ]; then
break
fi
fi
done
3、安装nginx
#!/usr/bin/env bash
yum -y install gcc pcre-devel zlib-devel net-tools wget
mkdir -p /tmp/nginx_install
cd /tmp/nginx_install
wget http://nginx.org/download/nginx-1.21.6.tar.gz
tar -zxf nginx-1.21.6.tar.gz
cd nginx-1.21.6 && ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
make && make install
nginx=/usr/local/nginx/sbin/nginx
$nginx
$nginx -s reload
cd .
rm -rf /tmp/nginx_install