演示:
一个tracker和一个storage的安装(除了明确指出是哪个服务器来安装的,其他未作特殊说明的都是两个服务器一起安装)
准备:
1、打开端口(可放在最后一步,根据配置文件中的配置进行打开)
# 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做准备:
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel
下载所需要的安装包:
1、进入放置安装包的目录:
# mkdir -p /usr/local/fastDfs
# cd /usr/local/fastDfs
2、选择最新的fastdfs包(tar.gz):https://github.com/happyfish100/fastdfs/releases
2.1、下载安装包到当前目录
# 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服务器上)https://github.com/happyfish100/fastdfs-nginx-module下载fastdfs-nginx-module:
# git clone https://github.com/happyfish100/fastdfs-nginx-module.git
5、(下载到storage服务器上)nginx:
# wget http://nginx.org/download/nginx-1.10.3.tar.gz
# tar -zxvf nginx-1.10.3.tar.gz
6、(下载到storage服务器上)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
进入解压目录并进行安装:
1、安装 libfastcommon:
# cd /usr/local/fastDfs/libfastcommon-1.0.40
# ./make.sh(权限不够时:chmod +x ***.sh)
# ./make.sh install
libfastcommon.so默认安装到了/usr/lib64/libfastcommon.so,但是FastDFS主程序设置的lib目录是/usr/local/lib,所以此处重新设置软链接:
# 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
所以为启动脚本创建软链接:
# 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:
进入 ngnix目录:
# cd /usr/local/fastDfs/nginx-1.10.3
加入模块命令(权限不够时: 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服务器修改此配置文件】
# 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目录存在,不存在则创建目录
启动tracker,/home/fastdfs/fastdfs_tracker目录下生成data和log目录以及文件:
# fdfs_trackerd /etc/fdfs/tracker.conf start
2、# vi /etc/fdfs/storage.conf【storage服务器修改此配置文件】
# 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服务器,即使tracker和storage在同一个服务器,此处也不能写127.0.0.1。这项配置可以出现一次或多次
tracker_server=tracker的ip:22122
# the port of the web server on this storage server
http.server_port=8888
确保/home/fastdfs/fastdfs_storage目录存在,不存在就创建目录
启动storage,/home/fastdfs/fastdfs_storage生成data和log目录以及文件:
# fdfs_storaged /etc/fdfs/storage.conf start
3、# vi /etc/fdfs/client.conf: 【client客户端修改此配置文件,在工程项目中配置客户端的话,可以先部件进行配置,此处是直接在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目录存在,不存在就创建目录
4、# vi /etc/fdfs/mod_fastdfs.conf【storage服务器修改此配置文件,为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中是否包组名(默认为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代表单组,非零代表多组,一般设置几就为几组,0时则不用写[group1]、[group2]
# [group1] #设置了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服务器修改此配置文件】:
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
配置过程中有几点要注意:
*最后要确保配置中用到的目录已经创建了。比如/home/fastdfs/fastdfs_client/client、/home/fdfs/fdfs_*/data、/home/fdfs/fdfs_*/data/logs
*确保各种配置文件之间引用的端口一直。比如:
* mod_fastdfs.conf文件中tracker_server的端口应该跟tracker.conf中port一致;
* mod_fastdfs.conf文件中storage_server_port的端口应该跟跟storage.conf中port一致;
*其他配置或文件虽然不用修改,但是fastdfs-nginx-module模块会用到:
* anti-steal.jpg
* http.conf
* mime.types
最后:
进行端口开放(根据配置文件需要):
# 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
启动服务器:
storage服务器:fdfs_trackerd /etc/fdfs/tracker.conf start
Tracker服务器:fdfs_storaged /etc/fdfs/storage.conf start
查看日志:
storage服务器:tail -n10 ~/fdfs/logs/trackerd.log
Tracker服务器:tail -n10 ~/fdfs/logs/storaged.log
#如果日志显示有错误信息,需要根据信息来查找错误原因
启动nginx:
/usr/local/nginx/sbin/nginx
访问:http://storage的ip:9270,出现welcom页面表示nginx安装成功
测试上传数据:
fdfs_test /etc/fdfs/client.conf upload /home/wuchangjing/Jep用法.png
访问途中网址,进行下载或者查看