Samba服务


Samba是SMB的一种实现方法,主要用来实现Linux系统的文件和打印服务。Linux用户通过配置使用Samba服务器可以实现与Windows用户的资源共享。守护进程smbd和nmbd是Samba的核心,在全部时间内运行。nmbd程序使得通过企图计算机可以浏览Linux服务器
配置命令
规划节点
IP 主机名 节点
内网地址192.168.0.188 Samba-server Sanmba服务节点

配置yum源

移除原有的本地repo文件,命令如下:

# mv /etc/yum.repos.d/* /media/

   
   
  • 1

创建本地Yum源文件local.repo。命令如下:

# vi /etc/yum.repos.d/local.repo           
# cat /etc/yum.repos.d/local.repo         
[samba]
name=samba
baseurl=file:///opt/samba
gpgcheck=0
enabled=1

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

验证本地repo文件是否配置成功,命令如下:

# yum clean all
Loaded plugins: fastestmirror, ovl
Cleaning repos: samba
Cleaning up list of fastest mirrors
Other repos take up 109 M of disk space (use --verbose for details)
# yum repolist
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
samba    | 2.9 kB  00:00:00
samba/primary_db    |  44 kB  00:00:00
repo id    repo name    status
samba    samba    29
repolist: 29

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

能看到repolist数量,即代表Yum源配置成功。

安装samba服务

samba-server节点安装Samba服务,命令如下:

[root@samba-server ~]# yum install -y samba

   
   
  • 1

samba-client节点安装samba-client服务和cifs-utils服务,命令如下:

[root@nfs-client ~]# yum install samba-client cifs-utils -y

   
   
  • 1

配置samba服务

在配置文件的最后,添加如下内容:

[root@samba-server ~]# vi /etc/samba/smb.conf
...
[share]
        path = /opt/share
        browseable = yes
        public = yes
        writable = yes

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

创建目录并赋予权限,命令如下:

[root@samba-server ~]# mkdir /opt/share
[root@samba-server ~]# chmod 777 /opt/share/

   
   
  • 1
  • 2

启动Samba服务,命令如下:

[root@samba-server ~]# systemctl start smb && systemctl enable smb
[root@samba-server ~]# systemctl start nmb && systemctl enable nmb

   
   
  • 1
  • 2

查看服务启动情况,命令如下:

[root@samba-server ~]# systemctl status smb
● smb.service - Samba SMB Daemon
   Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-05-27 15:50:55 CST; 1h 10min ago
     Docs: man:smbd(8)
           man:samba(7)
           man:smb.conf(5)
 Main PID: 2728 (smbd)
   Status: "smbd: ready to serve connections..."
   CGroup: /system.slice/smb.service
           ├─2728 /usr/sbin/smbd --foreground --no-process-group
           ├─2730 /usr/sbin/smbd --foreground --no-process-group
           ├─2731 /usr/sbin/smbd --foreground --no-process-group
           └─5881 /usr/sbin/smbd --foreground --no-process-group
May 27 15:50:55 samba systemd[1]: Starting Samba SMB Daemon...
May 27 15:50:55 samba smbd[2728]: [2020/05/27 15:50:55.837308,  0] ../lib/util/become_daemon.c:138(daemon_ready)
May 27 15:50:55 samba systemd[1]: Started Samba SMB Daemon.
May 27 15:50:55 samba smbd[2728]:   daemon_ready: STATUS=daemon 'smbd' finished starting up and ready to serve connections     

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

最后创建Samba用户。

[root@samba-server ~]# smbpasswd -a root    #这个用户必须是系统存在的用户
New SMB password:
Retype new SMB password:
Added user root.

   
   
  • 1
  • 2
  • 3
  • 4

重启Samba服务。

[root@samba-server ~]#  service smb restart  

   
   
  • 1

Windows环境使用Samba服务

若使用的是本地的服务器验证Samba服务,可以使用PC机访问。具体方法为,按PC机的“win+R”键,输入Samba服务器的IP地址,如下图所示:

输入地址后,单击“确定”按钮,输入用户名为root;密码为000000,即可像访问本地文件夹一样访问Samba服务,可以在共享的文件夹下增加、删除、修改、查看文件或目录。
Linux环境使用Samba服务


Linux环境使用Samba服务

(1)方法一使用smbclient命令

若使用实训平台验证Samba服务,需要用到samba-client节点,第一种访问方式为使用smbclient命令直接访问Samba服务器指定共享资源。命令如下:

[root@samba-client ~]# smbclient //192.168.0.188/share -U root
Enter SAMBA\root's password:                           //密码:000000
Try "help" to get a list of possible commands.
smb: \>

   
   
  • 1
  • 2
  • 3
  • 4

回到samba-server节点的共享目录/opt/share中,创建文件和目录用于实验,命令如下:

[root@samba-server share]# touch test.txt
[root@samba-server share]# mkdir xcloud
[root@samba-server share]# ll
total 4
-rw-r--r-- 1 root root    0 May 27 17:22 test.txt
drwxr-xr-x 2 root root 4096 May 27 17:22 xcloud

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

切换到samba-client节点,使用ls命令查看共享的资源,命令如下:

smb: \> ls
  .                                   D        0  Wed May 27 17:22:29 2020
  ..                                  D        0  Wed May 27 15:49:35 2020
  xcloud                              D        0  Wed May 27 17:22:29 2020
  test.txt                            N        0  Wed May 27 17:22:22 2020
	<span class="token number">40119584</span> blocks of size <span class="token number">1024.</span> <span class="token number">27520708</span> blocks available

smb: <span class=“token operator”>>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

可以使用get命令,将文件下载到本地,命令如下:

smb: \> get test.txt 
getting file \test.txt of size 0 as test.txt (0.0 KiloBytes/sec) (average nan KiloBytes/sec)
smb: \> ^C
[root@samba-client ~]# ll
total 0
-rw-r--r-- 1 root root 0 May 27 17:30 test.txt

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

(2)方法二使用挂载的方式

使用挂载的方式访问Samba共享目录,此方法和NFS挂载的方式类型,命令如下:

[root@samba-client ~]# mount -t cifs //192.168.0.188/share /mnt/ -o username=root
Password for root@//192.168.0.188/share:  ******
[root@samba-client ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               1.7G     0  1.7G   0% /dev
tmpfs                  1.7G     0  1.7G   0% /dev/shm
tmpfs                  1.7G   21M  1.7G   2% /run
tmpfs                  1.7G     0  1.7G   0% /sys/fs/cgroup
/dev/vda2               39G  2.5G   34G   7% /
/dev/vda1             1022M  9.1M 1013M   1% /boot/efi
tmpfs                  348M     0  348M   0% /run/user/0
//192.168.0.188/share   39G   13G   27G  32% /mnt

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

进入/mnt目录,可以查看共享的目录及文件,命令如下:

[root@samba-client mnt]# ll
total 0
-rwxr-xr-x 1 root root 0 May 27 17:22 test.txt
drwxr-xr-x 2 root root 0 May 27 17:22 xcloud

 
 
  • 1
  • 2
  • 3
  • 4

可以在此目录添加、删除、修改、查看文件或目录,samba-server节点会实时同步。创建文件验证,命令如下:

[root@samba-client mnt]# touch client.txt
[root@samba-client mnt]# ll
total 0
-rwxr-xr-x 1 root root 0 May 27 17:38 client.txt
-rwxr-xr-x 1 root root 0 May 27 17:22 test.txt
drwxr-xr-x 2 root root 0 May 27 17:22 xcloud

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

切换至samba-server节点,查看共享目录,命令如下:

[root@samba-server ~]# ll /opt/share/
total 4
-rwxr--r-- 1 root root    0 May 27 17:38 client.txt
-rw-r--r-- 1 root root    0 May 27 17:22 test.txt
drwxr-xr-x 2 root root 4096 May 27 17:22 xcloud

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值