接基于分布式文件系统的fastdfs-负载均衡篇(三),本篇主要讲解fastdfs的文件去重
下载Berkeleydb
wget http://download.oracle.com/berkeley-db/db-5.2.28.tar.gz
下载Libevent
wget https://github.com/libevent/libevent/releases/download/release-2.1.11-stable/libevent-2.1.11-stable.tar.gz
下载FastDHT
wget https://codeload.github.com/happyfish100/fastdht/zip/master
cd /root/pkg/ && tar -xf db-5.2.28.tar.gz
cd db-5.2.28/build_unix/ && …/dist/configure --prefix=/usr/local/db-5.2.28
make && make install # make -j 4 加快编译速度
cd /root/pkg
tar -xf libevent-2.1.11-stable.tar.gz
cd libevent-2.1.11-stable && ./configure --prefix=/usr/local/libevent-2.1.11
make && make install #make -j 4 可以加快编译
cd /root/pkg/
unzip fastdht-master.zip
cd fastdht-master
./make.sh
./make.sh install
ls -l /usr/local/bin/fdh*
cp -p /root/pkg/fastdht-master/init.d/fdhtd /usr/local/bin/
cp -p /root/pkg/fastdht-master/conf/fdhtd.conf /etc/fdht/
vim /etc/fdht/fdhtd.conf
port=11411 #fdhtd的服务端口号
base_path=/u01/fastdht #fdhtd的目录
#include /etc/fdht/fdht_servers.conf(本行前有#表示打开,如果想关闭此选项,则应该为##开头)
vim /etc/fdht/fdht_servers.conf
group_count = 2 #有两个group
group0 = 192.168.171.119:11411
group0 = 192.168.171.129:11411
group1 = 192.168.171.139:11411
group1 = 192.168.171.149:11411
vim /etc/fdht/fdht_client.conf
base_path=/u01/fastdht
vim /etc/fdfs/storage.conf
check_file_duplicate=1 #195行,是否检测上传文件已经存在。如果已经存在,则不存在文件内容,建立一个索引链接以节省磁盘空间)
key_namespace=FastDFS #206行,当上个参数设定为1时,在FastDHT中的命名空间
keep_alive=1 #210行,长连接配置选项,如果为0则为短连接 1为长连接
#include /etc/fdht/fdht_servers.conf #217行,可以通过 #include filename 方式来加载 FastDHT servers的配置;#和include之间没有空格)
fdfs_storaged /etc/fdfs/storage.conf restart
119服务器上终端日志输出
129服务器上终端日志输出
139服务器上终端日志输出
149服务器上终端日志输出
fdhtd /etc/fdht/fdhtd.conf -h
119服务器上终端日志输出
129服务器上终端日志输出
139服务器上终端日志输出
149服务器上终端日志输出
排重前,多次上传同一个文件,如下截图
排重后,多次上传同一个文件,如下截图
119服务器
129服务器
group_name=group1 #139和149均修改
group_name=group1 #139和149均修改
group_count = 0 #并注释点对group1和group2的操作
#[group1]
#group_name=group1
#storage_server_port=23000
#store_path_count=1
#store_path0=/u01/fastdfs/fastdfs_storage
#[group2]
#group_name=group2
#storage_server_port=23000
#store_path_count=1
#store_path0=/u01/fastdfs/fastdfs_storage
----------------------------------------------------------------------------------------------------------
cat fn.sh
#!/bin/bash
function fn_ssh(){
for i in `cat /etc/hosts |grep test |awk '{print $1}'`
do
ssh -qn $i "$*" && [ $? -eq 0 ] && echo -e "\033[32m [ Do succuess on $i ] \033[0m" || echo -e "\033[32m [ Do fail on $i ] \033[0m"
done
}
------------------------------------------------------------------------------------------------------
function fn_sync(){
for i in `cat /etc/hosts |grep test |awk '{print $1}'`
do
scp -r $1 $i:$1 && [ $? -eq 0 ] && echo -e "\033[32m [ Do succuess on $i ] \033[0m" || echo -e "\033[32m [ Do fail on $i ] \033[0m"
done
}
------------------------------------------------------------------------------------------------------
function ft_status(){
fdfs_trackerd /etc/fdfs/tracker.conf $1
}
function ft_log(){
tailf /u01/fastdfs/fastdfs_tracker/logs/trackerd.log
}
------------------------------------------------------------------------------------------------------
function fs_status(){
fdfs_storaged /etc/fdfs/storage.conf $1
}
------------------------------------------------------------------------------------------------------
function fs_log(){
tailf /u01/fastdfs/fastdfs_storage/logs/storaged.log
}
------------------------------------------------------------------------------------------------------
function fm_check(){
fdfs_monitor /etc/fdfs/client.conf
}
------------------------------------------------------------------------------------------------------
function fu_file(){
fdfs_upload_file /etc/fdfs/client.conf $1
}
------------------------------------------------------------------------------------------------------
function fh_status(){
/usr/local/bin/fdhtd /etc/fdht/fdhtd.conf $1
}
------------------------------------------------------------------------------------------------------
function fh_log(){
tailf /u01/fastdht/logs/fdhtd.log
}
------------------------------------------------------------------------------------------------------
function fh_check(){
fdht_test /etc/fdht/fdht_client.conf
}
说明:
fn_ssh 为批处理执行命令
fn_sync为批处理同步命令
ft_status为启停fastdfs_tracker服务命令,同理 fs_status,fh_status一样
ft_log为fastdfs_tracker的后台日志,同理fs_log,fh_log一样
fm_check为检查fastdfs集群状态
fu_file为客户端上传文件
fh_check为检测排重服务