【Ambari Plus】Step5—Nginx 本地 Yum 文件服务 Step5—Nginx 本地 Yum 文件服务Ambari Plus 安装包已经放在/data/modules但其他节点不能直接读核心节点的本地目录。这里要做一层 Nginx 文件服务把这个目录通过 HTTP 暴露出去。后面 RHEL 系写.repo、Ubuntu 写本地 APT 源都会指向这个地址。本文约定项目值核心节点hadoop1.test.com仓库目录/data/modulesHTTP 地址http://hadoop1.test.com/安装 Nginx只在核心节点hadoop1.test.com安装。sudodnf-yinstallnginx||sudoyum-yinstallnginxsudosystemctlenable--nownginxsudoaptupdatesudoaptinstall-ynginxsudosystemctlenable--nownginx检查服务systemctl is-active nginx准备目录权限Nginx 要能读取/data/modulessudomkdir-p/data/modulessudochmod-R755/data/modulesRHEL 系如果开启 SELinux还要处理上下文。临时验证可以用chcon正式环境建议写成持久规则getenforcesudosemanage fcontext-a-thttpd_sys_content_t/data/modules(/.*)?sudorestorecon-Rv/data/modules如果系统没有semanage先安装sudodnf-yinstallpolicycoreutils-python-utils||\sudoyum-yinstallpolicycoreutils-python-utils如果getenforce显示Disabled可以跳过这一段。写入站点配置在核心节点创建 Nginx 配置sudotee/etc/nginx/conf.d/ambari-plus-repo.conf/dev/nullEOF server { listen 80; server_name hadoop1.test.com 192.168.3.101 localhost; root /data/modules; index index.html index.htm; location / { allow 192.168.3.0/24; allow 127.0.0.1; deny all; autoindex on; autoindex_exact_size off; autoindex_localtime on; try_files $uri $uri/ 404; } types { application/xml xml; application/x-rpm rpm; text/plain repomd; } } EOF这里的server_name和allow 192.168.3.0/24按你的核心节点主机名、IP 和集群网段修改。root /data/modules不要写错否则后面仓库地址能打开但找不到包。测试并启动sudonginx-tsudosystemctl restart nginxsudosystemctlenablenginx放通 HTTP 端口如果启用了防火墙sudofirewall-cmd --add-servicehttp--permanentsudofirewall-cmd--reloadsudoufw allow80/tcpsudoufw reload云主机还要检查安全组是否允许工作节点访问核心节点 80 端口。先做目录访问验证在核心节点执行curl-HHost: hadoop1.test.com-Ihttp://127.0.0.1/curl-HHost: hadoop1.test.comhttp://127.0.0.1/|head在工作节点执行curl-Ihttp://hadoop1.test.com/curlhttp://hadoop1.test.com/|head如果返回200 OK或能看到目录索引说明 Nginx 文件服务已经通了。::: warning 访问范围这里打开了autoindex读者可以直接看到/data/modules下的包名。实验环境问题不大生产内网我建议至少保留上面的allow/deny并配合防火墙或安全组只允许集群网段访问。:::常见问题现象原因处理nginx -t失败配置语法错误检查大括号、分号和try_files本机能访问工作节点不能访问防火墙或安全组未放通放通 80/tcp403 ForbiddenNginx 没有目录权限、SELinux 拦截或不在允许网段检查权限、restorecon和allow网段404 Not Foundroot目录写错确认配置指向/data/modules本机127.0.0.1访问到默认页命中了默认站点用curl -H Host: hadoop1.test.com http://127.0.0.1/验证Nginx 通过后核心节点就具备了本地文件服务能力下一步准备 JDK 双环境。