两台文件fastDFS文件服务器

服务器A: 192.168.10.157

服务器B:192.168.10.158

上面实现目的:增加一台fastDFS备份服务器(192.168.10.158)做为fastDFS文件服务器(192.168.10.157)的从服务器,这两台fastDFS文件服务器之间实现双机热备。

即:从服务器(192.168.10.158)上面数据永远与主服务器(192.168.10.157)上面数据保持同步,并且随着主服务器(192.168.10.157)上面数据变化而变化。
环境说明
1、fastDFS主服务器 主机名称:Master
系统:CentOS 6.6   IP:192.168.10.157    FastDFS_v5.03.+nginx-1.6.2+libevent-2.0.21-stable
2  fastDFS从服务器 主机名称 :Slave
系统:CentOS 6.6   IP:192.168.10.158    FastDFS_v5.03.+nginx-1.6.2+libevent-2.0.21-stable
备注:作为主从服务器的fastDFS和nginx 版本建议使用同一版本!
开始:
一、安装libevent

明:在两台MySQL服务器192.168.10.157和192.168.21.158上分别进行如下操作,

1、下载libevent-2.0.21-stable.tar.gz

          http://sourceforge.net/  

2、解压并安装配置

tar  -zxvf libevent-2.0.21-stable.tar.gz

cd  libevent-2.0.21-stable

mkdir -p /usr/local/libevnet

./configure --prefix=/usr/local/libevent

make && make install

#为libevent创建软链接到/lib库下,64位系统对应/lib64

ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5

ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5

到此,libevent安装完成!
二、安装fastDFS文件服务器

1、下载lFastDFS_v5.03.tar.gz

         http://sourceforge.net/projects/fastdfs/

2、解压并安装配置

tar zxvf FastDFS_v5.03.tar.gz

cd FastDFS

vim make.sh

#WITH_LINUX_SERVICE=1  /取消此行的注释

./make.sh

./make.sh install

到此,fastDFS安装完成!

涉及ip的文件: /etc/fdfs/storage.conf          /etc/fdfs/client.conf         /etc/fdfs/mod_fastdfs.conf

涉及目录的文件: /etc/fdfs/storage.conf     /etc/fdfs/tracker.conf       /etc/fdfs/client.conf      /etc/fdfs/mod_fastdfs.conf

#trackerd

/usr/local/bin/stop.sh  /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf

/usr/local/bin/restart.sh  /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf

#storaged

/usr/local/bin/stop.sh  /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf

/usr/local/bin/restart.sh  /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf

3、建立存储路径并配置fastDFS_v5.03


   mkdir -p  /www/geebook_storage     #建立storage存储目录

   mkdir -p  /www/geebook_tracker       #建立tracker调度器目录

   mkdir -p  /www/geebook_client          #建立client客户端目录

   cp /etc/fdfs/storage.conf /etc/fdfs/storage.conf-bak    #备份配置文件

   cp /etc/fdfs/tracker.conf /etc/fdfs/tracker.conf-bak       #备份配置文件

   cp /etc/fdfs/client.conf  /etc/fdfs/client.conf-bak           #备份配置文件

   vi  /etc/fdfs/storage.conf                      #修改storage配置文件修改参数

       base_path=/www/geebook_stoarge     # the base path to store data and log files

       store_path0=/www/geebook_storage   # store_path#, based 0, if store_path0 not exists, it's value is base_path

       tracker_server=192.168.10.157          指定tracker server地址 可以有多个同步的IP

       tracker_server=192.168.10.158

   vi /etc/fdfs/tracker.conf    #修改tracker配置文件修改参数


        base_path=/www/geebook_tracker     # the base path to store data and log files

   vi /etc/fdfs/client.conf    #修改client配置文件修改参数

        base_path=/www/geebook_client      # the base path to store log files

        tracker_server=192.168.10.157          指定tracker server地址 可以有多个同步的IP

        tracker_server=192.168.10.158  


三、fastdfs-nginx-mod-install 安装与配置 
      1、安装准备工作    ####重点#####

 cat /etc/fdfs/mod_fastdfs.conf   中必须要有 #include http.conf ,

  cat /etc/fdfs/client.conf       中可以有 #include http.conf , 表示注释 ##include http.conf

#####增加用户和组   adduser --system --no-create-home --disabled-password --disabled-login --group nginx

groupadd nginx

useradd -g nginx -s /bin/false -M nginx

2、下载安装包和相关的依赖包并建立安装目录

 # wget http://nginx.org/download/nginx-1.6.2.tar.gz

# rewrite 模块需要 pcre 库    # wget http://downloads.sourceforge.net/project/pcre/pcre/8.36/pcre-8.36.zip

# ssl 功能需要 openssl 库      # wget http://www.openssl.org/source/openssl-1.0.2.tar.gz

# gzip 模块需要 zlib 库          # wget http://zlib.net/zlib-1.2.8.tar.gz

# ngx_cache_purge 清除缓存

# wget --no-check-certificate https://github.com/FRiCKLE/ngx_cache_purge/archive/master.zip -O ngx_cache_purge-master.zip

# nginx-echo

# wget --no-check-certificate https://github.com/agentzh/echo-nginx-module/archive/master.zip -O echo-nginx-module-master.zip

# nginx-upstream-fair  

# wget --no-check-certificate https://github.com/gnosek/nginx-upstream-fair/archive/master.zip -O nginx-upstream-fair-master.zip

# fastdfs nginx module

# wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz


####centos install

yum -y install gcc g++ gcc-c++ autoconf automake make unzip

yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel

mkdir -p /usr/local/nginx/conf                    mkdir -p /usr/local/nginx/conf/vhost

mkdir -p /usr/local/nginx/logs                     mkdir -p /usr/local/nginx/cache/body

mkdir -p /usr/local/nginx/cache/fastcgi      mkdir -p /usr/local/nginx/cache/uwsgi

mkdir -p /usr/local/nginx/cache/scgi          mkdir -p /usr/local/nginx/cache/proxy

 3、配置安装

  cd  /usr/src/nginx

  tar zxvf nginx-1.6.2.tar.gz

  tar zxvf fastdfs-nginx-module_v1.16.tar.gz

 unzip ngx-cache-purge-master.zip

 unzip echo-nginx-module-master.zip

 unzip nginx-upstream-fair-master.zip

  cd nginx-1.6.2

./configure --prefix=/usr/local/nginx \

--user=nginx \

--group=nginx \

--conf-path=/usr/local/nginx/conf/nginx.conf \

--error-log-path=/usr/local/nginx/logs/error.log \

--http-log-path=/usr/local/nginx/logs/access.log \

--lock-path=/usr/local/nginx/logs/nginx.lock \

--pid-path=/usr/local/nginx/logs/nginx.pid \

--http-client-body-temp-path=/usr/local/nginx/cache/body \

--http-fastcgi-temp-path=/usr/local/nginx/cache/fastcgi \

--http-uwsgi-temp-path=/usr/local/nginx/cache/uwsgi \

--http-scgi-temp-path=/usr/local/nginx/cache/scgi \

--http-proxy-temp-path=/usr/local/nginx/cache/proxy \

--with-pcre-jit \

--with-http_random_index_module \

--with-file-aio \

--with-debug \

--with-http_addition_module \

--with-http_gzip_static_module \

--with-http_realip_module \

--with-http_stub_status_module \

--with-http_sub_module \

--with-poll_module \

--with-http_ssl_module \

--add-module=/usr/src/nginx/echo-nginx-module-master \

--add-module=/usr/src/nginx/nginx-upstream-fair-master \

--add-module=/usr/src/nginx/ngx_cache_purge-master \

--add-module=/usr/src/nginx/fastdfs-nginx-module/src

make


make install

*************************** 配置nginx mod_fastdfs.conf***************************

/etc/fdfs/mod_fastdfs.conf 中必须要有 #include http.conf     注意不是注释 如果是注释是:      ##include http.conf

cp /usr/src/nginx/fastdfs-nginx-module/src/mod_fastdfs.conf     /etc/fdfs/     #复制配置文件到/etc/fdfs/  

cp /etc/fdfs/mod_fastdfs.conf  /etc/fdfs/mod_fastdfs.conf-bak                        #备份初始配置文件

mkdir -p /www/logs

vi /etc/fdfs/mod_fastdfs.conf

   base_path=/www/logs  #the base path to store log files 存放日志文件

  store_path0=/www/geebook_storage  # must same as storage.conf  

  url_have_group_name = ture

  tracker_server=192.168.10.157:22122

  tracker_server=192.168.10.158:22122

  #include http.conf

*************************** 配置nginx.conf***************************

cp    /usr/local/nginx/conf/nginx.conf    /usr/local/nginx/conf/nginx.conf-bak     #备份配置文件



八、测试fastDFS主从服务器双机热备是否成功
1、分别进入fastDFS主从服务器启动各服务

#trackerd

/usr/local/bin/stop.sh  /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf

/usr/local/bin/restart.sh  /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf

tail -f  /www/geebook_storage/logs/*.log    

#storaged

/usr/local/bin/stop.sh  /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf

/usr/local/bin/restart.sh  /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf

tail -f  /www/geebook_tracker/logs/*.log     

#nginx

chown -R nginx.nginx /usr/local/nginx/logs/

/usr/local/nginx/sbin/nginx -s stop

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

tail -f  /usr/local/nginx/logs/*.log    


2、在主
从服务器分别测试上传下载删除查询文件

在主服务器上传文件:/usr/local/bin/fdfs_upload_file  /etc/fdfs/client.conf  /www/geebook_client/a.jpg

返回信息:group1/M00/00/00/wKgKnVTv-lqADpl3AAAs_VD7qBc394.jpg

浏览器访问http://192.168.10.157/group1/M00/00/00/wKgKnVTv-lqADpl3AAAs_VD7qBc394.jpg

浏览器访问http://192.168.10.158/group1/M00/00/00/wKgKnVTv-lqADpl3AAAs_VD7qBc394.jpg

下载文件:/usr/local/bin/fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKgKnVTv-lqADpl3AAAs_VD7qBc394.jpg

删除文件:/usr/local/bin/fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgKnVTv-lqADpl3AAAs_VD7qBc394.jpg

查询服务器 /usr/local/bin/fdfs_monitor /etc/fdfs/client.conf

--------------------------------------------------------------------------------------------------------------------------------------

在主服务器上传文件:/usr/local/bin/fdfs_upload_file  /etc/fdfs/client.conf  /www/geebook_client/b.jpg

返回信息:group1/M00/00/00/wKgKnlTv-2mAdfNQAAA06ICuy-Q058.jpg

浏览器访问http://192.168.10.158/group1/M00/00/00/wKgKnlTv-2mAdfNQAAA06ICuy-Q058.jpg

浏览器访问http://192.168.10.157/group1/M00/00/00/wKgKnlTv-2mAdfNQAAA06ICuy-Q058.jpg

下载文件:/usr/local/bin/fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKgKnlTv-2mAdfNQAAA06ICuy-Q058.jpg  xxx.jpg

删除文件:/usr/local/bin/fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgKnlTv-2mAdfNQAAA06ICuy-Q058.jpg

查询服务器 /usr/local/bin/fdfs_monitor /etc/fdfs/client.conf

删除无效的存储服务器,active时,禁止删除 /usr/local/bin/fdfs_monitor /etc/fdfs/client.conf delete group1 10.0.250.103

####浏览器访问http://存储服务器ip:group1/M00/

------------------------------------------------------------------------------------------------------------

至此,fastDFS文件服务器双机热备实例教程完成