日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

项目开发中经常有一些被嫌弃的小数据,现在全丢给 FastDFS

發布時間:2023/12/4 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 项目开发中经常有一些被嫌弃的小数据,现在全丢给 FastDFS 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在我們開發項目的時候,經常會遇到大塊數據的問題(2M-100M),比如說保存報表中1w個人的ID號,說實話,這些數據存儲在服務器哪里都被嫌棄,放在redis,mongodb中吧,一下子你就會收到報警信息,因為內存滿了。。。放在mysql吧???你還得建立一個text字段,也沒人這么玩,而且還擔心受怕別人來一個 select * ,這速度你懂的。。。直接放到硬盤吧,沒擴展性,你1T大小的硬盤又能怎樣,照樣撐爆你,放在hadoop里面吧,對.net程序員來說,沒有這個緣分,好不容易微軟有一個.net hadoop sdk,說放棄就放棄了,兼具以上各種特性,最后目光只能落到FastDFS上了。

一:FastDFS

fastDFS的本意是一個分布式的文件系統,所以大家可以上傳各種小文件,包括這篇聊到的那些一個點一個點的數據,同樣你也可以認為是一些小文件,接下來我畫一下它的大概架構圖:

我來解釋一下:

  • fastDFS是按照Group的形式對file進行分組存儲的,這里的group1你可以理解成C盤,group2理解成D盤,所有的數據都是在Group來劃分的。

  • 為了提高讀取性能和熱備份,我們把group1放到了兩臺機器上,大概可能覺得有點浪費,對吧,事實就是這樣。

  • 為了提高擴展性,因為單機是有存儲上限的,這時候你可以再新建一個group2,也就是D盤,放到另外機器上,這樣你就擴容了,對吧。

  • trackerServer主要用來保存group和storage的一些狀態信息,主要和client端進行交互,返回正確的storeage server地址,這個和hadoop的namenode其實是同一個角色的。

  • 這里要注意的一個地方就是,client端在存儲file的時候,需要告訴trackerserver,你需要存儲到哪一個group中,比如group1還是group2?

二:下載安裝【CentOS】

為了方便測試,這里我部署到一臺CentOS上

1. 安裝步驟

1) 下載fastDFS基礎包:https://github.com/happyfish100/libfastcommon/releases

2) 然后下載fast源碼包:https://github.com/happyfish100/fastdfs/releases

3) wget之后,先把libfastcommon給安裝一下

tar?-xzvf?V1.0.36 cd?libfastcommon-1.0.36 ./make.sh?&&?./make.sh?install

再把fastdfs安裝一下。

tar?-xzvf?V5.11 cd?fastdfs-5.11 ./make.sh?&&./make.sh?install

這樣的話,我們的fast就算安裝好了,因為是默認安裝,所以配置文件是在 /etc/fdfs 目錄下,啟動服務在/etc/init.d下。

[root@localhost?~]#?cd?/etc/fdfs [root@localhost?fdfs]#?lsclient.conf?client.conf.sample?storage.conf.sample?storage_ids.conf.sample?tracker.conf.sample[root@localhost?fdfs]#?cd?/etc/init.d [root@localhost?init.d]#?ls fdfs_storaged??fdfs_trackerd??functions??netconsole??network??README [root@localhost?init.d]#

然后再把兩個storage.conf.sample 和 tracker.conf.sample中copy出我們需要配置的文件。

[root@localhost?fdfs]#?cp?storage.conf.sample?storage.conf [root@localhost?fdfs]#?cp?tracker.conf.sample?tracker.conf [root@localhost?fdfs]#?ls client.conf??client.conf.sample??storage.conf??storage.conf.sample??storage_ids.conf.sample??tracker.conf??tracker.conf.sample [root@localhost?fdfs]#?

4) tracker.conf 配置

這個配置文件,主要是配置里面的base_path。

#?the?base?path?to?store?data?and?log?files base_path=/usr/fast/fastdfs-5.11/data/tracker

指定完路徑之后,我們創建一個data文件夾和tracker文件夾。

5) storage.conf 配置

這個配置文件,我們主要配置三樣東西。

  • 本storage服務器的groupname,大家看過架構圖應該也明白了,對吧。

  • 為了提高磁盤讀寫,可以指定本groupname的file存儲在哪些磁盤上。

  • 指定和哪一臺trackerserver進行交互。

# the name of the group this storage server belongs to # # comment or remove this item for fetching from tracker server, # in this case, use_storage_id must set to true in tracker.conf, # and storage_ids.conf must be configed correctly. group_name=group1# the base path to store data and log files base_path=/usr/fast/fastdfs-5.11/data/storage# path(disk or mount point) count, default value is 1 store_path_count=1# store_path#, based 0, if store_path0 not exists, it's value is base_path # the paths must be exist store_path0=/usr/fast/fastdfs-5.11/data/storage/0 #store_path1=/home/yuqing/fastdfs2# tracker_server can ocur more than once, and tracker_server format is # "host:port", host can be hostname or ip address tracker_server=192.168.23.152:22122

然后在data目錄下創建storage和0文件夾

6) 啟動 FastDFS,可以看到22122的端口已經啟動了,說明搭建成功

[root@localhost?~]#?/etc/init.d/fdfs_trackerd?start Starting?fdfs_trackerd?(via?systemctl):????????????????????[??OK??] [root@localhost?~]#?/etc/init.d/fdfs_storaged?start Starting?fdfs_storaged?(via?systemctl):????????????????????[??OK??] [root@localhost?0]#?netstat?-tlnp Active?Internet?connections?(only?servers) Proto?Recv-Q?Send-Q?Local?Address???????????Foreign?Address?????????State???????PID/Program?name???? tcp????????0??????0?0.0.0.0:22122???????????0.0.0.0:*???????????????LISTEN??????4346/fdfs_trackerd?? tcp????????0??????0?192.168.122.1:53????????0.0.0.0:*???????????????LISTEN??????1786/dnsmasq???????? tcp????????0??????0?0.0.0.0:22??????????????0.0.0.0:*???????????????LISTEN??????1129/sshd??????????? tcp????????0??????0?127.0.0.1:631???????????0.0.0.0:*???????????????LISTEN??????1128/cupsd?????????? tcp????????0??????0?0.0.0.0:23000???????????0.0.0.0:*???????????????LISTEN??????4171/fdfs_storaged?? tcp????????0??????0?127.0.0.1:25????????????0.0.0.0:*???????????????LISTEN??????1556/master????????? tcp6???????0??????0?:::22???????????????????:::*????????????????????LISTEN??????1129/sshd??????????? tcp6???????0??????0?::1:631?????????????????:::*????????????????????LISTEN??????1128/cupsd?????????? tcp6???????0??????0?::1:25??????????????????:::*????????????????????LISTEN??????1556/master????????? [root@localhost?0]#?

三:使用C#客戶端

在github上有一個C#的客戶端,大概可以使用一下:https://github.com/smartbooks/FastDFS.Client ? 或者通過nuget上搜一下:

class?Program{static?void?Main(string[]?args){ConnectionManager.InitializeForConfigSection(new?FastDfsConfig(){FastDfsServer?=?new?List<FastDfsServer>(){new?FastDfsServer(){IpAddress="192.168.2.25",Port=22122}}});var?storageNode?=?FastDFSClient.GetStorageNode("group1");var?path?=?FastDFSClient.UploadFile(storageNode,?new?byte[10000],?".txt");var?rsp?=?FastDFSClient.DownloadFile(storageNode,?path);Debug.WriteLine("上傳的文件返回路徑:{0},?下載獲取文件大小:{1}",?path,?rsp.Length);}}

好了,本篇就說這么多,希望對你有幫助。

總結

以上是生活随笔為你收集整理的项目开发中经常有一些被嫌弃的小数据,现在全丢给 FastDFS的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。