设为首页 收藏本站
查看: 481|回复: 0

[经验分享] linux下一步步安装和配置samba服务器

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-10-23 10:10:17 | 显示全部楼层 |阅读模式
一,简介:  
  Samba既可以用于windows与Linux之间的文件共享,也可以用于Linux与Linux之间的资源共享,由于NFS(网络文件系统)可以很好的完成Linux与Linux之间的数据共享,因而 Samba较多的用在了Linux与windows之间的数据共享上面。
    组成Samba运行的有两个服务,一个是SMB,另一个是NMB;SMB是Samba 的核心启动服务,主要负责建立 Linux Samba服务器与Samba客户机之间的对话, 验证用户身份并提供对文件和打印系统的访问,只有SMB服务启动,才能实现文件的共享,监听139 TCP端口;而NMB服务是负责解析用的,类似与DNS实现的功能,NMB可以把Linux系统共享的工作组名称与其IP对应起来,如果NMB服务没有启动,就只能通过IP来访问共享文件,监听137和138 UDP端口。

二,系统环境
操作系统:CentOS-6.5-x86_64-minimal
防火墙:disable

三,安装samba服务
即可使用yum工具安装,也可以使用挂载光盘进行安装。有依赖关系的包samba-common,samba-winbind-clients,libsmbcliet将自动安装上去。

[iyunv@localhost ~]#  yum install samba samba-client samba-swat
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirrors.yun-idc.com
* extras: ftp.sjtu.edu.cn
* updates: mirrors.yun-idc.com
http://mirrors.btte.net/centos/6 ... epodata/repomd.xml: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.btte.net'"
Trying other mirror.
extras                                                              | 3.4 kB     00:00     
updates                                                             | 3.4 kB     00:00     
Package samba-3.6.23-20.el6.x86_64 already installed and latest version
Package samba-swat-3.6.23-20.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package samba-client.x86_64 0:3.6.23-20.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================
Package                 Arch              Version                   Repository       Size
===========================================================================================
Installing:
samba-client            x86_64            3.6.23-20.el6             base             11 M

Transaction Summary
===========================================================================================
Install       1 Package(s)

Total download size: 11 M
Installed size: 39 M
Is this ok [y/n]: y

2,查看安装的状况

[iyunv@localhost ~]# rpm -qa |grep samba

samba-winbind-3.6.23-20.el6.x86_64

samba-common-3.6.23-20.el6.x86_64

samba-swat-3.6.23-20.el6.x86_64

samba-winbind-clients-3.6.23-20.el6.x86_64

samba-3.6.23-20.el6.x86_64

3,安装包说明:
samba-common-3.5.10-125.el6.x86_64                 //主要提供samba服务器的设置文件与设置文件语法检验程序testparm
samba-client-3.5.10-125.el6.x86_64                    //客户端软件,主要提供linux主机作为客户端时,所需要的工具指令集
samba-swat-3.5.10-125.el6.x86_64                    //基于https协议的samba服务器web配置界面
samba-3.5.10-125.el6.x86_64                         //服务器端软件,主要提供samba服务器的守护程序,共享文档,日志的轮替,开机默认选项

备注:samba服务器安装完毕,会生成配置文件目录/etc/samba和其他一些samba可执行工具,/etc/samba/smb.conf是samba的核心配置文件

4,启动samba服务器常用的命令:
  /etc/init.d/smb start | stop |restart   或 service smb start | stop | restart

[iyunv@localhost ~]# service smb start
Starting SMB services:                                     [  OK  ]
[iyunv@localhost ~]# service smb status
smbd (pid  24789) is running...



(一)配置samba服务
Samba的主配置文件为:/etc/samba/smb.conf
主配置文件有两部分构成
     Global Settings   (它的设置项目是针对所有的共享资源的)
     Share Definitions  (针对的是共享目录个别的设置,只对当前共享资源起作用)

具体的配置看下边的实例:

案例一:公司现有一个工作组workgroup,现需要文件服务器作为文件服务器,并发布共享目录为/share 共享名为public允许所有的员工访问。
1,修改/etc/samba/smb.conf文件

#======================= Global Settings =====================================

[global]                                                  //该设置与Samba服务整体运行环境有关,它的设置项目针对所有共享资源      

# ----------------------- Network Related Options -------------------------
#
# workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
#
# server string is the equivalent of the NT Description field
#
# netbios name can be used to specify a server name not tied to the hostname

        workgroup = WORKGROUP                             //定义工作组,也就是windows中的工作组概念
        server string = David Samba Server Version %v     //定义Samba服务器的简要说明
        netbios name = DavidSamba                         //定义windows中显示出来的计算机名称

# --------------------------- Logging Options -----------------------------
#
# Log File let you specify where to put logs and how to split them up.

        log file = /var/log/samba/log.%m                  //定义Samba用户的日志文件,%m代表客户端主机名
                                                          //Samba服务器会在指定的目录中为每个登陆主机建立不同的日志文件
# ----------------------- Standalone Server Options ------------------------
#
# Scurity can be set to user, share(deprecated) or server(deprecated)

        security = share                                  //共享级别,用户不需要账号和密码即可访问

#============================ Share Definitions ==============================

[public]                                                  //设置针对的是共享目录个别的设置,只对当前的共享资源起作用
        comment = Public Stuff                            //对共享目录的说明文件,自己可以定义说明信息
        path = /share                                     //用来指定共享的目录,必选项
        public = yes                                      //所有人可查看,等效于

QQ截图20151023100917.png
QQ截图20151023100932.png

2,使用testparm 命令测试smb.conf配置是否正确
[iyunv@localhost share]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[public]"
Processing section "[ts]"
Processing section "[HR]"
Processing section "[FM]"
Processing section "[TS]"
Processing section "[Share]"
WARNING: The security=share option is deprecated
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions



3,创建共享目录和文件
[iyunv@localhost share]# mkdir /share
[iyunv@localhost ~]# cd /share/
[iyunv@localhost share]# ll
total 8
-rw-r--r--. 1 nobody nobody  0 Oct 16 16:08 1.txt
-rwxr--r--. 1 nobody nobody 43 Oct 19 17:14 2.txt
-rwxr-----. 1 nobody nobody  6 Oct 19 17:18 ddd .txt

4,给share文件夹赋权限
[iyunv@localhost share]# chown -R nobody:nobody /share
[iyunv@localhost share]# ll /share/
total 8
-rw-r--r--. 1 nobody nobody  0 Oct 16 16:08 1.txt
-rwxr--r--. 1 nobody nobody 43 Oct 19 17:14 2.txt
-rwxr-----. 1 nobody nobody  6 Oct 19 17:18 ddd .txt

5,重启smb服务
[iyunv@localhost share]# /etc/init.d/smb restart
Shutting down SMB services:                              [  OK  ]
Starting SMB services:                                     [  OK  ]


6,在Windows下访问samba服务器的共享:
QQ截图20151023100942.png


案例二:因业务需要,有共享目录ts,以便ts部门人员浏览查看,需要输入个人密码才可以访问。
1,添加ts部门组和用户并设置相应的密码
[iyunv@localhost ~]# groupadd ts
[iyunv@localhost ~]# useradd -g ts user1
[iyunv@localhost ~]# useradd -g ts user2
[iyunv@localhost ~]# passwd user1
Changing password for user user1.
New password:
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successful
[iyunv@localhost ~]# passwd user2
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.

2,创建ts目录文件夹
[iyunv@localhost ~]# mkdir /ts

3,将刚才建立的两个账号添加到samba账号中(smbpasswd  -a user1)
[iyunv@localhost ~]# smbpasswd -a user1
New SMB password:
Retype new SMB password:
Added user user6.

3,修改主配置文件:vim /etc/smb/smb.conf
#======================= Global Settings =====================================

[global]

# ----------------------- Network Related Options -------------------------
#
# workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH
#
# server string is the equivalent of the NT Description field
#
# netbios name can be used to specify a server name not tied to the hostname

        workgroup = WORKGROUP
        server string = David Samba Server Version %v
        netbios name = DavidSamba

# --------------------------- Logging Options -----------------------------
#
# Log File let you specify where to put logs and how to split them up.

        log file = /var/log/samba/log.%m

# ----------------------- Standalone Server Options ------------------------
#
# Scurity can be set to user, share(deprecated) or server(deprecated)

        security = user                                   //用户级别,由提供服务的Samba服务器负责检查账户和密码

#============================ Share Definitions ==============================

[homes]                                                   //设置用户宿主目录
        comment = Home Directories
        browseable = no
        writable = yes
;       valid users = %S
;       valid users = MYDOMAIN\%S

[public]
        comment = Public Stuff
        path = /share
        public = yes

[ts]                                                      //ts 组目录,只允许ts组成员访问
        comment = TS
        path = /ts
        valid users = @ts

4,重启smb服务
[iyunv@localhost ~]# service smb restart
Shutting down SMB services:                                [  OK  ]
Starting SMB services:                                     [  OK  ]

5,在windows下访问
QQ截图20151023100950.png




备注:给samba服务器添加用户最简单的步骤:
1,groupadd test            创建组

2, useradd  -g test user1     创建用户并把用户添加到组中

3,passwd user1               设置用户的密码

4,smbpasswd  -a liqingbiao     把user1账号添加到samba的账号中

即可通过该smaba的用户名和密码进行访问了


smaba常用的命令


testparm           测试smb.conf配置是否正确

smbstatus          #就可以查出那些用户在用samba相关的资料

pdbedit -L         查看服务器注册的用户

service smb start | status | restart | stop

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-129873-1-1.html 上篇帖子: Linux构建ftp服务器上的yum软件包仓库 下篇帖子: yum 用法详解 服务器 linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表