Centos7.4 samba服务器部署和测试.md

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012570105/article/details/83899617
关闭防火墙以及关闭防火墙开机自启
[root@localhost tmp]# systemctl stop firewalld.service 
[root@localhost tmp]# systemctl disable firewalld.service 
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
关闭selinux
  • 临时关闭
[root@localhost ~]# setenforce 0

# 查看SeLinux状态
[root@localhost ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: error (Success)
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 28
  • 永久关闭selinux,需要重启系统
[root@localhost tmp]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing 
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected. 
# mls - Multi Level Security protection.
SELINUXTYPE=targeted 

# 将SELINUX=enforcing 改成SELINUX=disabled 
# 重启后查看selinux装填
[root@localhost ~]# sestatus
SELinux status: disabled
安装samba服务器
  • 安装
[root@localhost tmp]# yum install samba -y

# 查看安装
[root@localhost tmp]# rpm -qa | grep samba
samba-common-libs-4.7.1-9.el7_5.x86_64                    // samba、cifs客户端和服务器都使用的库
samba-client-libs-4.7.1-9.el7_5.x86_64                         // SMB/CIFS 客户端命令所需要的库
samba-libs-4.7.1-9.el7_5.x86_64                                  // samba -libs包包含针对Samba套件提供的SMB、RPC和其他协议进行链接的程序所需的库。
samba-4.7.1-9.el7_5.x86_64                                         //服务器端软件,主要提供samba服务器的守护程序,共享文档,日志的轮替,开机默认选项
samba-common-4.7.1-9.el7_5.noarch                           //主要提供samba服务器的设置文件与设置文件语法检验程序testparm
samba-common-tools-4.7.1-9.el7_5.x86_64                 // 用于samba服务器和客户端的库

# Samba服务器安装完毕,会生成配置文件目录/etc/samba,/etc/samba/smb.conf是samba的核心配置文件。
  • 查看服务状态和启动服务
# 查看服务状态
[root@localhost tmp]# systemctl status smb.service 
● smb.service - Samba SMB Daemon
   Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

# 启动服务并开机自启动
[root@localhost tmp]# systemctl enable smb.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
[root@localhost tmp]# systemctl start smb.service 
[root@localhost tmp]# systemctl status smb.service 
● smb.service - Samba SMB Daemon
   Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2018-11-10 00:46:07 CST; 7s ago
 Main PID: 14985 (smbd)
   Status: "smbd: ready to serve connections..."
   CGroup: /system.slice/smb.service
           ├─14985 /usr/sbin/smbd --foreground --no-process-group
           ├─14987 /usr/sbin/smbd --foreground --no-process-group
           ├─14988 /usr/sbin/smbd --foreground --no-process-group
           └─14989 /usr/sbin/smbd --foreground --no-process-group

Nov 10 00:46:07 localhost.localdomain systemd[1]: Starting Samba SMB Daemon...
Nov 10 00:46:07 localhost.localdomain smbd[14985]: [2018/11/10 00:46:07.642957, 0] ../lib/util/become_daemon.c:124(daemon_ready)
Nov 10 00:46:07 localhost.localdomain smbd[14985]: STATUS=daemon 'smbd' finished starting up and ready to serve connections
Nov 10 00:46:07 localhost.localdomain systemd[1]: Started Samba SMB Daemon.
  • 配置服务(/etc/samba/smb.conf)
# 1.创建1个tc组,tc组里有两个人(develop和manjingliu)
# 2.创建这两个用户,并加入到tc组里面
[root@localhost tmp]# groupadd tc
[root@localhost tmp]# useradd develop
[root@localhost tmp]# useradd manjingliu
useradd: user 'manjingliu' already exists
[root@localhost tmp]# passwd develop
Changing password for user develop.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost tmp]# passwd manjingliu
Changing password for user manjingliu.
New password: 
BAD PASSWORD: The password contains the user name in some form
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost tmp]# user
useradd userdel userformat userhelper userinfo usermod usermount usernetctl userpasswd users       
[root@localhost tmp]# usermod manjingliu -g tc
[root@localhost tmp]# usermod develop -g tc            
[root@localhost tmp]# id manjingliu
uid=1000(manjingliu) gid=1001(tc) groups=1001(tc),1000(manjingliu)
[root@localhost tmp]# id develop
uid=1001(develop) gid=1001(tc) groups=1001(tc)

# 添加samba用户
[root@localhost tmp]# smbpasswd -a develop
New SMB password:
Retype new SMB password:
Added user develop.
[root@localhost tmp]# smbpasswd -a manjingliu
New SMB password:
Retype new SMB password:
Added user manjingliu.

# 修改配置文件
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.

[global]
        workgroup = SAMBA
        security = user

        passdb backend = tdbsam

        printing = cups
        printcap name = cups
        load printers = yes
        cups options = raw

[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 = @printadmin root
        force group = @printadmin
        create mask = 0664
        directory mask = 0775

[ts]                                                  
        comment = TS
        path = /ts
        valid users = @ts

# 校验配置文件
[root@localhost tmp]# testparm 
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[homes]"
Processing section "[printers]"
Processing section "[print$]"
Processing section "[ts]"
Loaded services file OK.
Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

# Global parameters
[global]
        printcap name = cups
        security = USER
        workgroup = SAMBA
        idmap config * : backend = tdb
        cups options = raw


[homes]
        browseable = No
        comment = Home Directories
        inherit acls = Yes
        read only = No
        valid users = %S %D%w%S


[printers]
        browseable = No
        comment = All Printers
        create mask = 0600
        path = /var/tmp
        printable = Yes


[print$]
        comment = Printer Drivers
        create mask = 0664
        directory mask = 0775
        force group = @printadmin
        path = /var/lib/samba/drivers
        write list = @printadmin root



[ts]   这里是地址中的名字
        comment = Tc
        path = /tc
        valid users = @tc

# 重新加载smb配置
[root@localhost tmp]# systemctl reload smb.service 
[root@localhost tmp]# systemctl status smb.service 
● smb.service - Samba SMB Daemon
   Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2018-11-10 00:51:26 CST; 10min ago
  Process: 15271 ExecReload=/usr/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)
 Main PID: 15100 (smbd)
   Status: "smbd: ready to serve connections..."
   CGroup: /system.slice/smb.service
           ├─15100 /usr/sbin/smbd --foreground --no-process-group
           ├─15102 /usr/sbin/smbd --foreground --no-process-group
           ├─15103 /usr/sbin/smbd --foreground --no-process-group
           └─15104 /usr/sbin/smbd --foreground --no-process-group

Nov 10 00:51:26 localhost.localdomain systemd[1]: Starting Samba SMB Daemon...
Nov 10 00:51:26 localhost.localdomain smbd[15100]: [2018/11/10 00:51:26.340995, 0] ../lib/util/become_daemon.c:124(daemon_ready)
Nov 10 00:51:26 localhost.localdomain smbd[15100]: STATUS=daemon 'smbd' finished starting up and ready to serve connections
Nov 10 00:51:26 localhost.localdomain systemd[1]: Started Samba SMB Daemon.
Nov 10 01:01:58 localhost.localdomain systemd[1]: Reloaded Samba SMB Daemon.
Nov 10 01:02:03 localhost.localdomain systemd[1]: Reloaded Samba SMB Daemon.
  • 访问测试
    • 本机命令行测试
[root@localhost home]# smbclient -U manjingliu //192.168.137.149/ts
Enter SAMBA\manjingliu's password: 
Try "help" to get a list of possible commands.
smb: \> 

.
* 远程主机访问
ts

猜你喜欢

转载自blog.csdn.net/u012570105/article/details/83899617