yum安装
nginx有两种安装方法、一种是yum安装直接用一条命令去安装依靠的是nginx的安装包需要知道这个安装包的具体地址,这是别人已经做好的,里面的一些功能已经确定,这是是一个以.rpm为后缀名的文件,可以直接安装,相当于window中的以.exe为后缀的安装程序。
编译安装
编译安装相当于定制功能可以自己选择开启或者关闭那些功能。
1、下载源码
2、编译前配置
安装需要用到的软件
yum install epel-release -y
./configure --prefix=/usr/local/nginx99 --user=root
–with-http_ssl_module --with-http_v2_module --with-threads --with-http_stub_status_module --with-stream
3、编译
top可以查看有几个CPU核心
make -j 2
执行后会生成二进制文件(Makefile)
4、编译安装
make install
5、安装成功以后就可以进入安装目录去运行
cd /usr/local/nginx99/sbin
,/nginx
总结
1、将安装nginx编写成脚本执行
#!/bin/bash
#新建文件存放下载源码
mkdir -p /nginx
cd /nginx
#新建用户
useradd -s /sbin/nologin north222
#下载源码
curl -O http://nginx.org/download/nginx-1.23.2.tar.gz
#解压源代码
tar xf nginx-1.23.2.tar.gz
#解决依赖关系,安装需要用到的软件
yum install gcc openssl openssl-devel pcre pcre-devel automake make -y
#编译前的配置
cd nginx-1.23.2
./configure --prefix=/usr/local/nginx99 --user=north222 --with-http_ssl_module --with-http_v2_module --with-threads --with-http_stub_status_module --with-stream
#开启两个进程编译
make -j 2
#安装
make install
#启动nginx
/user/local/nginx99/sbin/nginx
#修改path变量
PATH=$PATH:/usr/local/nginx99/sbin
#永久修改path变量
echo "PATH=$PATH:/usr/local/nginx99/sbin" >>/root/.bashrc
#设置开机启动
echo "/usr/local/nginx99/sbin/nginx" >>/etc/rc.local
chmod +x /etc/rc.d/rc.local
#selinux和firewalld防火墙都关闭
service firewalld stop
systemctl disable firewalld
#临时关闭selinux
setenforce 0
#永久关闭
sed -i '/^SELINUX=/ s/enforcing/disable/' /etc/selinux/config