fastdfs 测试客户端_分布式文件服务 FastDFS (第一篇)
[ 基礎(chǔ)環(huán)境準(zhǔn)備 ]
1.yum install -y gcc gcc-c++
2.yum -y install libevent & vsftpd安裝 &selinux關(guān)閉 防火墻權(quán)限 &Perl安裝
[ libfastcommon類庫安裝]
3.首先安裝libfastcommon類庫,否則報(bào)錯(cuò)【atal error: logger.h: No such file or directory】
4.unzip -o libfastcommon-master.zip -d /usr/local 解壓到該目錄下,進(jìn)入到解壓后的目錄下
./make.sh ./make.sh install
5..建立軟連接(windows相當(dāng)于創(chuàng)建快捷圖標(biāo))
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so
ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
[FastDFS安裝]
./make.sh
./make.sh install
6.cd fastdfs-master
cp -r conf/* /etc/fdfs/
7.將/etc/fdfs目錄下的tracker.conf.sample復(fù)制一份改名為tracker.conf
將/etc/fdfs目錄下的storage.conf.sample復(fù)制一份改名為storage.conf
報(bào)錯(cuò):Perl未安裝
8.cd /etc/fdfs/
cp client.conf.sample client.conf
cp storage.conf.sample storage.conf
cp tracker.conf.sample tracker.conf
FastDFS已經(jīng)安裝完畢,接下來的工作就是依次配置Tracker和Storage
[安裝tracker]
9.創(chuàng)建tracker工作目錄
創(chuàng)建Tracker服務(wù)器的文件路徑,用于存儲Tracker的數(shù)據(jù)文件和日志文件
mkdir /opt/fastdfs
mkdir /opt/fastdfs/tracker
10.cd /etc/fdfs/ vim tracker.conf 配置(4項(xiàng))
1.disabled=false #啟用配置文件(默認(rèn)啟用)
2.port=22122 #設(shè)置tracker的端口號,通常采用22122這個(gè)默認(rèn)端口
3.base_path=/opt/fastdfs/tracker #設(shè)置tracker的數(shù)據(jù)文件和日志目錄
4.http.server_iport=7070 #設(shè)置http端口號,默認(rèn)為8080
11.啟動tracker
service fdfs_trackerd start
或者: systemctl start fdfs_trackerd
12. netstat -unltp|grep fdfs 查看22122端口是否監(jiān)聽
13.將tracker設(shè)置開機(jī)啟動
vim /etc/rc.d/rc.local
增加一行命令 service fdfs_trackerd start,到此tracker配置完成
[安裝storage]
14.創(chuàng)建Storage服務(wù)器的文件目錄,需要注意的是同Tracker相比我多建了一個(gè)目錄,因?yàn)镾torage還需要一個(gè)文件存儲路徑,用于存放接收的文件。
mkdir /opt/fastdfs/storage
mkdir /opt/fastdfs/storage_data
15. 修改storage配置文件
cd /etc/fdfs/
vim storage.conf
修改內(nèi)容:
1.disabled=false #啟用配置文件(默認(rèn)啟用)
2.group_name=group1 #組名,根據(jù)實(shí)際情況修改
3.port=23000 #設(shè)置storage的端口號,默認(rèn)是23000,同一個(gè)組的storage端口號必須一致
4.base_path=/opt/fastdfs/storage #設(shè)置storage數(shù)據(jù)文件和日志目錄
5.store_path_count=1 #存儲路徑個(gè)數(shù),需要和store_path個(gè)數(shù)匹配
6.store_path0=/opt/fastdfs/storage_data #實(shí)際文件存儲路徑
7.tracker_server=192.168.122.1:22122 #tracker 服務(wù)器的 IP地址和端口號,如果是單機(jī)搭建,IP 不要寫127.0.0.1,否則啟動不成功 我用的是我的自己的本機(jī)ip,服務(wù)器就用對外ip
8.http.server_port=8888 #設(shè)置 http 端口號
9.創(chuàng)建軟鏈接 ln -s /usr/bin/fdfs_storaged /usr/local/bin 目的:service 服務(wù)名 啟/停
16.啟動storage
service fdfs_storaged start 如果啟動成功后 /opt/fastdfs/storage 就可以看到 啟動后新生成的data 和 logs 目錄,端口23000也應(yīng)被正常監(jiān)聽。
netstat -unltp|grep fdfs #查看fdfs相關(guān)端口
17.配置開機(jī)啟動:
vim /etc/rc.d/rc.local
底部添加:service fdfs_storaged start
18.查看storage是否注冊到了tracker中
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
19.配置客戶端,修改客戶端配置文件
vim /etc/fdfs/client.conf
修改如下:
1.base_path = /usr/fastdfs_tracker #tracker服務(wù)器文件路徑,這個(gè)文件夾路徑是我自己隨便創(chuàng)建的這么一個(gè)文件夾
2.tracker_server=192.168.122.1:22122 #tracker服務(wù)器IP地址和端口號
3.http.tracker_server_port=7070 # tracker 服務(wù)器的 http端口號,必須和tracker的設(shè)置對應(yīng)起來
20.模擬上傳圖片:/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/yuanzhaoyang/Pictures/runtimeError.png
如果成功 返回: 組名+磁盤+目錄+文件名
圖片會被上傳到 opt/fastdfs/storage_data/data/ cd 00 # ls
21.fastdfs的nginx 模塊安裝 nginx 的依賴包:
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel
我之前安裝過nginx,但是沒添加 fastdfs-nginx-module 模塊,so 我卸載重新安裝,
1.停止nginx systemctl stop nginx;
2.刪除 nginx 的自啟動 chkconfig nginx off
3.rm -rf /usr/sbin/nginx
rm -rf /etc/nginx
rm -rf /etc/init.d/nginx
4.yum remove nginx
5.刪除你安裝nginx目錄
安裝nginx: 我之前寫的一個(gè) nginx文章:https://www.toutiao.com/i6788375484758491660/
1.tra -zxvf nginx-1.13.7.tar.gz #解壓nginx包
unzip fastdfs-nginx-module-master.zi #解壓nginx-module安裝包
2.進(jìn)入到你解壓的nginx 目錄 編譯安裝并添加fastdfs-nginx-module
./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module-master/src
說明一下: --prefix=你要生成的目錄 --add-module=解壓出來nginx-module的模塊文件夾位置
3.make
4.make install
22.配置storage nginx 模塊
cd /usr/local/nginx
cd /conf
vim /nginx.conf
修改內(nèi)容:
1.修改監(jiān)聽端口: 9999
2.新增 location
location ~/group1/M00 {
root /opt/fastdfs/storage_data/data;
ngx_fastdfs_module;
}
3.進(jìn)入到 fastdfs-master/ 目錄下的conf文件 將http.conf和mime.types拷貝到/etc/fdfs目錄下
4.進(jìn)入到fastdfs-nginx-module安裝目錄中src目錄下的mod_fastdfs.conf也拷貝到/etc/fdfs目錄下
5.修改 /etc/fdfs 目錄下的mod_fastdfs.conf
1.base_path=/opt/fastdfs/storage #保存日志目錄
2.tracker_server=192.168.122.1:22122 #tracker服務(wù)器的IP地址以及端口號
3.storage_server_port=23000 #storage服務(wù)器的端口號
4.url_have_group_name = true #文件 url 中是否有 group 名
5.store_path0=/opt/fastdfs/storage_data #存儲路徑
6.group_count = 3 #設(shè)置組的個(gè)數(shù),事實(shí)上這次只使用了group1
7.文件尾部追加3個(gè)group seeting
[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/opt/fastdfs/storage_data
[group2]
group_name=group2
storage_server_port=23000
store_path_count=1
store_path0=/opt/fastdfs/storage_data
[group3]
group_name=group3
storage_server_port=23000
store_path_count=1
store_path0=/opt/fastdfs/storage_data
創(chuàng)建M00至storage存儲目錄的符號連接: ln -s /opt/fastdfs/storage_data/data /opt/fastdfs/storage_data/data/M00
23./usr/local/nginx/sbin/nginx nginx 啟動
24.配置 tracker nginx
1.再解壓一個(gè)nginx
2.cd 到你后解壓的nginx 目錄
./configure --prefix=/usr/local/nginx2 --add-module=/usr/local/fastdfs-nginx-module-master/src #新生成一個(gè)nginx2文件目錄
3.make
4. make install
5. vim /usr/local/nginx2/conf/nginx.conf
我的ngix2監(jiān)聽端口該改成了:9998
#新增
upstream fdfs_group1 {
server 127.0.0.1:9999;
}
#新增
location /group1/M00 {
proxy_pass http://fdfs_group1;
}
/usr/local/nginx2/sbin/nginx #啟動nginx2
25.通過客戶端測試上傳測試:
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/yuanzhaoyang/Pictures/全備completed.png
然后訪問:
http://192.168.122.1:9998/group1/M00/00/00/wKh6AV5wlAyAHIpXAAIB1eFJxZ4541.png
over !
郵箱:yzydevops@163.com
總結(jié)
以上是生活随笔為你收集整理的fastdfs 测试客户端_分布式文件服务 FastDFS (第一篇)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 陕北人裹羊肚毛巾,为何是白色的?
- 下一篇: 为什么说甜点是缓解压力的良药?