• 集群部署


    负载均衡(nginx 1.11.2):

    文件结构如下,content文件为网站静态资源文件夹,nginx.conf为配置文件。

    nginx.conf内容如下:

    #user  nobody;
    # multiple workers works !
    worker_processes  8;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    #pcre_jit on;
    
    events {
        worker_connections  8192;
    }
    
    
    http {
        ## 其他配置
        include       mime.types;
        default_type  application/octet-stream;
        client_max_body_size 100M;  ## 页面如果要上传大文件,要加上该属性。
        sendfile        off;
        server_names_hash_bucket_size 128;
        map_hash_bucket_size 64;
        client_body_timeout   10;
        client_header_timeout 10;
        keepalive_timeout     30;
        send_timeout          10;
        keepalive_requests    10;
    
    
         ## 添加两个负载均衡服务,每个管理两个站点(权重weight用来设置负载比例)
         upstream jrlc8811{
             server 10.10.131.40:10045 weight=100 fail_timeout=5;
             server 10.10.131.19:10045 weight=100 fail_timeout=5;
             least_conn;
         }
         upstream jrlc8812{
             server 10.10.131.40:10145 weight=100 fail_timeout=5;
             server 10.10.131.19:10155 weight=100 fail_timeout=5;
             least_conn;
         }
    
    
    
        ##jrlc8811服务配置 
        server {
            listen       8811;
            server_name  10.10.131.40:8811;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            ## Caching Static Files, put before first location
            location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
                expires     14d;
            root     html/;
            #    add_header Vary Accept-Encoding;
            }
            ## 
            location / {
                proxy_pass         http://jrlc8811;
                proxy_set_header   Host             $host;
                proxy_set_header   X-Real-IP        $remote_addr;
                proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            }
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    
        ##jrlc8812服务配置 
        server {
            listen       8812;
            server_name  10.10.131.40:8812;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            ## Caching Static Files, put before first location
            location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
                expires     14d;
            root     html/;
            #    add_header Vary Accept-Encoding;
            }
    
            ##
            location / {
                proxy_pass         http://jrlc8812;
                proxy_set_header   Host             $host;
                proxy_set_header   X-Real-IP        $remote_addr;
                proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            }
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    
    }

    分布式缓存(Redis-x64-3.0.501.msi):

            /// <summary>
            /// 初始化缓存数据
            /// </summary>
            /// <returns></returns>
            static List<PaperVM> LoadPaperCache()
            {
                RedisClient redisClient = new RedisClient(ConfigurationManager.AppSettings["CacheIpAddress"], Convert.ToInt32(ConfigurationManager.AppSettings["CachePortAddress"]));//redis服务IP和端口 6379默认端口
                var redisPaperVM = redisClient.Hashes["PaperVM"];
    
                redisPaperVM.Clear();
                List<PaperVM> list = SvrFactory.Instance.ExamSvr.GetAllPaperList(null).ToList();
                foreach (var item in list)
                {
                    redisPaperVM.Add(item.Id.ToString(), JsonConvert.SerializeObject(item));
                }
    
                return list;
            }
    
            /// <summary>
            /// 加载缓存数据
            /// </summary>
            /// <returns></returns>
            public static List<PaperVM> CurPaperCache()
            {
                RedisClient redisClient = new RedisClient(ConfigurationManager.AppSettings["CacheIpAddress"], Convert.ToInt32(ConfigurationManager.AppSettings["CachePortAddress"]));//redis服务IP和端口 6379默认端口
                var redisPaperVM = redisClient.Hashes["PaperVM"];
                var result = new List<PaperVM>();
                redisPaperVM.ToList().ForEach(x=>
                {
                    result.Add(JsonConvert.DeserializeObject<PaperVM>(x.Value));
                });
    
                if (result == null || result.Count == 0)
                {
                    return LoadPaperCache();
                }
                return result;
            }
    
            /// <summary>
            /// 通过id获取缓存
            /// </summary>
            /// <param name="id"></param>
            /// <param name="value"></param>
            public static PaperVM GetPaperCache(int id)
            {
                string key = id.ToString();
                RedisClient redisClient = new RedisClient(ConfigurationManager.AppSettings["CacheIpAddress"], Convert.ToInt32(ConfigurationManager.AppSettings["CachePortAddress"]));//redis服务IP和端口 6379默认端口
                var redisPaperVM = redisClient.Hashes["PaperVM"];
    
    
                //PaperVM vm
                var json = redisPaperVM[key];
                if (json != null)
                {
                    var vm = JsonConvert.DeserializeObject<PaperVM>(json);
                    return vm;
                }
                else
                {
                    PaperVM vm = SvrFactory.Instance.ExamSvr.GetPaper(id);
                    if (vm != null)
                    {
                        string jsonStr = JsonConvert.SerializeObject(vm);
                        redisPaperVM.Add(key, jsonStr);
                    }
                    return vm;
                }
            }
    
            /// <summary>
            /// 更新或新建缓存
            /// </summary>
            /// <param name="id"></param>
            /// <param name="value"></param>
            public static void SetPaperCache(int id, PaperVM value)
            {
                RedisClient redisClient = new RedisClient(ConfigurationManager.AppSettings["CacheIpAddress"], Convert.ToInt32(ConfigurationManager.AppSettings["CachePortAddress"]));//redis服务IP和端口 6379默认端口
                var redisPaperVM = redisClient.Hashes["PaperVM"];
                redisPaperVM.Add(id.ToString(), JsonConvert.SerializeObject(value));
            }
    
            /// <summary>
            /// 移除
            /// </summary>
            /// <param name="id"></param>
            public static void RemovePaperCache(int id)
            {
                RedisClient redisClient = new RedisClient(ConfigurationManager.AppSettings["CacheIpAddress"], Convert.ToInt32(ConfigurationManager.AppSettings["CachePortAddress"]));//redis服务IP和端口 6379默认端口
                var redisPaperVM = redisClient.Hashes["PaperVM"];
                redisPaperVM.Remove(id.ToString());
            }

    共享session:

    另外,需要确认该机器的注册表值正确,端口号值要一致(注册表中为16进制)。

     [HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesaspnet_stateParameters]

    结束后重启ASP.NET 状态服务,设为自启。

     共享文件:

    1. 在每个站点服务器建立同名,同密码的帐号。并选择账户所有者。

    在运行中输入lusrmgr.msc打开本地用户和组管理界面

     

    创建账户,密码选择“永不过期”

     

    用户属性中,添加隶属账户“administrators”

     

    在每个站点所属的程序池添加标识用户。

     

     在作为文件服务器的机器,创建网络共享文件夹。

    创建文件夹,并添加everyone及IUSER_SHARE权限

     

    文件夹属性中添加网络共享。

     

     为IIS的默认站点添加虚拟目录,路径选择共享文件夹

     

    启用iis中的目录浏览

     

    部分文件无法读取的情况下,添加crossdomain.xml文件,至虚拟目录所在站点的根目录下(Default Web Site)

     

    内容如下(星号*代表允许所有域名的访问):

    <?xml version="1.0" encoding="utf-8"?>
    <cross-domain-policy> 
        <allow-access-from domain="*"/>  
    </cross-domain-policy> 
  • 相关阅读:
    Leetcode(11)-盛最多水的容器
    Leetcode(10)-正则表达式匹配
    Leetcode(104)-二叉树的最大深度
    Leetcode(106)-从中序与后序遍历序列构造二叉树
    Ubuntu多系统安装注意事项
    openstack安装、卸载与启动
    基于数据存储管理的带有头尾指针的双向链表创建实例
    JQuery右键菜单contextMenu插件
    jQuery判断当前浏览器类型
    后台获取登录的IP地址
  • 原文地址:https://www.cnblogs.com/ariter/p/5834136.html
Copyright © 2020-2023  润新知