mogilefs雜記(2)
阿新 • • 發佈:2018-03-15
mogilefs 集群 基礎 雜記mogilefs集群
Nginx反代mogilefs
1、編譯安裝Nginx
1.1 安裝編譯環境
安裝編譯環境:
yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel patch
1.2 編譯安裝
[root@master1 ~]# ls nginx_mogilefs_module-1.0.4.tar.gz tengine-2.0.1.tar.gz 展開壓縮包: [root@master1 ~]# tar xf nginx_mogilefs_module-1.0.4.tar.gz [root@master1 ~]# tar xf tengine-2.0.1.tar.gz 1.2.1 創建用戶和組 [root@master1 ~]# groupadd -r nginx [root@master1 ~]# useradd -r -g nginx nginx 1.2.2 編譯安裝 [root@master1 tengine-2.0.1]# ./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 --with-pcre --with-debug --add-module=../nginx_mogilefs_module-1.0.4 [root@master1 tengine-2.0.1]# make 報錯: ../nginx_mogilefs_module-1.0.4/ngx_http_mogilefs_module.c: In function ‘ngx_http_mogilefs_create_spare_location’: ../nginx_mogilefs_module-1.0.4/ngx_http_mogilefs_module.c:1532:39: error: variable ‘pclcf’ set but not used [-Werror=unused-but-set-variable] ngx_http_core_loc_conf_t *clcf, *pclcf, *rclcf; 配合文件去除Werror [root@master1 tengine-2.0.1]# vim objs/Makefile CC = cc CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -g [root@master1 tengine-2.0.1]# make install
2、配置啟動腳本
[root@master1 tengine-2.0.1]# vim /usr/lib/systemd/system/nginx.service [Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/var/run/nginx/nginx.pid ExecStartPre=/usr/sbin//nginx -t ExecStart=/usr/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID KillMode=process KillSignal=SIGQUIT TimeoutStopSec=5 PrivateTmp=true [Install] WanteBy=multi-user.target —————— [root@master1 tengine-2.0.1]# systemctl daemon-reload 啟動 [root@master1 tengine-2.0.1]# systemctl start nginx.service
3、nginx配置文件
3.1 nginx配置
備份配置文件 [root@master1 nginx]# cp nginx.conf nginx.conf.bak 關閉VIM搜索高亮: :nohl 配置: [root@master1 nginx]# vim nginx.conf 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 ~([^\/]+)$ { mogilefs_tracker 10.201.106.132:7001; mogilefs_domain img; mogilefs_methods GET; mogilefs_noverify on; mogilefs_pass { proxy_pass $mogilefs_path; proxy_hide_header Content-Type; proxy_buffering off; } #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; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; root html; index index.html index.htm; } location /images { mogilefs_tracker 10.201.106.132:7001; mogilefs_domain imgs; mogilefs_methods GET; mogilefs_noverify on; mogilefs_pass { proxy_pass $mogilefs_path; proxy_hide_header Content-Type; proxy_buffering off; } } 語法測試: [root@master1 nginx]# nginx -t the configuration file /etc/nginx/nginx.conf syntax is ok configuration file /etc/nginx/nginx.conf test is successful 重新載入服務: [root@master1 nginx]# systemctl reload nginx.service 訪問測試: http://10.201.106.131/images/1.jpg
3.2 更改路徑測試
[root@master1 ~]# vim /etc/nginx/nginx.conf
location /images/ {
}
[root@master1 ~]# systemctl reload nginx.service
tracker配置
[root@master2 ~]# mogdelete --trackers=10.201.106.132:7001 --domain=imgs --key=‘/1.jpg‘
[root@master2 ~]# mogdelete --trackers=10.201.106.132:7001 --domain=imgs --key=‘/2.jpg‘
去掉斜線,重新上傳:
[root@master2 ~]# mogupload --trackers=10.201.106.132:7001 --domain=imgs --class=jpeg --key=‘2.jpg‘ --file=‘/root/2.jpg‘
[root@master2 ~]# mogupload --trackers=10.201.106.132:7001 --domain=imgs --class=jpeg --key=‘1.jpg‘ --file=‘/root/2.jpg‘
測試:
http://10.201.106.131/images/1.jpg
4、增加tracerk節點,消除tracerk單點隱患
4.1 拷貝tracerk節點的配置文件到另外兩個節點
[root@master2 ~]# scp /etc/mogilefs/mogilefsd.conf master3:/etc/mogilefs/
root@master3‘s password:
mogilefsd.conf 100% 1464 1.4KB/s 00:00
[root@master2 ~]#
[root@master2 ~]# scp /etc/mogilefs/mogilefsd.conf master4:/etc/mogilefs/
root@master4‘s password:
mogilefsd.conf
[root@master3 ~]# systemctl start mogilefsd.service
[root@master4 ~]# systemctl start mogilefsd.service
4.2 測試訪問
[root@master2 ~]# moglistkeys --trackers=10.201.106.133:7001 --domain=imgs
1.jpg
2.jpg
[root@master2 ~]# moglistkeys --trackers=10.201.106.134:7001 --domain=imgs
1.jpg
2.jpg
4.3 nginx設置負載均衡
[root@master1 ~]# vim /etc/nginx/nginx.conf
upstream trackers {
server 10.201.106.132:7001 weight=1;
server 10.201.106.133:7001 weight=1;
server 10.201.106.134:7001 weight=1;
#以下配置只在TNGINX有用
check interval=1000 rise=2 fall=5 timeout=1000;
# check_keepalive_request 100;
# check_http_send "GET / HTTP/1.0\r\n\r\n";
# check_http_expect_alive http_2xx http_3xx;
}
server {
location /images/ {
mogilefs_tracker trackers;
[root@master1 ~]# nginx -t
the configuration file /etc/nginx/nginx.conf syntax is ok
configuration file /etc/nginx/nginx.conf test is successful
[root@master1 ~]# systemctl reload nginx.service
4.4 訪問測試
http://10.201.106.131/images/1.jpg
http://10.201.106.131/images/2.jpg
4.5 打開nginx狀態頁,查看後端健康情況
[root@master1 ~]# vim /etc/nginx/nginx.conf
server {
location /status {
check_status;
access_log off;
#allow SOME.IP.ADD.RESS;
#deny all;
}
[root@master1 ~]# nginx -t
the configuration file /etc/nginx/nginx.conf syntax is ok
configuration file /etc/nginx/nginx.conf test is successful
[root@master1 ~]# systemctl reload nginx.service
測試:
http://10.201.106.131/status
關閉一個節點,測試狀態頁面:
[root@master4 ~]# systemctl stop mogilefsd.service
5、
mogilefs雜記(2)