如何配置 Ubuntu Hadoop 网络参数
导读:Ubuntu Hadoop 网络参数配置 一 基础网络与主机名解析 固定节点 IP(示例以 Ubuntu 18.04/20.04 的 Netplan 为例) 查看网卡名:ip link;编辑配置文件:sudo nano /etc/net...
Ubuntu Hadoop 网络参数配置
一 基础网络与主机名解析
- 固定节点 IP(示例以 Ubuntu 18.04/20.04 的 Netplan 为例)
- 查看网卡名:ip link;编辑配置文件:sudo nano /etc/netplan/00-installer-config.yaml
- 示例(将 eth0 替换为你的实际网卡名,如 ens33/enp0s3):
network: version: 2 ethernets: eth0: dhcp4: no addresses: [192.168.1.100/24] gateway4: 192.168.1.1 nameservers: addresses: [8.8.8.8, 1.1.1.1] - 应用:sudo netplan apply;验证:ip addr、ping 网关、ping 外网域名
- 主机名与解析
- 设置主机名:sudo hostnamectl set-hostname master(各节点分别设为 master/slave1/slave2)
- 统一解析:编辑 /etc/hosts
192.168.1.100 master 192.168.1.101 slave1 192.168.1.102 slave2
- 免密 SSH(集群内互通)
- 生成密钥:ssh-keygen -t rsa -b 4096
- 分发公钥:ssh-copy-id master;ssh-copy-id slave1;ssh-copy-id slave2
- 防火墙(测试环境可先放行,生产按需开放)
- Ubuntu:sudo ufw allow from 192.168.1.0/24;或 sudo ufw disable(仅测试)
二 Hadoop 关键网络参数配置
- 建议优先使用主机名(已在 /etc/hosts 或 DNS 中可解析),便于节点迁移与扩容
- 配置文件路径:$HADOOP_HOME/etc/hadoop/
core-site.xml
<
configuration>
<
!-- 默认文件系统地址(主机名或IP均可) -->
<
property>
<
name>
fs.defaultFS<
/name>
<
value>
hdfs://master:8020<
/value>
<
/property>
<
/configuration>
hdfs-site.xml
<
configuration>
<
!-- 副本数:生产常用 3 -->
<
property>
<
name>
dfs.replication<
/name>
<
value>
3<
/value>
<
/property>
<
!-- NameNode RPC 地址(主机名) -->
<
property>
<
name>
dfs.namenode.rpc-address<
/name>
<
value>
master:8020<
/value>
<
/property>
<
!-- NameNode HTTP UI -->
<
property>
<
name>
dfs.namenode.http-address<
/name>
<
value>
master:50070<
/value>
<
/property>
<
!-- DataNode 数据传输端口 -->
<
property>
<
name>
dfs.datanode.address<
/name>
<
value>
0.0.0.0:50010<
/value>
<
/property>
<
!-- DataNode IPC -->
<
property>
<
name>
dfs.datanode.ipc.address<
/name>
<
value>
0.0.0.0:50020<
/value>
<
/property>
<
!-- 可选:关闭 IP/主机名校验(仅当你的网络环境必须使用 IP 直连且 DNS/hosts 不一致时) -->
<
!-- <
property>
<
name>
dfs.namenode.datanode.registration.ip-hostname-check<
/name>
<
value>
false<
/value>
<
/property>
-->
<
/configuration>
yarn-site.xml
<
configuration>
<
!-- ResourceManager 主机名 -->
<
property>
<
name>
yarn.resourcemanager.hostname<
/name>
<
value>
master<
/value>
<
/property>
<
!-- Shuffle 服务 -->
<
property>
<
name>
yarn.nodemanager.aux-services<
/name>
<
value>
mapreduce_shuffle<
/value>
<
/property>
<
property>
<
name>
yarn.nodemanager.aux-services.mapreduce_shuffle.class<
/name>
<
value>
org.apache.hadoop.mapred.ShuffleHandler<
/value>
<
/property>
<
/configuration>
mapred-site.xml
<
configuration>
<
!-- 使用 YARN 作为执行框架 -->
<
property>
<
name>
mapreduce.framework.name<
/name>
<
value>
yarn<
/value>
<
/property>
<
/configuration>
- 说明
- 端口如 8020/50070/50010/50020 为常用默认值,若端口冲突或被占用,可调整为未被占用的端口并在防火墙放行对应端口。
三 系统级网络优化(可选)
- 编辑 /etc/sysctl.conf,提升并发与连接能力(按硬件与业务调优)
net.ipv4.ip_local_port_range = 1024 65535 net.core.somaxconn = 1024 net.core.netdev_max_backlog = 1024 net.ipv4.tcp_max_syn_backlog = 1024 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_fin_timeout = 30 - 应用:sudo sysctl -p
- 说明:上述为通用起点,生产环境请结合监控与压测逐步调优。
四 启动与验证
- 首次启动前格式化 NameNode(仅一次):hdfs namenode -format
- 启动集群:start-dfs.sh;start-yarn.sh
- 基本验证
- HDFS:hdfs dfsadmin -report(查看 Live datanodes 数量与容量)
- YARN:yarn node -list(查看 Active Nodes)
- Web UI:http://master:50070(NameNode);http://master:8088(ResourceManager)
- 连通性自检
- 节点互通:ping master/slave1/slave2
- 端口连通:nc -vz master 8020;nc -vz master 50070;nc -vz slave1 50010
- 变更生效
- Hadoop 配置修改后需重启相应进程(如 stop-dfs.sh/start-dfs.sh;stop-yarn.sh/start-yarn.sh)。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 如何配置 Ubuntu Hadoop 网络参数
本文地址: https://pptw.com/jishu/784765.html
