1、安装依赖(编译时需要)
yum install -y gcc gcc-c++
yum -y install libevent
yum install pcre
yum install pcre-devel
yum install zlib
yum install zlib-devel
yum install openssl
yum install openssl-devel
yum install -y zlib-devel
2、下载libfastcommon、fastdfs、fastdfs-nginx-module
cd ~
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz
wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
# 解压
tar -zxf xxx.tar.gz
3、安装 libfastcommon
cd libfastcommon-1.0.39
./make.sh
./make.sh install
4、安装 fastdfs
cd fastdfs-5.11
./make.sh
./make.sh install
安装成功程序是在/usr/bin
目录下:
配置文件是在/etc/fdfs
目录下:
[root@localhost ~]# ll /etc/fdfs/
client.conf.sample storage_ids.conf.sample tracker.conf.sample storage.conf.sample
这些配置文件是不全的,而且都是模板,所以需要从fastdfs-5.11
包中拷贝过来,并修改配置。
5、修改配置
vi /etc/fdfs/tracker.conf
# the tracker server port
port=22122
# the base path to store data and log files
base_path=/home/file/fastdfs
# HTTP port on this tracker server
http.server_port=80
vi /etc/fdfs/storage.conf
# storage所属的组
group_name=group1
# the storage server port
port=23000
# the base path to store data and log files
base_path=/home/file/fastdfs
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/home/file/fastdfs
#store_path1=/home/file/fastdfs
# tracker服务器,虽然是同一台机器上,但是不能写127.0.0.1。这项配置可以出现一次或多次
tracker_server=192.168.91.128:22122
# the port of the web server on this storage server
http.server_port=80
vi /etc/fdfs/client.conf
# the base path to store log files
base_path=/home/file/fastdfs
# 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.91.128:22122
#HTTP settings
http.tracker_server_port=80
vi /etc/fdfs/mod_fastdfs.conf
将fastdfs-nginx-module/src下的mod_fastdfs.conf拷贝至/etc/fdfs/下进行编辑
# the base path to store log files
base_path=/tmp
# 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=192.168.91.128:22122
# the port of the local storage server
# the default value is 23000
storage_server_port=23000
# 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/file/fastdfs
#store_path1=/home/yuqing/fastdfs1
配置过程中有几点要注意:
确保配置中用到的目录已经创建了。
比如:/home/file/fastdfs/client、/home/file/fastdfs/data、/home/file/fastdfs/logs
确保各种配置文件之间引用的端口一致。
比如:
mod_fastdfs.conf文件中tracker_server的端口应该跟tracker.conf中port一致;
mod_fastdfs.conf文件中storage_server_port的端口应该跟跟storage.conf中port一致;
6、启动tracker和storage
# 启动
fdfs_trackerd /etc/fdfs/tracker.conf start
fdfs_storaged /etc/fdfs/storage.conf start
# 查看日志
tail -f /home/file/fastdfs/logs/trackerd.log
tail -f /home/file/fastdfs/logs/storaged.log
# 如果日志显示有错误信息,需要根据信息来查找错误原因
7、fdfs_test
测试上传
$ fdfs_test /etc/fdfs/client.conf upload /home/images/wechatWang.jpg
8、Nginx的安装
#解压
tar -zxvf nginx-1.10.3.tar.gz -C /usr/
#进入nginx解压的目录下:
cd /usr/nginx-1.10.3/
#创建一个custom_configure.sh文件加入模块命令配置
vi custom_configure.sh
写入如下内容:
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/usr/fastdfs-nginx-module-1.20/src
#保存退出:wq!
#执行可执行命令
chmod +x custom_configure.sh
#执行custom_configure.sh
./custom_configure.sh
#执行configure
./configure
#编译并安装
make && make install
注意:最后添加了fastdfs-nginx-module所在目录,上边将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录。
检查nginx安装情况
配置nginx,加入路由规则,映射到fastdfs的数据目录:
server {
listen 80;
server_name 192.168.91.128;
#charset koi8-r;
#access_log logs/host.access.log main;
# 监听域名中带有group的,交给FastDFS模块处理
location ~/group([0-9])/M00 {
root /home/file/fastdfs/data;
ngx_fastdfs_module;
}
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
注意:
(a.) server_name指定本机ip;
(b.) location /group1/M00/:group1为nginx 服务FastDFS的分组名称,M00是FastDFS自动生成编号,对应store_path0=/home/fdfs_storage,如果FastDFS定义store_path1,这里就是M01
Nginx命令
#启动
cd usr/local/nginx/sbin
./nginx
#关闭
cd usr/local/nginx/sbin
./nginx -s reload
查询nginx主进程号
ps -ef | grep nginx
从容停止 kill -QUIT 主进程号
快速停止 kill -TERM 主进程号
强制停止 kill -9 nginx
若nginx.conf配置了pid文件路径,如果没有,则在logs目录下
9、在浏览器中访问上传到fastDFS的图片
因为Centos系统有防火墙,需要先关闭掉,才可以在浏览器中访问
centos7默认使用的是firewall作为防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)