码迷,mamicode.com
首页 > 其他好文 > 详细

创建fastdfs_nginx容器及nginx配置

时间:2020-01-11 11:45:48      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:inf   nginx   har   源码包   sed   系统   module   ted   common   

创建fastdfs_nginx容器及nginx配置

拉取镜像,创建容器

# 拉取镜像
sudo docker pull ubuntu:18.04
# 创建容器,创建容器时必须使用image:tag,标签不可缺少
sudo docker run -itd --network=host --name fastdfs_nginx -v /home/moluo/store_path/:/home/store_path ubuntu:18.04

进入容器,修改源

sudo docker exec -it fastdfs_nginx bash
cp /etc/apt/sources.list /etc/apt/sources.list.bak # 备份
exit    # 退出容器

# 直接当前操作系统里面的源文件复制到容器内部(容器中没有vi/vim)
sudo docker cp /etc/apt/sources.list fastdfs_nginx:/etc/apt/sources.list

我的操作系统的apt源使用了阿里源

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

下载编译安装nginx

# 进入容器安装nginx
sudo docker exec -it fastdfs_nginx bash
# 更新源
apt-get update

# 安装nginx相关依赖
apt-get install build-essential libtool
apt-get install libpcre3 libpcre3-dev
apt-get install zlib1g-dev
apt-get install openssl

下载nginx

# 到官网下载nginx源码包
# 如果容器内部没有wget命令,则安装命令: apt-get install wget
cd /
wget http://nginx.org/download/nginx-1.15.9.tar.gz
tar -zxvf nginx-1.15.9.tar.gz

# 下载fastdfs-nginx-module
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
tar -zxvf V1.20.tar.gz fastdfs-nginx-module-1.20

下载编译安装libfastcommon

wget https://github.com/happyfish100/libfastcommon/archive/V1.0.43.tar.gz
tar -zxvf V1.0.43.tar.gz libfastcommon-1.0.43
cd libfastcommon-1.0.43
./make.sh
./make.sh install

下载编译安装fastdfs

wget https://github.com/happyfish100/fastdfs/archive/V5.04.tar.gz
tar -zxvf V5.04.tar.gz  fastdfs-5.04
cd fastdfs-5.04
./make.sh
./make.sh install

编译安装nginx

cd /nginx-1.15.9
./configure --add-module=../fastdfs-nginx-module-1.20/src/
make
make install

nginx出现错误解决

# make命令编译报错
# 1.错误提示: 
# /usr/local/include/fastdfs/fdfs_define.h:15:27: 致命错误:common_define.h:没有那个文件或目录
# 解决方法:
# 修改文件 /fastdfs-nginx-module-1.20/src/config 第6,15行
apt install vim
vim /fastdfs-nginx-module-1.20/src/config
:set nu
ngx_module_incs="/usr/include/fastdfs /usr/include/fastcommon/"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"

# 2.错误提示:
# 'FDFSHTTPParams' has no member named 'support_multi_range'
# 解决方案:
# 打开报错的文件 /fastdfs-nginx-module-1.20/src/common.c 的1245行
vim /fastdfs-nginx-module-1.20/src/common.c
:set nu
:1245
# 原来代码:
   (pContext->range_count > 1  && !g_http_params.support_multi_range))   
# 修改为
   (pContext->range_count > 1 ))
# 再重新执行刚才nginx的编译 make && make install


# 3.错误提示
In file included from ../fastdfs-nginx-module-1.20/src//common.c:26:0,
                 from ../fastdfs-nginx-module-1.20/src//ngx_http_fastdfs_module.c:6:
/usr/include/fastdfs/fdfs_define.h:15:10: fatal error: common_define.h: No such file or directory
# 拷贝common_define.h到相应目录
cp /usr/include/fastcommon/common_define.h /fastdfs-nginx-module-1.20/src/
# 修改完错误后继续编译 make && make install

修改nginx相关配置

cp -r /fastdfs-5.04/conf/* /etc/fdfs/
cp /fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs

# 修改ngxinx 配置文件
vim /usr/local/nginx/conf/nginx.conf
server {
        # 1. 修改端口
        listen       8888;                          
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        # 2. 路径识别
        location ~/group([0-9])/M00 {
        # root /var/fdfs/storage_path;
            ngx_fastdfs_module;
        }

启动nginx

# 启动nginx
/usr/local/nginx/sbin/nginx

# 启动以后,退出容器
exit

nginx启动错误

# 如果nginx启动出现错误
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libfdfsclient.so: cannot open shared object file: No such file or directory

# 查找libfdfsclient.so
find / -name libfdfsclient.so
/usr/lib64/libfdfsclient.so
/fastdfs-5.04/client/libfdfsclient.so

# 发现/usr/lib目录中没有libfdfsclient.so
cp /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so
# 请确保/usr/lib和/usr/lib64中都有libfastcommon.so和libfdfsclient.so目录,如果没有的话,相互拷贝过来

# 重启nginx
/usr/local/nginx/sbin/nginx -s reload

技术图片

nginx已经启动,但无法获取资源,nginx运行时只有master进程没有work进程

# 查看日志
vim /usr/local/nginx/logs/error.log
# 错误
[2020-01-10 16:06:47] ERROR - file: client_func.c, line: 112, conf file "/etc/fdfs/mod_fastdfs.conf", host "tracker" is invalid
2020/01/10 16:06:47 [alert] 55#0: worker process 74 exited with fatal code 2 and cannot be respawned
2020/01/10 16:18:06 [notice] 107#0: signal process started

# 修改/etc/fdfs/mod_fastdfs.conf 第40、62行
vim /etc/fdfs/mod_fastdfs.conf
:set nu
tracker_server=192.168.11.46:22122    # 改为自己的ip
store_path0=/home/store_path

再修改配置

# 修改storage.conf
vim /etc/fdfs/storage.conf
base_path=/home/store_path
store_path0=/home/store_path
tracker_server=192.168.11.46:22122  # 改为自己的ip
http.server_port=8888

# 修改tracker.conf
vim /etc/fdfs/tracker.conf
base_path=/home/tracker_data

# 修改mod_fastdfs.conf(前面已修改则不用修改了)
vim /etc/fdfs/mod_fastdfs.conf
tracker_server=192.168.11.46:22122      # 改为自己的ip
store_path0=/home/store_path
url_have_group_name = true              # 请求路径是否携带组信息 

将nginx重启后将会有master和work两个进程,此时如果tracker和storage都启动了的话,即可通过浏览器访问nginx代理的资源

技术图片

技术图片

创建fastdfs_nginx容器及nginx配置

标签:inf   nginx   har   源码包   sed   系统   module   ted   common   

原文地址:https://www.cnblogs.com/sincere-ye/p/12179270.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!