centos7 install nginx+fastdfs

Posted 超我

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7 install nginx+fastdfs相关的知识,希望对你有一定的参考价值。

说明:centos7单机部署 nginx fastdfs

## 创建一下目录作为存储数据图片的路径 可以自己定义

mkdir -pv /data/application/{storage,tracker,client}

cd /data/application/

yum install lrzsz wget git gcc gcc-c++ zlib-devel cmake make

git clone [email protected]:happyfish100/libfastcommon.git

git clone [email protected]:happyfish100/fastdfs.git

git clone [email protected]:happyfish100/fastdfs-nginx-module.git

wget http://nginx.org/download/nginx-1.9.4.tar.gz

tar xf nginx-1.9.4.tar.gz -c /usr/local

cd /usr/local/nginx-1.9.4

### 编译nginx 检查编译过程 出现缺少的包 及时进行安装 保证编译的顺利进行

./configure --prefix=/usr/local/nginx --add-module=/data/application/fastdfs-nginx-module && make && make install

cd ..;rm -rf nginx-1.9.4

cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf;cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf

### 说明:下面2行替换 是对之前创建的目录 进行保存数据使用 -->可以按照自己的需求进行自定义

sed -i ‘[email protected]^base_path.*@base_path=/data/application/[email protected]‘ /etc/fdfs/tracker.conf

sed -i ‘[email protected]_path0=.*@store_path0=/data/application/[email protected]‘ /etc/fdfs/storage.conf

### 说明:执行下面的时候 需要把ip地址改成自己的主机地址 才不会出错

sed -i ‘s$^tracker_server=.*$tracker_server=172.17.0.2:22122$g‘ storage.conf

### 启动 tracker server 后期重启直接后面跟 restart 就可以

### 启动之后记得查看 22122 端口

`which fdfs_trackerd` /etc/fdfs/tracker.conf

### 启动 storage server 后期重启直接后面跟 restart 就可以

`which fdfs_storaged` /etc/fdfs/storage.conf

### 启动之后记得查看 23000 端口

################# nginx start

/usr/local/nginx/sbin/nginx -t;/usr/local/nginx/sbin/nginx

### check nginx process 发现没有 woker 进程  只有master

ps -elf | grep nginx

### 查看 nginx 错误日志 

#### 发现下面的错误

[2018-10-12 07:11:48] ERROR - file: shared_func.c, line: 1067, file /etc/fdfs/mod_fastdfs.conf not exist
[2018-10-12 07:11:48] ERROR - file: /data/application/fastdfs-nginx-module/src/common.c, line: 163, load conf file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 2
2018/10/12 07:11:48 [alert] 4447#0: worker process 4448 exited with fatal code 2 and cannot be respawned

### 解决方法 找到这个文件 复制到 /etc/fdfs/ 目录下

cp `find / -name mod_fastdfs.conf` /etc/fdfs/

### 重载 nginx 查看错误

/usr/local/nginx/sbin/nginx -s reload

#### 发现以下错误

[2018-10-12 08:39:59] ERROR - file: ini_file_reader.c, line: 1029, include file "http.conf" not exists, line: "#include http.conf"
[2018-10-12 08:39:59] ERROR - file: /data/application/fastdfs-nginx-module/src/common.c, line: 163, load conf file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 2
2018/10/12 08:39:59 [alert] 4447#0: worker process 4600 exited with fatal code 2 and cannot be respawned

### 解决方法 找到这个错误提示的文件 http.conf 复制到 /etc/fdfs/ 目录下

cp `find / -name http.conf` /etc/fdfs/

### 重启nginx 继续查看错误日志

/usr/local/nginx/sbin/nginx -s reload

#### 发现以下的错误 

2018/10/12 08:44:48 [notice] 4609#0: signal process started
ngx_http_fastdfs_process_init pid=4610
[2018-10-12 08:44:48] ERROR - file: shared_func.c, line: 1067, file /etc/fdfs/mime.types not exist
2018/10/12 08:44:48 [alert] 4447#0: worker process 4610 exited with fatal code 2 and cannot be respawned

### 直接在/data目录查找这个文件  复制到 /etc/fdfs/目录下

cp `find /data -name mime.types` /etc/fdfs/

### 修改/etc/fdfs/mod_fastdfs.conf配置文件配合nginx

sed -i ‘[email protected]^tracker_server=.*@tracker_server=172.17.0.2:[email protected]‘ /etc/fdfs/mod_fastdfs.conf

sed -i ‘[email protected]^url_have_group_name.*@url_have_group_name = [email protected]‘ /etc/fdfs/mod_fastdfs.conf

sed -i ‘[email protected]^store_path0=.*@store_path0=/data/application/[email protected]‘ /etc/fdfs/mod_fastdfs.conf

sed -i ‘$a#include http.conf‘ /etc/fdfs/mod_fastdfs.conf

### 这一步看自己爱好执行  删除多余行

 sed -i ‘/^ *#/d‘ /usr/local/nginx/conf/nginx.conf

/usr/local/nginx/sbin/nginx -s reload

#### 这会儿发现错误日志 没有报错了 worker 进程也启动了

### 进行上传图片测试 修改/etc/fdfs/client.conf文件    ip替换成自己的主机地址

sed -i ‘[email protected]_path=.*@base_path=/data/application/[email protected]‘ /etc/fdfs/client.conf

sed -i ‘[email protected]_server=.*@tracker_server=172.17.0.2:[email protected]‘ /etc/fdfs/client.conf

 








以上是关于centos7 install nginx+fastdfs的主要内容,如果未能解决你的问题,请参考以下文章

centos7自动化编译安装nginx

centos7下安装nginx

centos7 install lnmp

centos7 + nginx+django 运行环境

centos7 安装nginx和php5.6.25遇到 无法访问php页面 报错file not found 问题解决

centOs7安装Nginx