Linux安装Fastdfs与nginx整合

Linux安装Fastdfs与nginx整合

1.分别下载 libfastcommonfastdfs

​ 1.1 1.下载libfastcommon的源代码并进行安装

1.wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz -SO libfastcommon.tar.gz
# 解压
tar -xf libfastcommon.tar.gz
或
git clone https://github.com/happyfish100/libfastcommon.git
2.cd libfastcommon;git checkout V1.0.43
  ./make.sh clean && ./make.sh && ./make.sh install

​ 1.1.2. 下载fastdfs源代码并进行安装

1.wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz -SO fastdfs.tar.gz
# 解压
tar -xf fastdfs.tar.gz
git clone https://github.com/happyfish100/fastdfs.git
2cd fastdfs; git checkout V6.06
 ./make.sh clean && ./make.sh && ./make.sh install

2.1设置配置文件 ( 配置文件是在/etc/fdfs目录下 配置文件是不全的,而且都是模板,所以需要从解压的fastdfs包中拷贝过来,并修改配置)

cp -f fastdfs/tracker.conf /etc/fdfs/tracker.conf
cp -f fastdfs/storage.conf /etc/fdfs/storage.conf
cp -f fastdfs/client.conf /etc/fdfs/client.conf
cp -f fastdfs/storage_ids.conf /etc/fdfs/storage_ids.conf
cp -f fastdfs/http.conf /etc/fdfs/http.conf
cp -f fastdfs/mime.types /etc/fdfs/mime.types

2.2配置文件

vi /etc/fdfs/tracker.conf

# the tracker server port
port=22122

# the base path to store data and log files
base_path=/home/fdfs(自己的存在的目录)

# HTTP port on this tracker server
http.server_port=9270
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/fdfs(自己的存在的目录)

# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/home/caibh/fdfs(自己的存在的目录)
#store_path1=/home/caibh/fdfs2

# tracker服务器,虽然是同一台机器上,但是不能写127.0.0.1。这项配置可以出现一次或多次
tracker_server=191.8.1.77:22122(ip:22122)

# the port of the web server on this storage server
http.server_port=8888
vi /etc/fdfs/client.conf

# the base path to store log files
base_path=/home/fdfs/client(自己的存在的目录)
# tracker_server can ocur more than once, and tracker_server format is
#  "host:port", host can be hostname or ip address
tracker_server=191.8.1.77:22122(ip:22122)
#HTTP settings
http.tracker_server_port=9270
vi /etc/fdfs/mod_fastdfs.conf

# 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=191.8.1.77:22122(ip: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/fdfs(自己的存在的目录)
#store_path1=/home/yuqing/fastdfs1

注意:

  1. 确保配置中用到的目录已经创建了。比如(自己的存在的目录)/client(自己的存在的目录)/data(自己的存在的目录)/logs`

  2. 确保各种配置文件之间引用的端口一直。比如:

    • mod_fastdfs.conf文件中tracker_server的端口应该跟tracker.confport一致;
    • mod_fastdfs.conf文件中storage_server_port的端口应该跟跟storage.confport一致;

    3.其他配置或文件虽然不用修改,但是fastdfs-nginx-module模块会用到:

  • anti-steal.jpg

  • http.conf

  • mime.types

2.3启动trackerstorage

# 启动
fdfs_trackerd /etc/fdfs/tracker.conf start
fdfs_storaged /etc/fdfs/storage.conf start
# 查看日志
tail -n10 ~/fdfs/logs/trackerd.log
tail -n10 ~/fdfs/logs/storaged.log

2.4用fdfs_test测试上传

fdfs_test /etc/fdfs/client.conf upload ~/caibh/test_images/图片路径.jpg
或
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/include/stdlib.h

3.1安装nginx

#安装依赖库:
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
#安装nginx
https://nginx.org/en/download.html选择版本复制链接
wget https://nginx.org/download/nginx-1.16.1.tar.gz
#解压
tar -zxvf nginx-1.11.6.tar.gz
#配置命令
./configure
#编译安装
make && make install

3.2启动、停止nginx

#启动、停止nginx
#启动和停止nginx的命令 
#(1)先进入nginx的目录
cd /usr/local/nginx/sbin/
#(2)再执行命令
./nginx 开启
./nginx -s stop 此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程
./nginx -s quit 此方式停止步骤是待nginx进程处理任务完毕进行停止
./nginx -s reload 配置生效需要重启nginx,不用先停止nginx再启动,即可将配置信息在nginx中生效。

3.3配置nginx

#(1)进入配置文件文件夹
cd /usr/local/nginx/conf
#(2)备份配置文件(备份是个好习惯,可省略)
cp nginx.conf nginx.conf.back
#编辑nginx.conf配置文件
vim nginx.conf
#查询nginx进程
ps aux|grep nginx
#开机自启动
在etc的rc.local增加启动代码就可以了。
vim /etc/rc.local
/usr/local/nginx/sbin/nginx

4.1 下载FastDFS nginx模块源代码

1.wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz -SO fastdfs-nginx-module.tar.gz
# 解压
tar -xf xxx.tar.gz
2.git clone https://github.com/happyfish100/fastdfs-nginx-module
cd fastdfs-nginx-module; git checkout V1.22

4.2 进入nginx源目录,编译并安装fastdfs模块

cd nginx-1.16.1
./configure --add-module=$YOUR_PATH/fastdfs-nginx-module/src
make && make install
  1. 1配置nginx配置文件
location /M00 {
            root /home/fastdfs/data;(自己的目录)
            ngx_fastdfs_module;
        }
#主要是浏览器通过nginx访问fastdfs
#建立符号链接$ {fastdfs_base_path} / data / M00到$ {fastdfs_base_path} / data,命令行
ln -s /home/yuqing/fastdfs/data  /home/yuqing/fastdfs/data/M00

5.2重启nginx

/usr/local/nginx/sbin/nginx -s stop; /usr/local/nginx/sbin/nginx
#测试
 /usr/bin/fdfs_test /etc/fdfs/client.conf upload /usr/include/stdlib.h
 #获取链接
 #可以下载文件即可
 #或者
 /usr/bin/fdfs_upload_file /etc/fdfs/client.conf namei.jpeg
#上传成功后返回文件ID号:group1/M00/00/00/wKgz6lnduTeAMdrcAAEoRmXZPp870.jpeg
#返回的文件ID由group、存储目录、两级子目录、fileid、文件后缀名(由客户端指定,主要用于区分文件类型)拼接而成。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wY2JP9bq-1577873812680)(C:\Users\zd\AppData\Roaming\Typora\typora-user-images\1577871080628.png)]

#或者
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf namei.jpeg
#上传成功后返回文件ID号:如group1/M00/00/00/wKgz6lnduTeAMdrcAAEoRmXZPp870.jpeg
#返回的文件ID由group、存储目录、两级子目录、fileid、文件后缀名(由客户端指定,主要用于区分文件类型)拼接而成。


[外链图片转存中...(img-wY2JP9bq-1577873812680)]

发布了4 篇原创文章 · 获赞 0 · 访问量 94

猜你喜欢

转载自blog.csdn.net/qq_43523599/article/details/103794738