拓扑图
安装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源中
yum install perl-Net-Netmask perl-IO-stringy perl-Sys-Syslog perl-IO-AIO -y
准备工作
数据库授权
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;
初始化数据库
mogdbsetup --dbhost=172.16.29.20 --dbname=mogilefs --dbrootpass=oldking --dbuser=mguser --dbpass=mgpass
tracker节点基本配置
vim /etc/mogilefs/mogilefsd.conf
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服务
service mogilefsd start
存储节点配置
vim /etc/mogilefs/mogstored.conf
maxconns = 10000 httplisten = 0.0.0.0:7500 mgmtlisten = 0.0.0.0:7501 #数据的目录 docroot = /data
启动storage服务
su - mogilefs -c "mogstored -c /etc/mogilefs/mogstored.conf --daemon"
集群管理
添加节点
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 #查看节点状态
添加设备
mogadm device add d1 1 #这里的1是和d1的/data/dev1目录对应的,这也意味着一个节点可以有多个设备 mogadm device add d2 2 mogadm device add d3 3 mogadm device list
两个存储节点提供磁盘
mkdir /data/dev1 chown mogilefs.mogilefs /data/dev1/ mkdir /data/dev2 chown mogilefs.mogilefs /data/dev2/ mkdir /data/dev3 chown mogilefs.mogilefs /data/dev3/
添加域
mogadm domain add files mogadm domain add imgs mogadm domain list
上传文件
mogupload --trackers=172.16.29.10 --domain=files --key=‘fstab.html‘ --file=‘/etc/fstab‘
查询文件
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模块
下载模块文件并解压 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配置成系统服务
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的配置文件如下
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