拓扑图
安装mogilefs
本地安装的rpm包,下载地址http://down.51cto.com/data/2290310
MogileFS-Server-2.46-2.el6.noarch.rpm
perl-Danga-Socket-1.61-1.el6.rf.noarch.rpm
MogileFS-Server-mogilefsd-2.46-2.el6.noarch.rpm
perl-MogileFS-Client-1.14-1.el6.noarch.rpm
MogileFS-Server-mogstored-2.46-2.el6.noarch.rpm
perl-Perlbal-1.78-1.el6.noarch.rpm
MogileFS-Utils-2.19-1.el6.noarch.rpm
这些安装包网上不多,并且这些安装包的依赖没有定义好,需要手动解决依赖,需要安装如下的安装包,这些包大多来自于epel源中
1
|
yum
install
perl-Net-Netmask perl-IO-stringy perl-Sys-Syslog perl-IO-AIO -y
|
准备工作
数据库授权
1
2
3
|
GRANT ALL PRIVILEGES ON *.* TO ‘mguser’@‘172.16.29.%’ IDENTIFIED BY ‘mgpass’;
grant all on *.* to
'root'
@
'172.16.29.%'
identified by
'oldking'
;
FLUSH PRIVILEGES;
|
初始化数据库
1
|
mogdbsetup --dbhost=172.16.29.20 --dbname=mogilefs --dbrootpass=oldking --dbuser=mguser --dbpass=mgpass
|
tracker节点基本配置
vim /etc/mogilefs/mogilefsd.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
|
daemonize = 1
pidfile =
/var/run/mogilefsd/mogilefsd
.pid
#连接数据库的配置
db_dsn = DBI:mysql:mogilefs:host=172.16.29.20
db_user = mguser
db_pass = mgpass
#监听的端口
listen = 0.0.0.0:7001
conf_port = 7001
query_jobs = 10
delete_jobs = 1
replicate_jobs = 5
reaper_jobs = 1
|
启动tracker服务
1
|
service mogilefsd start
|
存储节点配置
vim /etc/mogilefs/mogstored.conf
1
2
3
4
5
|
maxconns = 10000
httplisten = 0.0.0.0:7500
mgmtlisten = 0.0.0.0:7501
#数据的目录
docroot =
/data
|
启动storage服务
1
|
su
- mogilefs -c
"mogstored -c /etc/mogilefs/mogstored.conf --daemon"
|
集群管理
添加节点
1
2
3
4
|
mogadm host add d1 --ip=172.16.29.10 --port=7500 --status=alive
mogadm host add d2 --ip=172.16.29.2 --port=7500 --status=alive
mogadm host add d3 --ip=172.16.29.20 --port=7500 --status=alive
mogadm host list
#查看节点状态
|
添加设备
1
2
3
4
|
mogadm device add d1 1
#这里的1是和d1的/data/dev1目录对应的,这也意味着一个节点可以有多个设备
mogadm device add d2 2
mogadm device add d3 3
mogadm device list
|
两个存储节点提供磁盘
1
2
3
4
5
6
|
mkdir
/data/dev1
chown
mogilefs.mogilefs
/data/dev1/
mkdir
/data/dev2
chown
mogilefs.mogilefs
/data/dev2/
mkdir
/data/dev3
chown
mogilefs.mogilefs
/data/dev3/
|
添加域
1
2
3
|
mogadm domain add files
mogadm domain add imgs
mogadm domain list
|
上传文件
1
|
mogupload --trackers=172.16.29.10 --domain=files --key=
'fstab.html'
--
file
=
'/etc/fstab'
|
查询文件
1
|
mogfileinfo --trackers=172.16.29.10 --domain=files --key=
'fstab.html'
|
使用浏览器访问,这一行的信息取决去mogfileinfo
http://172.16.29.2:7500/dev2/0/000/000/0000000004.fid
删除指定文件
mogdelete --trackers=172.16.29.10 --domain=<domain_name> --key=<key_name>
使用Nginx反向代理访问mogilefs内的文件
搭建这个服务器需要在centos6平台上,7上服务不能运行起来,拓扑图
模块使用指南网页http://www.grid.net.ru/nginx/mogilefs.en.html
编译Nginx和Nginx-mogilefs模块
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
下载模块文件并解压
wget http:
//nginx
.org
/download/nginx-1
.10.3.
tar
.gz
wget http:
//www
.grid.net.ru
/nginx/download/nginx_mogilefs_module-1
.0.4.
tar
.gz
tar
xf nginx-1.10.3.
tar
.gz
tar
xf nginx_mogilefs_module-1.0.4.
tar
.gz
安装开发包组合openssl和pcre
yum groupinstall
"Development Tools"
"Server Platform Deveopment"
-y
yum
install
openssl-devel pcre-devel -y
添加Nginx组和用户
groupadd -r nginx
useradd
-r -g nginx nginx
编译
cd
nginx-1.10.3
.
/configure
\
--prefix=
/usr
\
--sbin-path=
/usr/sbin/nginx
\
--conf-path=
/etc/nginx/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_flv_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-pcre \
--with-debug \
--add-module=
/root/nginx_mogilefs_module-1
.0.4
make
&&
make
install
|
Nginx配置成系统服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
vim
/etc/rc
.d
/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
chmod
+x
/etc/rc
.d
/init
.d
/nginx
chkconfig --add nginx
chkconfig nginx on
|
Nginx的配置文件如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
vim
/etc/nginx/nginx
.conf
#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 mogilefs {
server 172.16.29.10:7001;
server 172.16.29.2:7001;
}
server {
listen 80;
server_name yourdomain.com default;
location / {
mogilefs_tracker mogilefs;
mogilefs_domain files;
mogilefs_methods get;
mogilefs_pass {
proxy_pass $mogilefs_path;
proxy_hide_header Content-Type;
proxy_buffering off;
}
expires 1h;
}
error_page 500 502 503 504
/50x
.html;
location =
/50x
.html {
root html;
}
}
}
|
service nginx start
使用浏览器打开http://172.16.29.1/fstab.html
本文转自Ailu0li 51CTO博客,原文链接:http://blog.51cto.com/oldking/1902797,如需转载请自行联系原作者