Shell脚本 离线安装配置web项目及其依赖环境

nginx

离线下载nginx

#!/bin/bash

install_dir=/usr/local
# 安装环境
tar -zxvf pcre-8.45.tar.gz
cd pcre-8.45
./configure
make
make install
echo pcre is ready
cd ..

tar -zxvf libtool-2.4.6.tar.gz
cd libtool-2.4.2
./configure
make
make install
echo libtool is ready
cd ..

tar -zxvf  openssl-1.1.1b.tar.gz
cd  openssl-1.1.1b/
./config
make
make install
echo openssl is ready
cd ..

tar -zxvf  soft/zlib-1.2.13.tar.gz
cd zlib-1.2.13/
./configure 
make
make install
echo zlib is ready
cd ..

tar -zxvf nginx-1.17.5.tar.gz
cd nginx-1.13.9
./configure --with-pcre=../pcre-8.45/ --with-zlib=../zlib-1.2.13/ --with-openssl=../openssl-1.1.1b/ --prefix=$install_dir/nginx
make
make install
echo nginx is ready
cd ..

# 配置nginx
#配置环境变量
echo "export PATH=$install_dir/nginx/sbin:\$PATH" > /etc/profile.d/nginx.sh
source /etc/profile.d/nginx.sh

#创建服务文件
cat > /usr/lib/systemd/system/nginx.service <<EOF

[Unit]
Description=nginx
After=network.target
   
[Service]
Type=forking
ExecStart=$install_dir/nginx/sbin/nginx
ExecReload=$install_dir/nginx/sbin/nginx -s reload
ExecStop=$install_dir/nginx/sbin/nginx -s quit
PrivateTmp= true
   
[Install]
WantedBy=multi-user.target 

EOF
#开机自启
systemctl enable --now nginx

nginx 启动与停止脚本

#!/bin/bash
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL

启动开机自启服务

#!/bin/bash
#启动开机自启服务
#创建服务文件
install_dir=/usr/local
cat > /usr/lib/systemd/system/nginx.service <<EOF

[Unit]
Description=nginx
After=network.target
   
[Service]
Type=forking
ExecStart=$install_dir/nginx/sbin/nginx
ExecReload=$install_dir/nginx/sbin/nginx -s reload
ExecStop=$install_dir/nginx/sbin/nginx -s quit
PrivateTmp= true
   
[Install]
WantedBy=multi-user.target 

EOF
#开机自启
systemctl enable --now nginx

redis

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小龙凤团茶

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

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

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

打赏作者

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

抵扣说明:

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

余额充值