#!/bin/bash
#解决软件的依赖关系,需要安装的软件包
yum install epel-release -y
#新建luogan用户和组
id fanwenhao || useradd fanwenhao -s /sbin/nolog
#下载nginx软件
mkdir /fanwenhao99 -p
cd /fanwenhao99
wget https://nginx.org/download/nginx-1.21.4.tar
#解压软件
tar xf nginx-1.21.4.tar.gz
#进入解压后的文件夹
cd nginx-1.21.4
#编译前的配置
if (( $? != 0));then
#执行修改了环境变量的脚本
source /root/.bashrc
#firewalld and selinux
#stop firewall和设置下次开机不启动firewalld
tar xf nginx-1.21.4.tar.gz
#进入解压后的文件夹
#编译前的配置
if (( $? != 0));then
#执行修改了环境变量的脚本
source /root/.bashrc
#firewalld and selinux
#stop firewall和设置下次开机不启动firewalld
make -j 2
#执行修改了环境变量的脚本
source /root/.bashrc
#firewalld and selinux
#stop firewall和设置下次开机不启动firewalld
service firewalld stop
systemctl disable firewalld
#临时停止selinux和永久停止selinux
setenforce 0
sed -i '/^SELINUX=/ s/enforcing/disabled/' /etc/selinux/config
#开机启动
chmod +x /etc/rc.d/rc.local
echo "/usr/local/scfanwenhao99/sbin/nginx" >>/etc/rc.local
#修改nginx.conf的配置,例如:端口号,worker进程>数,线程数,服务域名
sed -i '/worker_processes/ s/1/2/' /usr/local/scfanwenhao99/conf/nginx.conf
sed -i '/worker_connections/ s/1024/2048/' /usr/local/scfanwenhao99/conf/nginx.conf
sed -i -r '36c \\tlisten 80;' /usr/local/scfanwenhao99/conf/nginx.conf
sed -i -r '37c \\tserver_name www.fanwenhao.com;' /usr/local/scfanwenhao99/conf/nginx.conf
#killall nginx进程
killall -9 nginx
#启动nginx
/usr/local/scfanwenhao99/sbin/nginx