⽤nginx做负载均衡服务器,配置动静分离

⽤nginx做负载均衡服务 器,配置动静分离


题目:
后端RS服务器⼀台部署LNMP(nginx1.22+mysql8.0+php8.1),⼀台部署
httpd。
要求nginx和php使⽤编译安装
最后要通过访问nginx负载均衡服务器的IP看到动静分离的效果。

环境准备:

主机 ip 安装的服务
node1 192.168.174.170 lnmp,动态资源
node2 192.168.174.175 nginx,静态资源
node3 192.168.174.177 nginx,做负载均衡

部署LNMP ,做动态资源

nginx安装
//首先关闭防火墙和selinux
[root@node1 ~]# setenforce 0
[root@node1 ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@node1 ~]# systemctl disable  --now firewalld.service 

//创建用户
[root@node1 ~]# useradd -rMs /sbin/nologin nginx

//安装所需要的依赖包
[root@node1 ~]# dnf -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make wget vim

//下载nginx源码包,并解压
[root@node1 ~]# wget https://nginx.org/download/nginx-1.22.0.tar.gz
[root@node1 ~]# tar -xf nginx-1.22.0.tar.gz 
[root@node1 ~]# cd nginx-1.22.0/
[root@node1 nginx-1.22.0]# 

//编译安装
[root@node1 nginx-1.22.0]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-debug \
> --with-http_ssl_module \
> --with-http_realip_module \
> --with-http_image_filter_module \
> --with-http_gunzip_module \
> --with-http_gzip_static_module \
> --with-http_stub_status_module 

//开启编译安装
[root@node1 nginx-1.20.2]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install

//安装成功
[root@node1 nginx-1.22.0]# cd /usr/local/nginx/
[root@node1 nginx]# ls
conf  html  logs  sbin

nginx配置

//配置环境变量
[root@node1 nginx]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@node1 nginx]# source /etc/profile

//启动服务
[root@node1 nginx]# nginx 
[root@node1 nginx]# ss -anlt
State      Recv-Q     Send-Q           Local Address:Port           Peer Address:Port     Process     
LISTEN     0          128                    0.0.0.0:80                  0.0.0.0:*                    
LISTEN     0          128                    0.0.0.0:22                  0.0.0.0:*                    
LISTEN     0          128                       [::]:22                     [::]:* 

//关闭服务,编写service文件,并设置服务开机自启
[root@node1 nginx]# cat > /usr/lib/systemd/system/nginx.service << EOF
> [Unit]
> Description=nginx server daemon
> After=network.target 
> 
> [Service]
> Type=forking
> ExecStart=/usr/local/nginx/sbin/nginx
> ExecStop=/usr/local/nginx/sbin/nginx -s stop
> ExecReload=/bin/kill -HUP \$MAINPID
>  
> [Install]
> WantedBy=multi-user.target
> EOF


[root@node1 nginx]# systemctl daemon-reload
[root@node1 nginx]# systemctl enable --now nginx.service 
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
[root@node1 nginx]# ss -anlt
State      Recv-Q     Send-Q           Local Address:Port           Peer Address:Port     Process     
LISTEN     0          128                    0.0.0.0:80                  0.0.0.0:*                    
LISTEN     0          128                    0.0.0.0:22                  0.0.0.0:*                    
LISTEN     0          128                       [::]:22                     [::]:*

1

mysql安装
//安装依赖包
[root@node1 ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel

//创建apache服务的用户和组
[root@node1 ~]# useradd -r -M -s /sbin/nologin mysql[root@node1 ~]# cd /usr/local/
[root@node1 local]# chown -R mysql.mysql mysql*
[root@node1 local]# ll |gerp mysql
bash: gerp: command not found
[root@node1 local]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值