准备

  • Centos7 VPS一台
  • SSH工具

查看系统信息

[root@localhost ~]# cat /etc/redhat-release

查看yum源中SAMBA版本

[root@localhost ~]# yum list | grep samba

查看Centos7 IP地址

[root@localhost ~]# ifconfig
或者
[root@localhost ~]# ip address

防火墙

关闭防火墙

[root@localhost ~]# systemctl stop firewalld.service

禁止防火墙开机启动

[root@localhost ~]# systemctl disable firewalld.service

查看防火墙状态

[root@hadoop101 ~]# firewall-cmd --state

关闭SeLinux

临时性关闭

[root@localhost ~]# setenforce 0

永久性关闭

[root@hadoop101 ~]# vim /etc/sysconfig/selinux
SELINUX=disabled

永久关闭SeLinux,需要重启机器,修改配置文件/etc/selinux/config,将SELINU置为disabled

重启后使用命令检查,查看SELinux状态

[root@hadoop101 ~]# getenforce
Disabled
 
[root@hadoop101 ~]# sestatus -v
SELinux status:                 disabled
 
[root@localhost ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          error (Success)
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28

开始安装

安装Samba服务

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

查看安装状况

[root@hadoop101 /]# rpm -qa | grep samba
samba-4.8.3-4.el7.x86_64
samba-client-libs-4.8.3-4.el7.x86_64
samba-libs-4.8.3-4.el7.x86_64
samba-common-4.8.3-4.el7.noarch
samba-common-libs-4.8.3-4.el7.x86_64
samba-common-tools-4.8.3-4.el7.x86_64
samba-client-4.8.3-4.el7.x86_64

管理命令

[root@hadoop101 /]# systemctl start smb.service #启动smb
[root@hadoop101 /]# systemctl status smb.service #查看smb
[root@hadoop101 /]# systemctl start nmb.service #启动nmb
[root@hadoop101 /]# systemctl status nmb.service #查看nmb

SMB开机自启动

[root@hadoop101 ~]# chkconfig smb on
Note: Forwarding request to 'systemctl enable smb.service'.
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.

nmb开机自启动

[root@hadoop101 ~]# chkconfig nmb on
Note: Forwarding request to 'systemctl enable nmb.service'.
Created symlink from /etc/systemd/system/multi-user.target.wants/nmb.service to /usr/lib/systemd/system/nmb.service.

查看Samba服务进程

[root@hadoop101 ~]# ps -ef | grep -E 'smb|nmb'
root       3040      1  0 16:56 ?        00:00:00 /usr/sbin/smbd --foreground --no-process-group
root       3042   3040  0 16:56 ?        00:00:00 /usr/sbin/smbd --foreground --no-process-group
root       3043   3040  0 16:56 ?        00:00:00 /usr/sbin/smbd --foreground --no-process-group
root       3044   3040  0 16:56 ?        00:00:00 /usr/sbin/smbd --foreground --no-process-group
root       3067      1  0 16:57 ?        00:00:00 /usr/sbin/nmbd --foreground --no-process-group
root       3144   2871  0 16:59 pts/0    00:00:00 grep --color=auto -E smb|nmb

备份配置文件

[root@hadoop101 ~]# cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

需求描述

公司现有一个工作组workgroup,需要添加samba服务器作为文件服务器,并发布共享目录 /share,共享名为 public,此共享目录允许所有员工访问

编辑配置文件

[root@hadoop101 ~]# vim /etc/samba/smb.conf
[global]
    workgroup = WORKGROUP
    security = user
    map to guest = Bad User
    server string = alex Samba Server Version %v
    netbios name = alexSamba
    log file = /var/log/samba/log.%m
[public]
    comment = Public Stuff
    path = /opt/module/share
    public = yes
    guest ok = yes
    writeable = yes
    available = yes
    browseable = yes

创建目录

[root@hadoop101 ~]# mkdir -p /opt/module/share
[root@hadoop101 ~]# echo 123 /opt/module/share/a.txt

重启服务

[root@hadoop101 ~]# systemctl restart smb
[root@hadoop101 ~]# systemctl restart nmb
[root@hadoop101 ~]# systemctl status smb
[root@hadoop101 ~]# systemctl status nmb

测试检查smb.conf 配置是否正确

[root@hadoop101 ~]# testparm

客户端连接

Linux客户端连接

[root@hadoop101 /]# smbclient //192.168.2.121/public
Enter WORKGROUP\root's password: 
Try "help" to get a list of possible commands.
smb: \> ls
  .                                   D        0  Mon Apr 15 17:16:15 2019
  ..                                 DR        0  Mon Apr 15 17:15:53 2019
  samba.txt                           N        0  Mon Apr 15 17:16:10 2019
  aa.txt                              N        0  Mon Apr 15 17:16:15 2019
 
        52403200 blocks of size 1024. 46628252 blocks available
smb: \> quit

window 连接

window + R ->  \\192.168.2.121\public
最后修改:2022 年 11 月 07 日
如果觉得我的文章对你有用,请随意赞赏