使用工具:
CentOS Stream release 8
nginx-1.21.6.tar.gz
安装nginx脚本
#!/bin/bash
#解决软件的依赖关系,需要安装的软件包
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc gcc-c++ autoconf automake make#add a user
id=peanuts || useradd peanuts#make a directory for nginx
mkdir -p /nginx
cd /nginx#download nginx source
curl -O https://nginx.org/download/nginx-1.21.6.tar.gz#unzip this file
tar xf nginx-1.21.6.tar.gzcd nginx-1.21.6
#生成编译前的配置工作--》Makefile
./configure --prefix=/usr/local/nginx1 --user=peanuts --group=peanuts --with-threads --with-http_ssl_module --with-http_realip_module --with-http_v2_module --with-file-aio --with-http_stub_status_module --with-stream#编译
make -j 2#编译安装 --》将编译好的二进制程序安装指定目录/usr/local/nginx1
make install#修改PATH变量
echo "PATH=$PATH:/usr/local/nginx1/sbin" >>/root/.bash_profile
#执行修改了环境变量的脚本
source /root/.bash_profile#停止防火墙,开启不启动
service firewalld stop
systemctl disable firewalld
#停止selinux,开机不启动
setenforce 0
sed -i '/^SELINUX=/ s/enforcing/disabled/' /etc/sysconfig/selinux
卸载nginx脚本
#!/bin/bash
rm -rf /usr/local/nginx1
rm -rf /nginx