编写shell 脚本,一键安装nginx
[root@www ~]# cat onekey_install_nginx.sh
#!/bin/bash
#useradd chenran
id chenran || useradd chenran -s /sbin/nologin chenran
#dowmload nginx
mkdir -p /nginx
cd /nginx
curl -O http://nginx.org/download/nginx-1.19.6.tar.gz
#解压源码包
tar xf nginx-1.19.6.tar.gz
cd nginx-1.19.6
#解决依赖关系
yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc gcc-c++ autoconf automake make
#编译前的配置工作--》Makefile
./configure --prefix=/usr/local/nginx1 --user=chenran --group=chenran --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
#设置直接使用nginx命令就可启nginx动服务
#永久修改path变量,影响全局,
#/etc/profile, /root/.bashrc 影响全局
#/etc/profile, /root/.bash_profile 只影响当前用户
echo "PATH=$PATH:/usr/local/nginx1/sbin" >>/root/.bashrc
#立即执行修改了的环境变量的脚本
source /root/.bashrc
#启动nginx
/usr/local/nginx1/sbin/nginx
#firewalld and selinux
#stop firewall和设置下次开机不启动firewalld
service firewalld stop
systemctl disable firewalld
#临时停止selinux和永久停止selinux
setenforce 0
sed -i '/^SELINUX=/ s/enforcing/disabled/' /etc/sysconfig/selinux
编译安装的参数
--with-http_stub_status_module
状态统计功能
--with-stream
4层负载均衡功能
--with-http_ssl_module
https
--with-http_realip_module
负载均衡器
在转发数据的时候可以让后端的real server知道前端client的IP地址,原因是7层负载均衡可以在HTTP协议里面添加一段标签用于存放client的ip地址
负载均衡器在转发的时候,src ip和dst ip都会改变
如何卸载编译安装的nginx?
删除安装指定的目录
–prefix指定的路径