Centos7安装Fastdfs(单机)

该安装方式为先安装nginx插件,再安装ng。如果先安装ng再装插件,要把插件add到ng中,重新编译把生成的nginx运行文件替换原有的

安装依赖

zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent
个人安装习惯,将必要的tar.gz放在指定位置解压后安装,安装到指定的目录


1、将安装包上传到指定目录/usr/local/fastdfs(没有就创建)

image.png

image.png

2、libevent解压、安装

tar -zxvf libevent-2.1.8-stable.tar.gz
cd libevent-2.1.8-stable
./configure
make && make install

3、libfastcommon解压、安装、配置

3.1解压
tar -zxvf libfastcommon-1.0.7.tar.gz
3.2安装

进入libfastcommon

cd libfastcommon-1.0.7
[root@centos libfastcommon-1.0.7]# ll
总用量 24
-rw-rw-r-- 1 root root 2170 9月  16 2014 HISTORY
-rw-rw-r-- 1 root root  582 9月  16 2014 INSTALL
-rw-rw-r-- 1 root root 1341 9月  16 2014 libfastcommon.spec
-rwxrwxr-x 1 root root 2151 9月  16 2014 make.sh
-rw-rw-r-- 1 root root  617 9月  16 2014 README
drwxrwxr-x 2 root root 4096 9月  16 2014 src
[root@centos libfastcommon-1.0.7]# ./make.sh
[root@centos libfastcommon-1.0.7]# ./make.sh install
3.3配置

libfastcommon安装好之后会自动将库文件拷贝至usr/lib64下,由于FastDFS程序引用/usr/lib目录,所以需要把/usr/lib64下的库文件拷贝至/usr/lib下。

[root@centos libfastcommon-1.0.7]# cd /usr/lib64
[root@centos lib64]# cp libfastcommon.so /usr/lib
[root@centos lib64]# find /usr/lib -name libfastcommon.so
/usr/lib/libfastcommon.so

4、FastDFS解压、安装、配置

4.1解压
[root@centos lib64]# cd /usr/local/fstdf/
[root@centos fstdf]# tar -zxvf fastdfs-5.05.tar.gz 
4.2安装fastdfs
[root@centos fstdf]# ls
fastdfs-5.05                       libevent-2.1.8-stable         libfastcommon-1.0.7.tar.gz  pcre-8.39.tar.gz
fastdfs-5.05.tar.gz                libevent-2.1.8-stable.tar.gz  nginx-1.17.5.tar.gz         zlib-1.2.11.tar.gz
fastdfs-nginx-module_v1.16.tar.gz  libfastcommon-1.0.7           openssl-1.0.1t.tar.gz
[root@centos fstdf]# cd fastdfs-5.05
[root@centos fastdfs-5.05]# ls
client  conf             fastdfs.spec  init.d   make.sh     README.md   stop.sh  test
common  COPYING-3_0.txt  HISTORY       INSTALL  php_client  restart.sh  storage  tracker
[root@centos fastdfs-5.05]# ./make.sh 
[root@centos fastdfs-5.05]# ./make.sh install

安装成功后将安装目录下的conf下的文件拷贝到/etc/fdfs下。(nginx需要)conf文件目录在/usr/local/fastdfs/FastDFS/conf,进到这个conf目录

[root@centos fastdfs-5.05]# cd conf/
[root@centos conf]# cp * /etc/fdfs/
4.3安装tracker服务(跟踪服务)
[root@centos conf]# cd /usr/local/fstdf/fastdfs-5.05/tracker/
[root@centos tracker]# vim /etc/fdfs/tracker.conf

将base_path中的地址换成tracker地址
将http.server_port=8099 改成nginx对应的地址!!!!

image.png

4.4启动tracker服务
[root@centos tracker]# /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf

重启tracker命令:上面的命令后面加 restart

4.5安装storage服务(存储服务)
[root@centos tracker]# cd /usr/local/fstdf/fastdfs-5.05/storage/
[root@centos storage]# vim /etc/fdfs/storage.conf

注意下面几个内容
group_name=group1 #组名是不是跟你访问路径中的组名一致?
base_path=/usr/local/fstdf/fastdfs-5.05/storage/ #这个文件路径存不存在?
store_path0=/usr/local/fstdf/fastdfs-5.05/storage/ #这个文件路径存不存在?
tracker_server=192.168.59.131:22122 #ip对吗?
http.server_port=80 #nginx的端口地址(虽然还没有装,但是端口一定要保持一致)


image.png

image.png

image.png

image.png
4.6启动storage服务(存储服务)
[root@centos storage]# /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
4.7client配置

将/usr/local/fastdfs/FastDFS/client里面的libfdfsclient.so拷贝到/usr/lib下

[root@centos storage]# cd /usr/local/fstdf/fastdfs-5.05/client/
[root@centos client]# cp libfdfsclient.so /usr/lib
[root@centos client]# vim /etc/fdfs/client.conf

注意下面内容
base_path=/usr/local/fstdf/fastdfs-5.05/storage/ #这个文件路径存不存在?
tracker_server=..***:22122 #ip正确吗?
http.tracker_server_port=8099 #端口号是否跟之前配置的一致,统一起来

image.png

image.png

4.8测试上传

创建个html页面

[root@centos client]# cd /usr/local/fstdf/
[root@centos fstdf]# vim test.html
[root@centos fstdf]# /usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/local/fstdf/test.html

这个就是标志文件上传成功

image.png

文件的地址
http://10.10.23.243:8099/group1/M00/00/00/CgoX82E6ye6AMh46AAAAJZipYbE18_big.html
因为FastDFS本身并不具有处理http协议的能力,而客户端正是通过http协议访问的,因此在浏览器中不能够直接访问文件,所以引入ng就非常必要

文件存储位置

[root@centos fstdf]# pwd
/usr/local/fstdf
[root@centos fstdf]# cd fastdfs-5.05/storage/data/00/00/
[root@centos 00]# ls
CgoX82E6ye6AMh46AAAAJZipYbE18_big.html    CgoX82E6ye6AMh46AAAAJZipYbE18.html
CgoX82E6ye6AMh46AAAAJZipYbE18_big.html-m  CgoX82E6ye6AMh46AAAAJZipYbE18.html-m

5、安装nginx-fastDFS插件

5.1解压
[root@centos 00]# cd /usr/local/fstdf/
[root@centos fstdf]# tar -zxvf fastdfs-nginx-module_v1.16.tar.gz
[root@centos fstdf]# cd fastdfs-nginx-module
5.2修改config配置文件
[root@centos fstdf]# cd fastdfs-nginx-module
[root@centos fastdfs-nginx-module]# cd src/
[root@centos src]# ls
common.c  common.h  config  mod_fastdfs.conf  ngx_http_fastdfs_module.c
[root@centos src]# vim config 

把路径上的local全部去掉

image.png

image.png

把该下的mod_fastdfs.conf文件复制到/etc/fdfs目录下,并编辑该文件。

[root@centos src]# cp mod_fastdfs.conf /etc/fdfs/
[root@centos src]# vim /etc/fdfs/mod_fastdfs.conf

请注意
tracker_server=***:22122 #ip?
url_have_group_name = true #这个是true?
store_path0=/usr/local/fstdf/fastdfs-5.05/storage #路径存在吗?

image.png

image.png

image.png

6、安装nginx

6.1将nginx相关包移动到指定目录下(个人习惯)
[root@centos src]# cd /usr/local/fstdf/
[root@centos fstdf]# mv pcre-8.39.tar.gz openssl-1.0.1t.tar.gz  /usr/local/src
[root@centos fstdf]# mv zlib-1.2.11.tar.gz nginx-1.17.5.tar.gz /usr/local/src/
[root@centos fstdf]# cd /usr/local/src/
[root@centos src]# ls
nginx-1.17.5.tar.gz  openssl-1.0.1t.tar.gz  pcre-8.39.tar.gz  zlib-1.2.11.tar.gz
6.2解压并安装pcre包
[root@centos src]# tar -zxvf pcre-8.39.tar.gz
[root@centos src]# ll
总用量 8088
-rw-r--r-- 1 root root 1036056 9月  10 09:40 nginx-1.17.5.tar.gz
-rw-r--r-- 1 root root 4556447 9月  10 09:40 openssl-1.0.1t.tar.gz
drwxr-xr-x 7 1169 1169    8192 6月  14 2016 pcre-8.39
-rw-r--r-- 1 root root 2062258 9月  10 09:40 pcre-8.39.tar.gz
-rw-r--r-- 1 root root  607698 9月  10 09:40 zlib-1.2.11.tar.gz
[root@centos src]# cd pcre-8.39
[root@centos pcre-8.39]# ./configure 
[root@centos pcre-8.39]# make && make install
6.3解压并安装zlib包
[root@centos pcre-8.39]# cd ../
[root@centos src]# tar -zxvf zlib-1.2.11.tar.gz
[root@centos src]# cd zlib-1.2.11
[root@centos zlib-1.2.11]# ./configure
[root@centos zlib-1.2.11]# make && make install
6.4解压并安装openssl包
[root@centos zlib-1.2.11]# cd ../
[root@centos src]# tar -zxvf openssl-1.0.1t.tar.gz

该包不需要重新编译

6.5解压并安装nginx包
[root@centos src]# tar -zxvf nginx-1.17.5.tar.gz
[root@centos src]# cd nginx-1.17.5
[root@centos nginx-1.17.5]# ./configure --prefix=/usr/local/nginx \
> --sbin-path=/usr/local/nginx/sbin/nginx \
> --conf-path=/usr/local/nginx/conf/nginx.conf \
> --error-log-path=/usr/local/nginx/log/error.log \
> --http-log-path=/usr/local/nginx/log/access.log \
> --pid-path=/usr/local/nginx/log/pid/nginx.pid \
> --lock-path=/usr/local/nginx/log/lock/subsys/nginx \
> --with-http_ssl_module --with-http_realip_module \
> --with-pcre=/usr/local/src/pcre-8.39 \
> --with-zlib=/usr/local/src/zlib-1.2.11 \
> --with-openssl=/usr/local/src/openssl-1.0.1t \
> --add-module=/usr/local/fstdf/fastdfs-nginx-module/src/
[root@centos nginx-1.17.5]# make && make install

安装到指定目录的命令

./configure --prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--error-log-path=/usr/local/nginx/log/error.log \
--http-log-path=/usr/local/nginx/log/access.log \
--pid-path=/usr/local/nginx/log/pid/nginx.pid \
--lock-path=/usr/local/nginx/log/lock/subsys/nginx \
--with-http_ssl_module --with-http_realip_module \
--with-pcre=/usr/local/src/pcre-8.39 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.0.1t \
--add-module=/usr/local/fstdf/fastdfs-nginx-module/src/

查看nginx插件是否安装成功

[root@centos nginx-1.17.5]# cd /usr/local/nginx/
[root@centos nginx]# ls
conf  html  log  sbin
[root@centos nginx]# cd sbin/
[root@centos sbin]# ./nginx -V
nginx version: nginx/1.17.5
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.1t  3 May 2016
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/usr/local/nginx/log/error.log --http-log-path=/usr/local/nginx/log/access.log --pid-path=/usr/local/nginx/log/pid/nginx.pid --lock-path=/usr/local/nginx/log/lock/subsys/nginx --with-http_ssl_module --with-http_realip_module --with-pcre=/usr/local/src/pcre-8.39 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.0.1t --add-module=/usr/local/fstdf/fastdfs-nginx-module/src/
[root@centos sbin]# 

修改nginx配置文件

[root@centos sbin]# cd ../conf/
[root@centos conf]# vim nginx.conf
image.png

启动nginx

[root@centos conf]# cd ../sbin/
[root@centos sbin]# ll
总用量 8356
-rwxr-xr-x 1 root root 8554160 9月  10 12:35 nginx
[root@centos sbin]# ./nginx -t
ngx_http_fastdfs_set pid=29127
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@centos sbin]# ./nginx 
ngx_http_fastdfs_set pid=29135

访问fastdfs中存入的html页面

image.png

别忘了端口开放!!!!

你可能感兴趣的:(Centos7安装Fastdfs(单机))