FastDFS分布式文件系统环境介绍
系统:centos6.5_64_mini
FastDFS版本:FastDFS_v5.01
实验节点如下:(注:以下两个节点的安装及配置完全相同)
SERVER1 IP:192.168.100.250
SERVER2 IP:192.168.100.251
1:安装定时同步相关
# yum install -y ntpdate
# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# ntpdate us.pool.ntp.org
2:配置时间同步
# crontab -e
3:输入以下代码
*/10 * * * * /usr/sbin/ntpdate us.pool.ntp.org | logger -t NTP
4:安装相关依赖包
# yum -y install gcc gcc-c++ openssl openssl-devel pcre-devel perl wget
# mkdir /yunwei8/soft
# cd /yunwei8/soft
5:下载所需的安装包至soft文件夹下
# wget http://down.yunwei8.com/soft/linux/libevent-2.0.21-stable.tar.gz
# wget http://down.yunwei8.com/soft/linux/FastDFS_v5.01.tar.gz
# wget http://down.yunwei8.com/soft/linux/fastdfs-nginx-module_v1.15.tar.gz
# wget http://down.yunwei8.com/soft/linux/nginx-1.6.0.tar.gz
6:删除自带libevent
# rpm -qa libevent
# rpm -e --nodeps libevent-1.4.13-4.el6.x86_64
7:安装libevent-2.0.21
# cd /yunwei8/soft/
# tar -zxvf libevent-2.0.21-stable.tar.gz
# cd libevent-2.0.21-stable
# ./configure
# make && make install
8:为libevent创建软链接到/lib库下,64位系统对应/lib64
# ln -s /usr/local/lib/libevent* /lib64/
# ln -s /usr/local/lib/libevent* /lib/
9:安装FastDFS_v5.01
# cd /yunwei8/soft
# tar -zxvf FastDFS_v5.01.tar.gz
# cd FastDFS/
# ./make.sh
# ./make.sh install
10:配置跟踪器tracker server
10.1建立文件夹
# mkdir -p /yunwei8/data/fastdfs
10.2修改tracker参数,找到base_path=/home/yuqing/fastdfs修改如下
# vi /etc/fdfs/tracker.conf
base_path=/yunwei8/data/fastdfs
11:启动tracker服务
# /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
# echo '/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf' >> /etc/rc.local
12:配置存储服务storage server,并修改相关参数
# mkdir -p /yunwei8/data/fastdfs 注:(若tracker和storage在不同服务器则需建立)
# mkdir /yunwei8/data/images
# vi /etc/fdfs/storage.conf
找到base_path=/home/yuqing/fastdfs,修改如下
base_path=/yunwei8/data/fastdfs
找到store_path0=/home/yuqing/fastdfs,修改如下
store_path0=/yunwei8/data/images
找到tracker_server=192.168.209.121:22122,修改如下
tracker_server=192.168.100.251:22122
tracker_server=192.168.100.250:22122
13:启动storage服务
# /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
会显示一长串如下的内容
mkdir data path: 00 ...
mkdir data path: 01 ...
mkdir data path: 02 ...
mkdir data path: 03 ...
mkdir data path: 04 ...
mkdir data path: 05 ...
mkdir data path: 06 ...
写入开机自启动
# echo '/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf' >> /etc/rc.local
14:在storage server安装nginx模块
# cd /yunwei8/soft/
# tar -zxvf fastdfs-nginx-module_v1.15.tar.gz
# tar -zxvf nginx-1.6.0.tar.gz
# cd nginx-1.6.0
# ./configure --prefix=/yunwei8/server/nginx --add-module=../fastdfs-nginx-module/src
# make && make install
15:修改nginx参数配置如下
# vi /yunwei8/server/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location /group1/M00 {
alias /data/images/data;
ngx_fastdfs_module;
}
}
}
16:编写nginx 启动脚本
# vi /etc/init.d/nginx
输入以下代码并保存
#!/bin/sh## nginx - this script starts and stops the nginx daemin## chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \# proxy and IMAP/POP3 proxy server# processname: nginx# config: /yunwei8/server/nginx/conf/nginx.conf# pidfile: /yunwei8/server/nginx/logs/nginx.pid # Source function library.. /etc/rc.d/init.d/functions # Source networking configuration.. /etc/sysconfig/network # Check that networking is up.[ "$NETWORKING" = "no" ] && exit 0 nginx="/yunwei8/server/nginx/sbin/nginx"prog=$(basename $nginx) NGINX_CONF_FILE="/yunwei8/server/nginx/conf/nginx.conf" lockfile=/var/lock/subsys/nginx start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval} stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval} restart() { configtest || return $? stop start} reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo} configtest() { $nginx -t -c $NGINX_CONF_FILE} rh_status() { status $prog} rh_status_q() { rh_status >/dev/null 2>&1} case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; status) rh_status ;; *) echo $"Usage: $0 {start|stop|status|restart|reload|configtest}" exit 2esac
17:保存后,设置权限并添加到启动服务列表中
# chmod 755 /etc/init.d/nginx
# chkconfig --add nginx
# chkconfig --level 345 nginx on
18:启动nginx服务
# service nginx start
19:给storage的存储目录做一个软连接
# ln -s /yunwei8/data/images/data/ /yunwei8/data/images/data/M00
20:拷贝mod_fastdfs.conf到/etc/fdfs/
# cp /yunwei8/soft/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
21:修改mod_fastdfs.conf配置
# vi /etc/fdfs/mod_fastdfs.conf
找到base_path=/tmp,修改为如下
base_path=/yunwei8/data/fastdfs
找到store_path0=/home/yuqing/fastdfs,修改如下
store_path0=/yunwei8/data/images
找到url_have_group_name = fasle,修改如下
url_have_group_name = true
找到tracker_server=tracker:22122,修改如下
tracker_server=192.168.100.251:22122
tracker_server=192.168.100.250:22122
22:在tracker server上配置client
# vi /etc/fdfs/client.conf
修改client参数,找到base_path=/home/yuqing/fastdfs,修改如下
base_path=/yunwei8/data/fastdfs
找到tracker_server=192.168.0.197:22122,修改如下
tracker_server=192.168.100.250:22122
tracker_server=192.168.100.251:22122
23:防火墙开放相应端口
# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
# /sbin/iptables -I INPUT -p tcp --dport 22122-j ACCEPT
# /etc/rc.d/init.d/iptables save
24:创建测试文件
# cd /yunwei8/
创建网页名为yunwei8.html
# vi yuwnei8.html
输入网页内容
yunwei8
25:退出和重启
25.1退出
直接kill即可让server进程正常退出,可以使用killall命令,例如:
# killall fdfs_trackerd
# killall fdfs_storaged
也可以使用FastDFS自带的stop.sh脚本,如:
# /usr/local/bin/stop.sh /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
# /usr/local/bin/stop.sh /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
stop.sh只会停止命令行(包括参数)完全相同的进程。
千万不要使用-9参数强杀,否则可能会导致binlog数据丢失的问题。
25.2重启
可以kill掉server进程后,执行启动命令行。如:
# killall fdfs_trackerd
# killall fdfs_storaged
# /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
# /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
或者直接使用FastDFS自带的restart.sh脚本,如:
# /usr/local/bin/restart.sh /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
# /usr/local/bin/restart.sh /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
26:上传测试 /usr/local/bin/restart.sh /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
# /usr/local/bin/fdfs_test /etc/fdfs/client.conf upload /yunwei8/yunwei8.html (绝对路径)
27:访问上传输出的测试地址
http://192.168.100.250/group1/M00/00/00/wKhk-lNC56-ABoAZAAAAd6SYAsE45_yunwei8.html
http://192.168.100.251/group1/M00/00/00/wKhk-lNC56-ABoAZAAAAd6SYAsE45_yunwei8.html