赞
踩
NGINX 代理是非常常见的,内网生成环境一般不让在本机直接访问,这时候就得利用代理,但是一般代理就得脱敏或去掉页面上的高危操作。这里就拿 YARN 代理来讲解。这里也会涉及到 subs_filter
讲解,如果对 subs_filter
不理解的小伙伴,可以先查阅我这篇文章:NGINX sub_filter和subs_filter 指令讲解
Hadoop 的部署可以参考我之前的以下几篇文章:
这里部署的是基于GitHub上的一个项目:https://github.com/HBigdata/yarn-reverse-proxy
# 安装yum-config-manager配置工具
yum -y install yum-utils
# 建议使用阿里云yum源:(推荐)
#yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 安装docker-ce版本
yum install -y docker-ce
# 启动并开机启动
systemctl enable --now docker
docker --version
curl -SL https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
dnsmasq
先去解析 /etc/hosts
文件。/etc/dnsmasq.d/
下的 *.conf
文件,并且这些文件的优先级要高于 /etc/dnsmasq.conf
。resolv.dnsmasq.conf
中的 DNS
也被称为上游 DNS
,这是最后去查询解析的。yum install -y dnsmasq
systemctl start dnsmasq.service
把 hadoop
相关的主机名映射都提前配置到 /etc/hosts
文件中。
想了解更多,可以参考我这篇文章:dnsmasq( DNS和DHCP)服务
git clone https://github.com/HBigdata/yarn-reverse-proxy.git
cd yarn-reverse-proxy-master
cp docker-compose.example.yml docker-compose.yml
version: '3'
services:
app:
build: .
#expose:
# - 80
## WARNING: uncomment the following only if you are
## not directly exposing a non-kerberized cluster
## to the Internet
# ports:
# - "5555:80"
environment:
TZ : 'Asia/Shanghai'
dns:
- localhost
ports:
- "80:80"
# 指定 DNS 服务
environment:
# Because your primary resource-manager is at /rm1
# access your main status page at $SERVER_URL_BASE/rm1
SERVERS: "hostname-rm-110:8088@rm110
hostname-rm-111:8088@rm111
hostname-nm-112:8042@nm112
hostname-nm-113:8042@nm113
hostname-nm-114:8042@nm114
hostname-nm-115:8042@nm115
hostname-nm-116:8042@nm116
hostname-nm-117:8042@nm117
hostname-nm-118:8042@nm118
hostname-jn-119:19888@jh119"
RESOLVER: YOUR_NETWORKS_DNS_SERVER # or 127.0.0.11 for the system resolver
SERVER_URL_BASE: http://REVERSE_PROXY_HOSTNAME:80
需要修改的地方:
SERVERS
、REVERSE_PROXY_HOSTNAME
dns
地址记得更好成自己的 dns
机器。docker-compose build
docker-compose up -d
如果nm节点太多了,都遍历代理的话,就导致超过NGINX配置的长度的,太长配置也影响阅读,所以这里就通过 nginx subs_filter
进行改进。
subs_filter
的部署与用法可以参考我这篇文章:NGINX sub_filter和subs_filter 指令讲解
通过正则表达式修改 run.sh
# 将这段内容替换成正则
cat <<EOF
# Rewrite references without the scheme, e.g. //google.com
sub_filter 'src="//$REWRITE_NAME:$REWRITE_PORT' 'src="$SERVER_URL_BASE/$REWRITE_ALIAS';
sub_filter 'href="//$REWRITE_NAME:$REWRITE_PORT' 'href="$SERVER_URL_BASE/$REWRITE_ALIAS';
sub_filter 'href=\'//$REWRITE_NAME:$REWRITE_PORT' 'href=\'$SERVER_URL_BASE/$REWRITE_ALIAS';
# Rewrite all absolute references, regardless of where
# they appear in the page
sub_filter 'http://$REWRITE_NAME:$REWRITE_PORT/' '$SERVER_URL_BASE/$REWRITE_ALIAS/';
sub_filter 'http://$REWRITE_NAME:$REWRITE_PORT' '$SERVER_URL_BASE/$REWRITE_ALIAS';
proxy_redirect http://$REWRITE_NAME:$REWRITE_PORT/ $SERVER_URL_BASE/$REWRITE_ALIAS/;
EOF
# 示例替换
cat <<EOF
# Rewrite references without the scheme, e.g. //google.com
sub_filter 'src="//local-168-(\w+)-(\d+):$REWRITE_PORT' 'src="$SERVER_URL_BASE/\$1\$2' g r;
sub_filter 'href="//local-168-(\w+)-(\d+):$REWRITE_PORT' 'href="$SERVER_URL_BASE/\$1\$2' g r;
sub_filter 'href=\'//local-168-(\w+)-(\d+):$REWRITE_PORT' 'href=\'$SERVER_URL_BASE/\$1\$2' g r;
# Rewrite all absolute references, regardless of where
# they appear in the page
sub_filter 'http://local-168-(\w+)-(\d+):$REWRITE_PORT/' '$SERVER_URL_BASE/\$1\$2/' g r;
sub_filter 'http://local-168-(\w+)-(\d+):$REWRITE_PORT' '$SERVER_URL_BASE/\$1\$2' g r;
proxy_redirect http://local-168-(\w+)-(\d+):$REWRITE_PORT/ $SERVER_URL_BASE/\$1\$2/ g r;
EOF
yarn-proxy on k8s
部署跟 docker-compose
差不多,这里就不再重复讲解了,有任何疑问欢迎给我留言或私信。
NGINX 实战操作(yarn-proxy)讲解就先到这里了,有任何疑问也可关注我公众号:大数据与云原生技术分享,进行技术交流,如本篇文章对您有所帮助,麻烦帮忙一键三连(点赞、转发、收藏)~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。