• linux基础05


    作业一:nginx服务

    1. 二进制安装nginx包

    yum install epel-release && yum install nginx安装epel源和nginx

    2. 作为web服务修改配置文件

    #主服务器nginx配置文件
    vim /etc/nginx/nginx.conf
    #添加服务器组
    upstream webCluster{
     server 192.168.16.192;
     server 192.168.16.191;
     server 192.168.16.190;
    }
    #server添加反向代理
    server {
    	location / {
        	proxy_pass http://webCluster/;
        }
    }
    
    #各web服务器
    vim /etc/nginx/nginx.conf
    server {
    	root /web/;
        index index.html;
    }
    mkdir /web
    

    3. 让配置生效,验证配置

    #关闭防火墙 启动nginx
    systemctl stop firewalld
    systemctl start nginx
    systemctl disable firewalld
    systemctl enable nginx
    

    作业二:nfs服务

    1. 二进制安装nfs

    #主服务器
    yum -y install rpcbind nfs-utils
    cd / && mkdir share
    #编辑etc/exports文件设置共享目录
    echo "/share 192.168.16.0 /24(rw,sync,no_root_squash) " > /etc/exports
    systemctl start nfs
    systemctl enable nfs
    

    2. 作为共享存储挂载在三台web的网站根目录下

    #web服务器
    yum -y install rpcbind nfs-utils
    #设置开机挂载主服务器NFS到/web
    echo "192.168.16.193:/share	/web/	nfs	defaults	0	0" >> /etc/fstab
    reboot
    

    作业三:nginx反向代理三台web

    1. 实现基于轮询的方式调度三台web

    默认的负载均衡模式就是轮询,不需要更改
    论询会以顺序方式将请求分发请求到各台web服务器

    2. 实现基于权重的方式调度三台web

    upstream webCluster{
     server 192.168.16.192 weight=2;
     server 192.168.16.191 weight=1;
     server 192.168.16.190 weight=1;
    }
    

    上述权重设置,在服务器每收到4个请求时会将其中两个请求发到192这台服务器,其余两个请求会分别发给191和190这两台服务器

    3. 实现基于hash的方式调用三台web

    upstream myapp1 {
        ip_hash;
        server 192.168.16.192;
        server 192.168.16.191;
        server 192.168.16.190;
    }
    

    iphash会将请求固定到后端服务器,这样session会话就能得到保持

    作业四:nginx反向代理+三台web+nfs共享存储实现集群配置

    #为所有服务器安装nginx和rpc、nfs
    yum install epel-release
    yum install nginx nfs-utils rpcbind
    #关闭防火墙
    systemctl disable firewalld
    vim /etc/selinux/config
    SELINUX=disabled
    #重启计算机
    reboot
    

    服务均衡服务器配置:

    #主服务器nginx配置文件
    vim /etc/nginx/nginx.conf
    #添加服务器组
    upstream webCluster{
     server 192.168.16.192;
     server 192.168.16.191;
     server 192.168.16.190;
    }
    #server添加反向代理
    server {
    	listen 80;
    	location / {
        	proxy_pass http://webCluster/;
        }
    }
    #负载均衡服务器配置NFS服务
    yum -y install rpcbind nfs-utils
    cd / && mkdir share
    #编辑etc/exports文件设置共享目录
    echo "/share 192.168.16.0 /24(rw,sync,no_root_squash) " > /etc/exports
    #启动nginx和nfs
    systemctl start nginx
    systemctl enable nginx
    systemctl start nfs
    systemctl enable nfs
    

    各web服务器配置:

    #开机挂载nfs目录
    yum -y install rpcbind nfs-utils
    #设置开机挂载主服务器NFS到/web
    echo "192.168.16.193:/share	/web/	nfs	defaults	0	0" >> /etc/fstab
    #nginx配置
    vim /etc/nginx/nginx.conf
    server {
    	listen 80;
        location / {
            index index.html;
    	    root /web/;
        }
    }
    #开机启动nginx然后启动挂载
    systemctl enable nginx
    mount -a
    
  • 相关阅读:
    JVM内存模型
    生产者与消费者的Java实现
    kafka常用命令
    java中join用法
    elasticsearch关于索引切分的实现
    三十六进制加法
    leetCode之Median of Two Sorted Arrays
    腾讯云“动态加速”与“CDN”的区别——浅谈对“动态加速”的理解(可能有误)
    洗澡或游泳等导致的耳朵进水的解决方案
    windows服务器间文件同步搭建步骤搜集
  • 原文地址:https://www.cnblogs.com/anyanyaaaa/p/6591324.html
Copyright © 2020-2023  润新知