演示:
一個tracker和一個storage的安裝(除了明確指出是哪個服務(wù)器來安裝的番川,其他未作特殊說明的都是兩個服務(wù)器一起安裝)
準(zhǔn)備:
1绿满、打開端口(可放在最后一步功茴,根據(jù)配置文件中的配置進(jìn)行打開)
# firewall-cmd --add-port=22122/tcp --permanent &
# firewall-cmd --add-port=22/tcp --permanent &
# firewall-cmd --add-port=8888/tcp --permanent &
# firewall-cmd --add-port=9270/tcp --permanent &
# firewall-cmd --add-port=23000/tcp --permanent &
# firewall-cmd --reload
2落追、登陸root賬戶
3叠赐、安裝yum install gcc?yum install make cmake gcc-c++ git wget
為nginx做準(zhǔn)備:
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel
下載所需要的安裝包:
1、進(jìn)入放置安裝包的目錄:
?? ??#?mkdir -p?/usr/local/fastDfs
?? ??#?cd??/usr/local/fastDfs
2五鲫、選擇最新的fastdfs包(tar.gz):https://github.com/happyfish100/fastdfs/releases
2.1挽封、下載安裝包到當(dāng)前目錄
#?wget?https://github.com/happyfish100/fastdfs/archive/V5.12.tar.gz??-SO fastdfs.tar.gz
#?tar -zxvf?fastdfs.tar.gz?
?? ??? ??? ?ps:如果將安裝包解壓到其他文件則:tar -zxvf?fastdfs.tar.gz?-C /usr/local/fast?
3、 選擇最新的libfastcommon(tar.gz):https://github.com/happyfish100/libfastcommon/releases
#?wget?https://github.com/happyfish100/libfastcommon/archive/V1.0.40.tar.gz?-SO libfastcommon.tar.gz
#?tar -zxvf??libfastcommon.tar.gz
4臣镣、(下載到storage服務(wù)器上)https://github.com/happyfish100/fastdfs-nginx-module下載fastdfs-nginx-module:
?? ?? ? ?# git clone?https://github.com/happyfish100/fastdfs-nginx-module.git?
5、(下載到storage服務(wù)器上)nginx:
?? ?? ? ?# wget?http://nginx.org/download/nginx-1.10.3.tar.gz
?? ?? ? ???#??tar -zxvf??nginx-1.10.3.tar.gz
6智亮、(下載到storage服務(wù)器上)https://ftp.pcre.org/pub/pcre/選擇最新的pcre:
?? ?? ? ?# wget?https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
?? ?? ? ???#??tar -zxvf??pcre-8.43.tar.gz
進(jìn)入解壓目錄并進(jìn)行安裝:
1忆某、安裝 libfastcommon:
?? ??# cd?/usr/local/fastDfs/libfastcommon-1.0.40
?? ??#?./make.sh(權(quán)限不夠時:chmod +x??***.sh)
#?./make.sh install
libfastcommon.so默認(rèn)安裝到了/usr/lib64/libfastcommon.so,但是FastDFS主程序設(shè)置的lib目錄是/usr/local/lib阔蛉,所以此處重新設(shè)置軟鏈接:
?? ??# 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
2弃舒、安裝 fastdfs:
?? ??#?cd /usr/local/fastDfs/fastdfs-5.12/
?? ??#?./make.sh
?? ??#?./make.sh install
安裝好后,fdfs_trackerd等命令是在/usr/bin目錄下:
?? ??? ??#?which?fdfs_trackerd
?? ??? ??? /usr/bin/fdfs_trackerd
所以為啟動腳本創(chuàng)建軟鏈接:
?? ??# ?ln -s /usr/bin/fdfs_trackerd??/usr/local/bin
?? ??# ?ln -s /usr/bin/fdfs_storaged??/usr/local/bin
?? ??# ?ln -s /usr/bin/stop.sh???/usr/local/bin
?? ??# ?ln -s /usr/bin/restart.sh???/usr/local/bin
而配置文件是在/etc/fdfs目錄下:
?? ??? ???#?ls /etc/fdfs
?? ??? ??? ?client.conf.sample??storage.conf.sample??storage_ids.conf.sample??tracker.conf.sample
3状原、storage安裝pcre:
?? ??#?cd?/usr/local/fastDfs/pcre-8.43
?? ??#?./configure --prefix=/usr/local/fastDfs/pcre-8.43
?? ??#?make && make install
[if !supportLists]4聋呢、[endif]storage安裝nginx:
進(jìn)入 ngnix目錄:
?? ?? # cd?/usr/local/fastDfs/nginx-1.10.3
加入模塊命令(權(quán)限不夠時:?chmod +x configure):
?? ?? #?./configure --add-module=/usr/local/fastDfs/fastdfs-nginx-module/src/
?? ??編譯命令:
?? ?? #?make && make install
拷貝配置文件到/etc/fdfs目錄下:
?? ?1、由于/etc/fdfs中的配置文件都是模板颠区,而且不全削锰,所以需要從fastdfs-5.12/conf/包中將所有配置文件拷貝過來,并修改配置:
?? ?????#?cd? /usr/local/fastDfs/fastdfs-5.12/conf
?? ?????# ls
?? ???????anti-steal.jpg client.conf http.conf mime.types storage.conf storage_ids.conf tracker.conf
?? ?????#?cp?/usr/local/fastDfs/fastdfs-5.12/conf/* /etc/fdfs
?????2毕莱、另將storage中的mod_fastdfs.conf拷貝到/etc/fdfs目錄下:
?? ??? ?#?cp?/usr/local/fastDfs/fastdfs-nginx-module/src/mod_fastdfs.conf?/etc/fdfs?
?修改配置文件:
1器贩、#?vi /etc/fdfs/tracker.conf【tracker服務(wù)器修改此配置文件】
# the tracker server port
port=22122
# the base path to store data and log files
base_path=/home/fastdfs/fastdfs_tracker
# HTTP port on this tracker server
http.server_port=9270
保存后颅夺,要確保/home/fastdfs/fastdfs_tracker目錄存在,不存在則創(chuàng)建目錄
?? 啟動tracker蛹稍,/home/fastdfs/fastdfs_tracker目錄下生成data和log目錄以及文件:
? ???? ???#?fdfs_trackerd /etc/fdfs/tracker.conf start?
2吧黄、#?vi?/etc/fdfs/storage.conf【storage服務(wù)器修改此配置文件】
# storage所屬的組
group_name=group1
# the storage server port
port=23000
# the base path to store data and log files
base_path=/home/fastdfs/fastdfs_storage
# store_path#, based 0, if store_path0 not exists, it's value is base_path# the paths must be exist
store_path0=/home/fastdfs/fastdfs_storage
#store_path1=/home/caibh/fdfs2
# tracker服務(wù)器,即使tracker和storage在同一個服務(wù)器,此處也不能寫127.0.0.1唆姐。這項配置可以出現(xiàn)一次或多次
tracker_server=tracker的ip:22122
# the port of the web server on this storage server
http.server_port=8888
????確保/home/fastdfs/fastdfs_storage目錄存在拗慨,不存在就創(chuàng)建目錄
????啟動storage,/home/fastdfs/fastdfs_storage生成data和log目錄以及文件:
? ? ?? ? # fdfs_storaged /etc/fdfs/storage.conf start
3奉芦、#? vi /etc/fdfs/client.conf:? ?【client客戶端修改此配置文件赵抢,在工程項目中配置客戶端的話,可以先部件進(jìn)行配置仗阅,此處是直接在linux上配置并使用】
# the base path to store log files
base_path=/home/fastdfs/fastdfs_client
# tracker_server can ocur more than once, and tracker_server format is#??"host:port", host can be hostname or ip address
tracker_server=tracker的ip:22122
# tracker_server=tracker2的ip:22122
#HTTP settings
http.tracker_server_port=9270
確保/home/fastdfs/fastdfs_client目錄存在昌讲,不存在就創(chuàng)建目錄
4、# vi /etc/fdfs/mod_fastdfs.conf【storage服務(wù)器修改此配置文件减噪,為nginx使用】:
# the base path to store log files
base_path=/home/fastdfs/fastdfs_storage?#修改成和storage 存放路徑一致
# FastDFS tracker_server can ocur more than once, and tracker_server format is#??"host:port", host can be hostname or ip address# valid only when load_fdfs_parameters_from_tracker is true
tracker_server=tracker的ip:22122?
# tracker_server=tracker2的ip:22122
# the port of the local storage server# the default value is 23000
storage_server_port=23000
url_have_group_name = true??#url中是否包組名(默認(rèn)為false短绸,需要改成true)
# the group name of the local storage server
group_name=group1
# store_path#, based 0, if store_path0 not exists, it's value is base_path# the paths must be exist# must same as storage.conf
store_path0=/home/fastdfs/fastdfs_storage??#修改成和storage 存放路徑一致
#store_path1=/home/yuqing/fastdfs1
# set the group count
# set to none zero to support multi-group on this storage server
# set to 0 ?for single group only
# groups settings section as [group1], [group2], ..., [groupN]
# default value is 0
# since v1.14
group_count = 0 ?#0代表單組,非零代表多組筹裕,一般設(shè)置幾就為幾組醋闭,0時則不用寫[group1]、[group2]
# [group1] ?#設(shè)置了group_count = 2朝卒,接下來就需要在文件尾部追加這2個group setting
# group_name=group1
# storage_server_port=23000
# store_path_count=1
# store_path0=/home/fastdfs/fastdfs_storage
# [group2]
# group_name=group2
# storage_server_port=23000
# store_path_count=1
# store_path0=/home/admin/fastDFS/fastdfs_storage_data
5证逻、#vi /usr/local/nginx/conf/nginx.conf【storage服務(wù)器修改此配置文件】:
?? ??? ??server {
????????listen???????9270;
????????server_name??localhost;
????????#charset koi8-r;
????????#access_log??logs/host.access.log??main;
????????location ~/group([0-9])/M00?{
????????????root???/usr/local/fastDfs;
????????????index??index.html index.htm;
??????????ngx_fastdfs_module;
??????? }
?? ?# ln -s /usr/share/nginx/sbin/nginx /usr/sbin/nginx
?? ?# fdfs_storaged /etc/fdfs/storage.conf start
?? ?# tail -n10 /home/fastdfs/fastdfs_storage/logs/storaged.log
?? ?# ln -s /home/fastdfs/fastdfs_storage/data??/home/fastdfs/fastdfs_storage/data/M00
配置過程中有幾點(diǎn)要注意:
*最后要確保配置中用到的目錄已經(jīng)創(chuàng)建了。比如/home/fastdfs/fastdfs_client/client抗斤、/home/fdfs/fdfs_*/data囚企、/home/fdfs/fdfs_*/data/logs
*確保各種配置文件之間引用的端口一直。比如:
* mod_fastdfs.conf文件中tracker_server的端口應(yīng)該跟tracker.conf中port一致瑞眼;
* mod_fastdfs.conf文件中storage_server_port的端口應(yīng)該跟跟storage.conf中port一致龙宏;
*其他配置或文件雖然不用修改,但是fastdfs-nginx-module模塊會用到:
????* anti-steal.jpg
????* http.conf
* mime.types
最后:
進(jìn)行端口開放(根據(jù)配置文件需要):
# firewall-cmd --add-port=22122/tcp --permanent &
# firewall-cmd --add-port=22/tcp --permanent &
# firewall-cmd --add-port=8888/tcp --permanent &
# firewall-cmd --add-port=9270/tcp --permanent &
# firewall-cmd --add-port=23000/tcp --permanent &
# firewall-cmd --reload
啟動服務(wù)器:
storage服務(wù)器:fdfs_trackerd /etc/fdfs/tracker.conf start
Tracker服務(wù)器:fdfs_storaged /etc/fdfs/storage.conf start
查看日志:
storage服務(wù)器:tail -n10 ~/fdfs/logs/trackerd.log
Tracker服務(wù)器:tail -n10 ~/fdfs/logs/storaged.log
#如果日志顯示有錯誤信息伤疙,需要根據(jù)信息來查找錯誤原因
啟動nginx:
/usr/local/nginx/sbin/nginx
訪問:http://storage的ip:9270银酗,出現(xiàn)welcom頁面表示nginx安裝成功
測試上傳數(shù)據(jù):
fdfs_test /etc/fdfs/client.conf?upload /home/wuchangjing/Jep用法.png
訪問途中網(wǎng)址,進(jìn)行下載或者查看