共计 8924 个字符,预计需要花费 23 分钟才能阅读完成。
两台文件 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 文件服务器双机热备实例教程完成
CentOS 6.2 下 fastDFS 的完整安装和配置步骤 http://www.linuxidc.com/Linux/2012-12/75989.htm
FastDFS 在 Ubuntu 下的安装,PHP 客户端 http://www.linuxidc.com/Linux/2012-09/71459.htm
FastDFS 分布式文件服务器安装,及配置,测试 http://www.linuxidc.com/Linux/2012-09/71458.htm
FastDFS 整合 Nginx 问题整理 http://www.linuxidc.com/Linux/2012-09/71232.htm
CentOS 下搭建 FastDFS http://www.linuxidc.com/Linux/2012-09/70995.htm
Ubuntu 安装 FastDFS 全程记录 http://www.linuxidc.com/Linux/2012-03/56377.htm
FastDFS 的详细介绍:请点这里
FastDFS 的下载地址:请点这里
本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-04/115767.htm