FastDFS加载fastdfs-nginx-module模块,实现HTTP访问
来源:互联网 发布:全景补地软件 编辑:程序博客网 时间:2024/06/10 00:13
接上篇:Keepalived+Nginx+FastDFS实现最简单的文件服务器的高可用
地址:http://blog.csdn.net/goodmylove/article/details/78183152
接下来我们来为storage安装fastdfs-nginx-module,目的是通过HTTP来访问我们上传到storage上的东西。
在所有storage上操作
进入我们的软件目录
cd /home/software解压fastdfs-nginx-module_v1.19.zip
unzip fastdfs-nginx-module_v1.19.zip安装Nginx依赖环境
yum install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel -y解压Nginx,并进入nginx目录
tar -zxvf nginx-1.13.0.tar.gzcd nginx-1.13.0编译nginx配置,这里要注意,标红字段为你自己解压的fastdfs-nginx-module的src目录的位置
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-stream --with-pcre --add-module=/home/software/fastdfs-nginx-module-master/src --with-stream编译安装
make && make install添加nginx为系统服务
vim /etc/init.d/nginx写入内容如下
#!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval killall -9 nginx } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac保存退出
赋予可执行权限
chmod +x /etc/init.d/nginx添加nginx用户
useradd -M -s /sbin/nglogin nginx增加client目录
mkdir /var/tmp/nginx/client -p复制mod_fastdfs.conf文件至fastdfs配置目录
cp /home/software/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/修改
vim /etc/fdfs/mod_fastdfs.conf修改如下内容
tracker_server=192.168.1.211:22122tracker_server=192.168.1.212:22122url_have_group_name = truestore_path0=/home/fastdfs/storage复制http.conf、mine.types到/etc/fdfs
cp /home/software/fastdfs-5.05/conf/http.conf mime.types /etc/fdfs/在/home/fastdfs/storage文件存储目录下创建软连接,将其链接到实际存放数据的目录
ln -s /home/fastdfs/storage/data/ /home/fastdfs/storage/data/M00配置nginx访问storage文件
vim nginx.conf删除所有内容,添加下面内容
#user nobody;worker_processes 1;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 8888; server_name localhost; location ~/group([0-9])/M00 { ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}保存退出
启动nginx
service nginx start
启动nginx后,如果打印出ngx_http_fastdfs_setpid=xxx,表示fastdfs-nginx-module模块加载成功了,xxx表示模块的进程ID
再tracker上重新上传文件
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/ht.jpgtracker1
[root@localhost home]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/ht.jpggroup1/M00/00/00/wKgB1VnbSxSAeXaBAATBl8xofxY228.jpg[root@localhost home]#tracker2
[root@localhost home]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /home/ht.jpggroup1/M00/00/00/wKgB1lnbSxWAL4aiAATBl8xofxY395.jpg[root@localhost home]#通过storageIP:8888+返回路径访问上传至storage服务器上的网页
192.168.1.213:8888/group1/M00/00/00/wKgB1VnbSxSAeXaBAATBl8xofxY228.jpg
192.168.1.214:8888/group1/M00/00/00/wKgB1VnbSxSAeXaBAATBl8xofxY228.jpg
192.168.1.213:8888/group1/M00/00/00/wKgB1lnbSxWAL4aiAATBl8xofxY395.jpg
192.168.1.214:8888/group1/M00/00/00/wKgB1lnbSxWAL4aiAATBl8xofxY395.jpg
我这里就贴一个连接的侧视图就可以了,不多贴其他的接下来我们在tracker上安装nginx,实现通过tracker的80端口向storage发送读写请求
在所有tracker上操作
进入软件目录
cd /home/software
安装以来环境
解压nginxyum install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel -y
tar -zxvf nginx-1.13.0.tar.gz进入nginx目录
cd nginx-1.13.0编译配置
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-stream --with-pcre --with-stream编译安装
make && make install
添加nginx为系统服务
vim /etc/init.d/nginx写入内容如下
#!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval killall -9 nginx } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac保存退出
赋予可执行权限
chmod +x /etc/init.d/nginx添加nginx用户
useradd -M -s /sbin/nglogin nginx增加client目录
mkdir /var/tmp/nginx/client -p
防火墙通过80端口,之前又类似操作,这里就不细写了。
重启防火墙
service iptables restart启动nginx
service nginx startHTTPD分别访问两个tracker,查看nginx安装是否正常。
tracker1
tracker2
两个都可以正常访问,记下来我们配置nginx配置文件,让tracker将对自己的80端口的请求代理到两个storage上去。
vim /usr/local/nginx/conf/nginx.con删除原有内容,增加如下内容
#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on;upstream fastdfs_tracker_read { server 192.168.1.213:8888 weight=1 max_fails=2 fail_timeout=30s; server 192.168.1.214:8888 weight=1 max_fails=2 fail_timeout=30s;} server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; proxy_pass http://fastdfs_tracker_read/; proxy_set_header Host $http_host; proxy_set_header Cookie $http_cookie; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; client_max_body_size 300m; } #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; } }}#stream {# server { # listen 22222;# proxy_pass fastdfs_write;# }# upstream fastdfs_write {# server 192.168.1.230:22122;# server 192.168.1.231:22122; # }#}
保存退出,重启Nginx
chkconfig nginx on
service nginx restart之前我们测试的是通过storagedIP:8888+返回路径来访问图片,如下
192.168.1.214:8888/group1/M00/00/00/wKgB1lnbSxWAL4aiAATBl8xofxY395.jpg
现在我们用trackerIP+返回路径来访问一下,如下
192.168.1.211/group1/M00/00/00/wKgB1lnbSxWAL4aiAATBl8xofxY395.jpg
相同的,,用192.168.1.212+返回路径也是可以正常访问的。
到这里我们只是实现了对通过tracker对storage的读访问和读负载均衡,并没有写入和写负载均衡。下面是我的另外一篇博客,,用来介绍PHP和Apache和fastdfs的tracker结合,实现写入和写负载均衡。其中对应的IP改为你自己的trackerIP即可。http://blog.csdn.net/goodmylove/article/details/78165208
阅读全文
0 0
- FastDFS加载fastdfs-nginx-module模块,实现HTTP访问
- fastdfs+nginx+fastdfs-nginx-module
- 【fastDFS】Nginx+FastDFS module安装
- fastdfs-nginx-module安装
- FastDFS+nginx+fastdfs-nginx-module服务器配置
- FastDFS+nginx+fastdfs-nginx-module服务器配置
- nginx添加fastdfs模块
- nginx-image模块和fastdfs module的协作
- 7. ubuntu 16.04 LTS 安装模块儿fastdfs-nginx-module
- FastDfs (三) Nginx整合Fastdfs模块
- FastDFS-nginx-module功能解释
- FastDFS+Nginx实现文件服务器
- nginx+FastDFS+fastdfs-nginx-module配置分布式文件存储
- Nginx+fastDFS-nginx-module+FastDFS配置分布式文件系统
- FastDFS+nginx+fastdfs-nginx-module服务器配置详解
- FastDFS+Nginx+fastdfs-nginx-module分布式存储环境搭建
- Nginx+fastDFS-nginx-module+FastDFS配置分布式文件系统
- 搭建FastDFS,Nginx,fastdfs-nginx-module图片资源服务器
- TCP三次握手分析、http登录密码抓取
- python使用tesseract-ocr完成验证码识别
- 国际化
- 开机或者安装系统时提示tsc: Fast TSC calibration failed解决方法
- 文思海辉面试
- FastDFS加载fastdfs-nginx-module模块,实现HTTP访问
- 计算广告基础知识(一)
- Java NIO系列教程(一) Java NIO 概述
- tomcat配置多个数据源
- 队内训练赛--A(Tree)
- Vuejs的一些总结
- 实验三:内部模块化的命令行菜单小程序V2.0
- 关于微信公众号scope参数错误或没有scope权限的解决方案
- <Qt>实例:TCP网络传输