最近有个需求需要实现windows 上直接访问Hadoop HDFS 文件系统,并设置相关权限,
前提条件:
1.hadoop 健康集群一个
2.centos7 系统一个
3. hadoop-fuse-dfs 安装软件
4. samba4 安装软件
第一步: 安装hadoop-fuse-dfs
使用root用户登陆centos7
修Ccentos-base.repo
添加以下内容到文件最后:
[cloudera-cdh5]
# Packages for Cloudera's Distribution for Hadoop, Version 5, on RedHat or CentOS 6 x86_64
name=Cloudera's Distribution for Hadoop, Version 5
baseurl=https://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/5/
gpgkey =https://archive.cloudera.com/cdh5/redhat/6/x86_64/cdh/RPM-GPG-KEY-cloudera
gpgcheck = 1
然后执行:
yum install -y hadoop-fuse-dfs
yum install -y samba
如果下载慢,可以到国外服务器上下载,然后拷贝回本地安装。
yum install -y --downloadonly --downloaddir=/tmp/hadoop-fuse-dfs hadoop-fuse-dfs
tar -czf hadoop-fuse-dfs.tgz /tmp/hadoop-fuse-dfs
yum install -y --downloadonly --downloaddir=/tmp/samba samba
tar -czf samba.tgz /tmp/samba
echo “或者从下面2个连接下载 http://nexus.nps.xszq.vip/samba.tgz . http://nexus.nps.xszq.vip/hadoop-hdfs-fuse.tgz”
scp hadoop-fuse-dfs.tgz 到目标机器
scp samba.tgz 到目标机器
或wget http://nexus.nps.xszq.vip/samba.tgz
wget http://nexus.nps.xszq.vip/hadoop-hdfs-fuse.tgz
cd /root
tar -zxvf hadoop-hdfs-fuse.tgz
cd hadoop-hdfs-fuse
yum -y localinstall *.rpm
cd /root/
tar -zxvf samba.tgz
cd samba
yum -y localinstaall *.rpm
echo “请检查是非安装成功.”
mkdir -p /var/server/share
chmod 777 /var/server/share
echo “执行挂载hdfs”
echo "10.6.1.13:8020 是active namenode "
hadoop-fuse-dfs -o allow_other,usetrash,nonempty dfs://10.6.1.13:8020 /mnt/hdfs
ls -al /var/server/share
#执行samba配置,把/var/server/share共享出去.
请查看samb 相关配置
查看samba的版本
#smbd --version
#Version 4.9.1
/etc/samba/smb.conf 内容如下
[root@localhost ~]# more /etc/samba/smb.conf
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[global]
workgroup = SAMBA
security = user
socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=65536 SO_SNDBUF=65536
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
log level = 3 passdb:5 auth:5
[Anonymous]
path=/var/server/nginx/download.cityworks.cn
read only = no
guest ok = yes
[hdfs]
comment = HDFS
path = /mnt/hdfs
public = yes
writable = yes
printable = no
create mask = 0744
valid users = nobody hadoop hdfs centos
force user = hadoop
force group = hadoop
available = yes
browseable = yes
workgroup = WORKGROUP
display charset = UTF-8
unix charset = UTF-8
[Share]
guest ok = yes
public = yes
path=/var/server/share
writable = yes
valid users = centos
create mask = 0700
directory mask = 0700
force user = nobody
force group = nogroup
available = yes
browseable = yes
workgroup = WORKGROUP
display charset = UTF-8
unix charset = UTF-8
dos charset = cp936
[secured]
path = /var/server/nginx.cityworks.cn
valid users = @smbgrp
read only = No
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = root
create mask = 0664
directory mask = 0775
#创建一个本地账号hadoop,并设置密码
[root@localhost ~]# useradd hadoop
passwd hadoop
#设置smb用户 hadoop的密码
smbpasswd hadoop
这个2个密码要设置一样.
关闭selinux
#setenforce 0
然后重新启动smb 服务
systemctl enable smb.service
systemctl enable nmb.service
systemctl restart smb.service
systemctl restart nmb.service
samba 需要打开对于的网络端口
firewall-cmd --permanent --zone=public --add-service=samba
firewall-cmd --reload
关于samba 的安装 可以使用ansible 自动安装
https://github.com/HappyFreeAngel/ansible-samba.git
测试:使用window10 打开 \192.168.2.47
会提示输入用户和密码 输入 hadoop 和你的刚才设置的密码
打开hdfs 文件夹
经测试工作正常。
这里可以直接拷贝或创建文件到 hdfs文件夹,马上hadoop 里就可以看到了。
如果要永久关闭selinux 并立即生效,执行下面代码.
echo “永久关闭selinux”
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/sysconfig/selinux
setenforce 0
如果希望系统重新启动,还可以正常访问,则修改/etc/fstab 内容
增加一行
hadoop-fuse-dfs#dfs://10.6.1.13:8020 /mnt/hdfs fuse allow_other,nonempty,usetrash,rw 0 0
记得把IP改为你的hadoop IP 地址
坑: selinux 必须关闭,否则会导致无法浏览.
[root@localhost ~]# setenforce 0
[root@localhost ~]# service smb restart
Redirecting to /bin/systemctl restart smb.service
Mac 电脑访问方式:
1.随便打开一个文件夹
2.点击 最上面的 “前往“ , 然后鼠标移动到 弹出菜单的 最下面“连接服务器…" 点击 “连接服务器…"
3. 在弹出的对话框内输入你的centos7 地址 smb://你的IP地址 然后点击连接即可。