一张症、在安裝FastDFS之前必須先安裝libevent仓技,安裝libevent步驟如下:
1.下載libevent:
wgethttps://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
2.解壓libevent:
tar?-zxvpf?libevent-2.0.21-stable.tar.gz
3.進入解壓目錄:
cd libevent-2.0.21-stable
4.指定安裝目錄:
./configure --prefix=/usr/local/libevent-2.0.21
5.安裝libevent:
make
make install
二、安裝FastDFS步驟如下:
1.下載FastDFS:
wgethttp://fastdfs.googlecode.com/files/FastDFS_v4.06.tar.gz
2.解壓FastDFS:
tar xvf FastDFS_v4.06.tar.gz
3.進入解壓目錄:
cd FastDFS
4.修改FastDFS的安裝文件:
vi make.sh
TARGET_PREFIX=/usr/local/FastDFS??---安裝路徑
TARGET_CONF_PATH=/etc/fdfs??---配置文件路徑
WITH_LINUX_SERVICE=1???---是否為linux服務(wù)
5.指定libevent的lib目錄:
./make.sh C_INCLUDE_PATH=/usr/local/libevent-2.0.21/include LIBRARY_PATH=/usr/local/libevent-2.0.21/lib
6.安裝FastDFS:
./make.sh install
7.設(shè)置軟連接(否則編譯nginx時會出錯)
ln -sv /usr/local/FastDFS/include/fastcommon /usr/local/include/fastcommon
ln -sv /usr/local/FastDFS/include/fastdfs /usr/local/include/fastdfs
ln -sv /usr/local/FastDFS/lib/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -sv /usr/local/FastDFS/lib/libfastcommon.so.1 /usr/local/lib/libfastcommon.so.1
ln -sv /usr/local/FastDFS/lib/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -sv /usr/local/FastDFS/lib/libfdfsclient.so.1 /usr/local/lib/libfdfsclient.so.1
三俗他、在安裝Nginx之前脖捻,需要安裝gcc、 openssl-devel兆衅、 pcre-devel和zlib-devel軟件庫郭变,具體如下:
yum install gcc-c++
yum install openssl-devel
yum install pcre-devel
yum install zlib-devel
四、安裝Nginx和fastdfs-nginx-module
wgethttp://nginx.org/download/nginx-1.6.0.tar.gz
wgethttp://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz
將安裝包文件上傳到/usr/local中執(zhí)行以下操作:
1.進入文件目錄:
cd /usr/local
2.解壓安裝包:
tar -zxv -f nginx-1.6.0.tar.gz
tar -xvf fastdfs-nginx-module_v1.15.tar.gz
3.修改安裝包目錄名稱:
mv nginx-1.6.0 nginx
4.進入安裝包目錄:
cd /usr/local/nginx
5.配置安裝目錄:
./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf? --add-module=/usr/local/fastdfs-nginx-module/src
6.安裝Nginx:
make
make install
7.修改防火墻:
vi + /etc/sysconfig/iptables
8.添加配置項
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
9.重啟防火墻:
service iptables restart
10.將libfastcommon.so涯保、libfastcommon.so.1诉濒、libfdfsclient.so、libfdfsclient.so.1復(fù)制到/usr/lib夕春,否則nginx啟動會報錯未荒。
Nginx的操作:
啟動:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
或者
cd /usr/local/nginx/sbin
./nginx
如果啟動找不到
error while loading shared libraries: libfdfsclient.so: cannot open shared object file: No such file or directory
error while loading shared libraries: libfastcommon.so: cannot open shared object file: No such file or directory
請使用以下軟連接
[root@localhost lib]# ln -s /usr/local/FastDFS/lib/libfastcommon.so /usr/lib/libfastcommon.so
[root@localhost lib]# ln -s /usr/local/FastDFS/lib/libfastcommon.so /usr/lib64/libfastcommon.so
[root@localhost lib]# ln -s /usr/local/FastDFS/lib/libfastcommon.so /usr/lib64/libfastcommon.so
[root@localhost lib]# ln -s /usr/local/FastDFS/lib/libfdfsclient.so /usr/lib/libfdfsclient.so
[root@localhost lib]# ln -s /usr/local/FastDFS/lib/libfdfsclient.so /usr/lib64/libfdfsclient.so
停止服務(wù):
#查詢nginx主進程號
ps -ef | grep nginx
#停止進程
kill -QUIT 主進程號
#快速停止
kill -TERM 主進程號
#強制停止
pkill -9 nginx
重啟:
/usr/local/nginx/sbin/nginx -s reload
五、配置tracker server:
1. vi /etc/fdfs/tracker.conf
bind_addr=192.168.227.128
base_path=/home/tracker/fastdfs
vi /etc/fdfs/client.conf
base_path=/home/tracker/fastdfs
tracker_server=192.168.20.200:22122
http.tracker_server_port=8080
2.配置防火墻:
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 22122 -j
3.保存配置:
/etc/init.d/iptables save
4.?啟動 tracker
/usr/local/FastDFS/bin/fdfs_trackerd /etc/fdfs/tracker.conf
在啟動時報錯:
/usr/local/bin/fdfs_trackerd: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
執(zhí)行下面的命令即可正常啟動:
echo '/usr/local/libevent-2.0.21/include/' >> /etc/ld.so.conf
echo '/usr/local/libevent-2.0.21/lib/' >> /etc/ld.so.conf
ldconfig
5. 查看監(jiān)聽程序:
netstat -ntpl | grep fdfs
6. 查看日志文件:
cat /home/tracker/fastdfs/logs/trackerd.log
7.添加開機啟動命令行:
vim /etc/rc.d/rc.local
/usr/local/FastDFS/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
六及志、配置storage server
1. vi /etc/fdfs/storage.conf
group_name=group1
bind_addr=192.168.227.130
base_path=/home/storage/fastdfs
store_path0=/home/storage/fastdfs
tracker_server=192.168.227.130:22122
http.server.port=80
2. cp /usr/local/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
3. vi /etc/fdfs/mod_fastdfs.conf
base_path=/home/storage1/fastdfs
group_name=group1
store_path0=/home/stroage1/fastdfs
tracker_server=192.168.227.128:22122
url_have_group_name = true
group_count = 0
4. vi /usr/local/nginx/conf/nginx.conf
location /group1/M00 {
root /home/storage1/fastdfs/data;
ngx_fastdfs_module;
}
5.配置防火墻:
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 23000 -j ACCEPT
6.保存配置:
/etc/init.d/iptables save
7.啟動 storage
/usr/local/FastDFS/bin/fdfs_storaged /etc/fdfs/storage.conf
8. 查看監(jiān)聽程序:
netstat -ntpl | grep fdfs
9. 查看日志文件:
cat /home/storage/fastdfs/logs/storaged.log
七片排、測試:
/usr/local/FastDFS/bin/fdfs_test /etc/fdfs/client.conf upload /etc/passwd
結(jié)果如下:
This is FastDFS client test program v4.06
Copyright (C) 2008, Happy Fish / YuQing
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Pagehttp://www.csource.org/
for more detail.
[2014-06-03 20:26:21] DEBUG - base_path=/home/client/fastdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0
tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=192.168.227.130, port=23000
group_name=group1, ip_addr=192.168.227.130, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKjjglOOkd2AdZiiAAAFng0Nczs9728851
source ip address: 192.168.227.130
file timestamp=2014-06-03 20:26:21
file size=1438
file crc32=218985275
file url:http://192.168.227.130/group1/M00/00/00/wKjjglOOkd2AdZiiAAAFng0Nczs9728851
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKjjglOOkd2AdZiiAAAFng0Nczs9728851_big
source ip address: 192.168.227.130
file timestamp=2014-06-03 20:26:21
file size=1438
file crc32=218985275
file url:http://192.168.227.130/group1/M00/00/00/wKjjglOOkd2AdZiiAAAFng0Nczs9728851_big
在瀏覽器上打開http://192.168.227.130/group1/M00/00/00/wKjjglOOkd2AdZiiAAAFng0Nczs9728851_big
測試成功U弧!率寡!
參考:
http://www.cnblogs.com/zhoulf/archive/2013/02/09/2909653.html
http://blog.csdn.net/gaofuqi/article/details/27052155