好了下面就可以上传一下文件试一下看看了
上传图片文件
[root@www ~]# mogupload --trackers=172.16.6.20:7001 --domain=images --key='/a.jepg' --file='/root/75b4519340.jpg'
上传文本文件
[root@www ~]# mogupload --trackers=172.16.6.20:7001 --domain=files --key='/init.html' --file='/etc/inittab'
查看文件的fid进行访问
[root@www ~]# mogfileinfo --trackers=172.16.6.20:7001 --domain=images --key='/a.jepg'
- file: /a.jepg
class: default
devcount: 2
domain: images
fid: 4
key: /a.jepg
length: 432441
- http://172.16.6.30:7500/dev2/0/000/000/0000000004.fid
- http://172.16.6.20:7500/dev1/0/000/000/0000000004.fid

[root@www ~]# mogfileinfo --trackers=172.16.6.20:7001 --domain=files --key='/init.html'
- file: /init.html
class: default
devcount: 2
domain: files
fid: 5
key: /init.html
length: 884
- http://172.16.6.20:7500/dev1/0/000/000/0000000005.fid
- http://172.16.6.30:7500/dev2/0/000/000/0000000005.fid

OK,成功了。
但是如果是通过fid来访问的方式实在是太过拙劣,我们能不能通过直接访问如172.16.6.20/a.jpeg这种方式来访问呢
没错,那这就是用nginx来反向代理的意义了,我们可以通过nginx上的mogilefs模块来实现这种功能,那么下面就来让我们安装配置吧
nginx的编译安装
由于yum安装的nginx不支持mogilefs这个模块,因此我们只能编译安装了
编译之前确保编译环境准备就绪
# yum groupinstall "Development Tools" "Server Platform Deveopment"
# yum install openssl-devel pcre-devel
下面我们需要编译安装的包已经模块包
这里我已经下载好了
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog mogilefs nginx-1.6.1.tar.gz nginx_mogilefs_module-1.0.4.tar.gz
创建系统用户nginx
[root@localhost nginx-1.6.1]# groupadd -r nginx
[root@localhost nginx-1.6.1]# useradd -g nginx -r nginx
2个包都进行解压
[root@localhost ~]# tar xf nginx-1.6.1.tar.gz
[root@localhost ~]# tar xf nginx_mogilefs_module-1.0.4.tar.gz
编译安装nginx
[root@localhost ~]# cd nginx-1.6.1

[root@localhost nginx-1.6.1]# make && make install
ok,安装完毕
修改配置文件使nginx进行反向代理
[root@localhost nginx-1.6.1]# vim /etc/nginx/nginx.conf
以下yellow字体为加入的配置
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream trackers { 定义上流服务器集群
server 172.16.6.20:7001;
server 172.16.6.30:7001;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location ~* ^(/img/.*)$ { 注意为了方便起见,这里我只是对图片这个区域进行了定义,
mogilefs_tracker trackers; 这里 并没有对其他区域定义,对其他区域定义的方式也一样
mogilefs_domain images; 指定区域
mogilefs_noverify on;
mogilefs_pass $1{
proxy_pass $mogilefs_path;
proxy_hide_header Content-Type;
proxy_buffering off;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
为nginx提供类似service的启动脚本
[root@localhost nginx-1.6.1]# 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/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
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
}
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
给予执行权限
[root@localhost nginx-1.6.1]# chmod +x /etc/init.d/nginx
启动服务
root@localhost nginx-1.6.1]# service nginx start
Starting nginx: [ OK ]
OK,下面我们就可以测试下了
先传一张图片到服务器上
[root@www ~]# mogupload --trackers=172.16.6.20:7001 --domain=images --key='/img/a.jpg' --file='/root/75b4519340.jpg'
OK,下面我们直接用key的路径进行访问

OK,实验完成。
那么本节的内容就讲到这里,欢迎大家的批评指正,谢谢!
本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-10/107519.htm
