日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

FastDFS-支持雙IP、IPV6

作者:西京刀客 更新時間: 2022-07-26 編程語言

文章目錄

    • FastDFS-支持雙IP特性介紹
    • 雙ip配置
    • FastDFS-支持IPV6
    • 參考

FastDFS-支持雙IP特性介紹

FastDFS V6.0支持雙IP特性介紹
參考URL: https://www.nuomiphp.com/Article/detail/id/87.html
FastDFS6.0.6搭建集群
參考URL: http://www.luyixian.cn/news_show_381479.aspx

v6.0支持雙IP,tracker server和storage server均支持雙IP。

v6.0新增特性說明如下:

支持雙IP,一個內網IP,一個外網IP,支持NAT方式的內網和外網雙IP,解決跨機房或混合云部署問題。雙ip特性可以解決這個外網和跨云的問題。

tracker server 和 storage server均可支持雙IP,一個內網IP,一個外網IP。

FastDFS支持雙IP特性后,將完全兼容以前單IP的設計和邏輯。對于storage server要使用雙IP特性,必須使用FastDFS V4.0引入的storage server id特性,也就是把雙IP配置到 storage_ids.conf 中。

雙ip連接規則

  1. storage 連接storage server,優先嘗試連接內網IP,失敗了再嘗試連接外網IP。

  2. client向tracker server獲取storage server IP,tracker server采用規則如下:
    外網過來的請求,返回外網IP;
    內網過來的請求,返回內網IP。

內網IP地址段為:10. 打頭,192.168. 打頭以及 172.[16-32). 打頭的IP地址。注:[10-32)為范圍表示方式,表示大于等于10且小于32的整數。

雙ip配置

  1. 配置 tracker

    vim /etc/fdfs/tracker.conf
    
    # 需要修改的內容如下
     
    # 注意服務器是 NAT 方式所以此處綁定的是內網 IP 可以在阿里云后臺看到
    # 可以使用命令查看 ifconfig -a 沒有公網的IP
    bind_addr = 172.xxx.xxx.xxx
     
    # tracker 服務器端口(默認22122,一般不修改)
    port=22122
     
    # 存儲日志和數據的根目錄 
    base_path=/home/dfs 
     
    # use_storage_id 設置為 true 后需要在 storage_ids.conf 設置雙 IP 
    # 原注釋如下:
    # if use storage server ID instead of IP address
    # if you want to use dual IPs for storage server, you MUST set
    # this parameter to true, and configure the dual IPs in the file
    # configured by following item "storage_ids_filename", such as storage_ids.conf
    # default value is false
    # since V4.00
    use_storage_id = true
    

    use_storage_id 設置為 true 后需要在 storage_ids.conf 設置雙 IP

  2. 配置 storage_ids.conf

    # <id>  <group_name>  <ip_or_hostname[:port]>
    #
    # id is a natural number (1, 2, 3 etc.),
    # 6 bits of the id length is enough, such as 100001
    #
    # storage ip or hostname can be dual IPs seperated by comma,
    # one is an inner (intranet) IP and another is an outer (extranet) IP,
    # or two different types of inner (intranet) IPs
    # for example: 192.168.2.100,122.244.141.46
    # another eg.: 192.168.1.10,172.17.4.21
    #
    # the port is optional. if you run more than one storaged instances
    # in a server, you must specified the port to distinguish different instances.
    # 一個內網 IP 一個公網 IP
    100001   group1  172.XXX.XXX.XXX,123.XXX.XXX.XXX
    100002   group1  172.XXX.XXX.XXX,123.XXX.XXX.XXX
    
  3. 配置 storage

    vim /etc/fdfs/storage.conf
    
    # 需要修改的內容如下
     
    # storage服務端口(默認23000,一般不修改)
    port=23000
     
    # 數據和日志文件存儲根目錄  
    base_path=/home/dfs
     
    # 第一個存儲目錄  
    store_path0=/home/dfs  
     
    # 重點是這個,一定注意格式     內網,外網:端口號
    # 重點是這個,一定注意格式     內網,外網:端口號
    # 重點是這個,一定注意格式     內網,外網:端口號
    # tracker_server can ocur more than once for multi tracker servers.
    # the value format of tracker_server is "HOST:PORT",
    #   the HOST can be hostname or ip address,
    #   and the HOST can be dual IPs or hostnames seperated by comma,
    #   the dual IPS must be an inner (intranet) IP and an outer (extranet) IP,
    #   or two different types of inner (intranet) IPs.
    #   for example: 192.168.2.100,122.244.141.46:22122
    #   another eg.: 192.168.1.10,172.17.4.21:22122
    tracker_server = 192.168.2.100,122.244.111.111:22122
    tracker_server = 192.158.2.100,123.244.222.222:22122
     
    # http訪問文件的端口(默認8888,看情況修改,和nginx中保持一致)
    http.server_port=8888
    

storage server要使用雙IP的話,需要啟動storage server id特性,在tracker.conf中將use_storage_id設置為true,需要將storage server雙IP配置到storage_ids.conf中。

FastDFS-支持IPV6

官方HISTORY 關鍵字 IPv6
Version 1.41 2019-09-30

  • change CIDR network_bits range from [16, 32) to [10, 32)
  • ini_file_reader.c: fix empty string compare
  • multi_socket_client.c: code refine
  • sockopt.[hc] support IPv6

查看源碼 sockopt.c,可以看到 加入ipv6的判斷,使用的函數都是支持ipv6的函數,如:
inet_pton 函數是隨IPv6出現的函數,對于IPv4地址和IPv6地址都適用,函數中p和n分別代表表達(presentation)和數值(numeric)。

typedef struct sockaddr_convert_s {
    socklen_t len;
    union {
        struct sockaddr addr;
        struct sockaddr_in addr4;
        struct sockaddr_in6 addr6;
    } sa;
} sockaddr_convert_t;
...

int setsockaddrbyip(const char *ip, const short port, sockaddr_convert_t *convert)
{
    int af;
    void *dest;

    if (is_ipv6_addr(ip))
    {
        convert->len = sizeof(convert->sa.addr6);
        dest = &convert->sa.addr6.sin6_addr;

        af = AF_INET6;
        convert->sa.addr6.sin6_family = PF_INET6;
        convert->sa.addr6.sin6_port = htons(port);
    }
    else  //ipv4
    {
        convert->len = sizeof(convert->sa.addr4);
        dest = &convert->sa.addr4.sin_addr;

        af = AF_INET;
        convert->sa.addr4.sin_family = PF_INET;
        convert->sa.addr4.sin_port = htons(port);
    }

    if (inet_pton(af, ip, dest) == 0)
    {
		logError("file: "__FILE__", line: %d, "
			"invalid %s ip address: %s", __LINE__,
            (af == AF_INET ? "IPv4" : "IPv6"), ip);
        return EINVAL;
    }
    return 0;
}

參考

FastDFS6.0.6搭建集群
參考URL: http://www.luyixian.cn/news_show_381479.aspx

原文鏈接:https://blog.csdn.net/inthat/article/details/106139228

欄目分類
最近更新