前言

之前做了一个项目,需要写python脚本来修改组件的安装方式,脚本是在windows下面的pycharm下面进行编写,但是编译要在linux上面进行分模块的maven编译,虽然之前也写了pycharm自带的远程同步代码教程,但是小组当时还是决定使用samba来做。那么使用samba如何实现呢?

Samba介绍

Samba是在Linux和UNIX系统上实现SMB协议的一个软件,由服务器及客户端程序构成。另外,它又是基于NetBIOS协议工作的。

NetBIOS和SMB/CIFS的概念

NetBIOS(Network Basic Input/Output System,网络基本输入/输出系统协议)是一种在局域网上的程序可以使用的应用程序编程接口(API),作用是为了给局域网提供网络以及其他特殊功能。系统可以利用WINS服务、广播及Lmhost文件等多种模式将NetBIOS Name(特指基于NetBIOS协议获得的计算机名称)解析为相应IP地址,实现信息通讯,所以在局域网内部使用NetBIOS协议可以方便地实现消息通信及资源的共享。NetBIOS 是一种会话层协议,因其占用系统资源少、传输效率高,所以几乎所有的局域网都是在NetBIOS协议的基础上工作的,它已被适配到各种其它协议上,如IPX/SPX和TCP/IP。

SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和打印机等的通信协议,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务,是一种客户端/服务器型协议。

SMB最初被设计为运行在NetBIOS协议之上(而NetBIOS本身运行于TCP/IP或NetBEUI、IPX/SPX上),后来可直接运行于TCP/IP上。

CIFS是SMB协议的开源版本。随着Internet的流行,Microsoft将SMB协议扩展到Internet上去,成为Internet上计算机之间相互共享数据的一种标准,并将其重命名为CIFS(Common Internet File System)。

windows系统默认支持这两种协议,如果在linux上也提供支持,则linux和windows系统之间就能实现资源共享了。

安装Samba

检查安装

首先我们检查一下,软件是否已经安装了,如果没有安装,那么执行安装:

经过检查,确认了samba并没有安装。

安装samba

接下来我们就安装samba,可以使用rpm安装,只要去centos的资源库下面,将软件包下载之后,使用rpm安装即可,但是这样子可能会有一些依赖需要解决,所以我们选择使用yum安装!并且安装服务端的时候将客户端也一并安装了。

如果有依赖的话,他会自己解决依赖!如果出现:

说明安装成功了!

Samba配置

接下来是Samba的配置。

添加samba用户

添加samba用户,那么该用户必须是linux已经创建过的用户,才能添加,否则的话不能够添加!

修改配置文件

接下俩就是修改配置文件,samba的配置文件在/etc/samba/smb.conf

在文件末尾添加如下所示内容:

创建共享目录

从末尾我们添加的内容来看,我们共享的目录为/opt/hzhiping,所以我们需要在linux上面添加共享目录:

并且我们在/opt/hzhiping下面放置一些文件!

检查配置文件并重启samba

检查samba配置文件的内容是否正确

windows客户端访问

输入samba添加的账户相关账户密码:

结果如下:

linux客户端访问

上面介绍了windows客户端访问Samba服务器的操作,那么在Linux作为客户端时,查看其它Linux Samba服务器共享的文件时,应该如何操作呢?

这就要用到smbclient这个工具,系统默认自带了这个命令,Smbclient常见用法介绍如下:

查看Samba服务器的共享资料

# smbclient  –L  //Samba服务器的ip地址  -U  Samba用户名

“-L”即为list的含义,“-U”是user的意思,如果Samba服务器是无密码访问的话,可以省略“-U  Samba用户名”。

例如:samba需要密码登陆时,查看共享方法如下:

# smbclient  -L //10.0.0.163/public –U david

Samba无密码访问时,执行如下命令:

# smbclient  -L //10.0.0.163/public

password: 直接回车即可。

登陆Samba服务器

如果需要在Linux客户端登陆Samba服务器,用法如下:

# smbclient  //Samba服务器的ip地址  -U  Samba用户名

请看下面执行的操作:

# smbclient //10.0.0.163/public -U david

smb: \> ?                     //在这里输入问号即可查看在smb命令行可用的所有命令。

操作过程与登陆FTP服务器很类似,登陆Samba服务器后,就可以进行文件的上传与下载,如果有足够的权限,还可以进行修改文件操作。

samba共享文件挂载

此外,Samba服务器共享出来的文件还可以在Linux客户端进行挂载,这就要用到mount命令,如下所示:

# mount -t cifs -l //10.0.0.163/public /mnt/samba/

Samba Web管理工具 SWAT

SWAT(Samba WEB Administration Tool) 是通过浏览器对 Samba 进行管理的工具之一。通过 SWAT,可以在 Samba 允许访问范围内的客户端,用浏览器对服务端的 Samba 进行控制。在线文档的阅览、smb.conf 的确认和编辑,以及密码的变更、服务的重启等等都可以通过 SWAT 来完成,它的直观让 Samba 变得温和化,对那些不喜欢文本界面管理服务器的朋友来说,是一个强大的工具。

swat工具嵌套在xinetd超级守护进程中,要通过启用xinetd进程来启用swat。因此要先安装xinetd工具包,然后安装swat工具包。上面已经安装过samba-swat-3.5.10-125.el6.x86_64,这里不再赘述。

配置swat

因为swat是xinetd超级守护进程的一个子进程,所以swat工具配置文件在xinetd目录中。我们要设置swat配置文件,开启此子进程,以便在启用xinetd进程是来启用swat。swat配置文件在/etc/xinetd.d目录中。

打开并编辑 /etc/xinetd.d/swat

# default: off
# description: SWAT is the Samba Web Admin Tool. Use swat \
#              to configure your Samba server. To use SWAT, \
#              connect to port 901 with your favorite web browser.
service swat
{
        port            = 901                    //swat默认使用tcp的901端口, 可以修改
        socket_type     = stream                 //通过web来配置samba, 默认使用root账号进入, 可以修改成其他的系统用户
        wait            = no
        only_from       = 127.0.0.1
        only_from       = 10.0.0.0               //添加此行, 将“only_from=127.0.0.1”改成“only_from=10.0.0.0”, 只允许内网范围对SWAT进行访问
        user            = root
        server          = /usr/sbin/swat         //swat的执行程序默认在/usr/sbin目录下
        log_on_failure  += USERID
        disable         = yes                    //将“disable=yes”改成“disable=no”, 这样swat子进程就可以随xinetd超级守护进程一起启动了
}

启动 swat

因为swat是xinetd的子进程,所以只要启用了xinetd,那么swat也就会伴随xinetd启动。

打开 swat

在服务端启动 swat后,我们就可以通过 swat允许范围内的客户机的浏览器中,通过 http://服务器的内网IP:901 来访问服务端的 swat了,输入 root用户的用户名及密码进入 swat的管理首页,如下所示:

swat管理中心的首页

通过 swat管理 Samba 与直接修改 smb.conf 的方式,在本质上并无差异,但通过浏览器访问的方式,可以使 Samba 的管理更加温和化,更加适用于不擅长使用文本界面、直接修改配置文件的朋友。

通过swat配置samba

在swat页面我们可以看到有8个选项,每个选项可以配置samba的不同功能。

HOME:Samba相关程序及文件说明。

GLOBALS:设置Samba的全局参数。即smb.conf文件的[global]。

SHARES:设置Samba的共享参数。

PRINTERS:设置Samba的打印参数。

WIZARD:Samba配置向导。

STATUS:查看和设置Samba的服务状况。

VIEW:查看Samba的文本配置文件,即smb.conf。

PASSWORD:设置Samba用户,可以修改密码,新建删除用户。

至此,Samba服务器的所有配置完成。

参考链接:https://www.cnblogs.com/muscleape/p/6385583.html

Samba配置文件配置详解

# This is the main Samba configuration file. For detailed information about the
# options listed here, refer to the smb.conf(5) manual page. Samba has a huge
# number of configurable options, most of which are not shown in this example.
#
# The Samba Wiki contains a lot of step-by-step guides installing, configuring,
# and using Samba:
# https://wiki.samba.org/index.php/User_Documentation
#
# In this file, lines starting with a semicolon (;) or a hash (#) are
# comments and are ignored. This file uses hashes to denote commentary and
# semicolons for parts of the file you may wish to configure.
#
# NOTE: Run the "testparm" command after modifying this file to check for basic
# syntax errors.
#
#---------------
# Security-Enhanced Linux (SELinux) Notes:
#
# Turn the samba_domain_controller Boolean on to allow a Samba PDC to use the
# useradd and groupadd family of binaries. Run the following command as the
# root user to turn this Boolean on:
# setsebool -P samba_domain_controller on
#
# Turn the samba_enable_home_dirs Boolean on if you want to share home
# directories via Samba. Run the following command as the root user to turn this
# Boolean on:
# setsebool -P samba_enable_home_dirs on
#
# If you create a new directory, such as a new top-level directory, label it
# with samba_share_t so that SELinux allows Samba to read and write to it. Do
# not label system directories, such as /etc/ and /home/, with samba_share_t, as
# such directories should already have an SELinux label.
#
# Run the "ls -ldZ /path/to/directory" command to view the current SELinux
# label for a given directory.
#
# Set SELinux labels only on files and directories you have created. Use the
# chcon command to temporarily change a label:
# chcon -t samba_share_t /path/to/directory
#
# Changes made via chcon are lost when the file system is relabeled or commands
# such as restorecon are run.
#
# Use the samba_export_all_ro or samba_export_all_rw Boolean to share system
# directories. To share such directories and only allow read-only permissions:
# setsebool -P samba_export_all_ro on
# To share such directories and allow read and write permissions:
# setsebool -P samba_export_all_rw on
#
# To run scripts (preexec/root prexec/print command/...), copy them to the
# /var/lib/samba/scripts/ directory so that SELinux will allow smbd to run them.
# Note that if you move the scripts to /var/lib/samba/scripts/, they retain
# their existing SELinux labels, which may be labels that SELinux does not allow
# smbd to run. Copying the scripts will result in the correct SELinux labels.
# Run the "restorecon -R -v /var/lib/samba/scripts" command as the root user to
# apply the correct SELinux labels to these files.
#
#--------------
#
#======================= Global Settings =====================================

[global]

# ----------------------- Network-Related Options -------------------------
#
# workgroup = the Windows NT domain name or workgroup name, for example, MYGROUP                                                 .
#
# server string = the equivalent of the Windows NT Description field.
#
# netbios name = used to specify a server name that is not tied to the hostname,
#                maximum is 15 characters.
#
# interfaces = used to configure Samba to listen on multiple network interfaces.
# If you have multiple interfaces, you can use the "interfaces =" option to
# configure which of those interfaces Samba listens on. Never omit the localhost
# interface (lo).
#
# hosts allow = the hosts allowed to connect. This option can also be used on a
# per-share basis.
#
# hosts deny = the hosts not allowed to connect. This option can also be used on
# a per-share basis.
#
        workgroup = MYGROUP
        server string = Samba Server Version %v

        netbios name = MYSERVER

        interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24
        hosts allow = 127. 192.168.12. 192.168.13.

# --------------------------- Logging Options -----------------------------
#
# log file = specify where log files are written to and how they are split.
#
# max log size = specify the maximum size log files are allowed to reach. Log
# files are rotated when they reach the size specified with "max log size".
#

        # log files split per-machine:
        log file = /var/log/samba/log.%m
        # maximum size of 50KB per log file, then rotate:
        max log size = 50

# ----------------------- Standalone Server Options ------------------------
#
# security = the mode Samba runs in. This can be set to user, share
# (deprecated), or server (deprecated).
#
# passdb backend = the backend used to store user information in. New
# installations should use either tdbsam or ldapsam. No additional configuration
# is required for tdbsam. The "smbpasswd" utility is available for backwards
# compatibility.
#

        security = user
        passdb backend = tdbsam

# ----------------------- Domain Members Options ------------------------
#
# security = must be set to domain or ads.
#
# passdb backend = the backend used to store user information in. New
# installations should use either tdbsam or ldapsam. No additional configuration
# is required for tdbsam. The "smbpasswd" utility is available for backwards
# compatibility.
#
# realm = only use the realm option when the "security = ads" option is set.
# The realm option specifies the Active Directory realm the host is a part of.
#
# password server = only use this option when the "security = server"
# option is set, or if you cannot use DNS to locate a Domain Controller. The
# argument list can include My_PDC_Name, [My_BDC_Name], and [My_Next_BDC_Name]:
#
# password server = My_PDC_Name [My_BDC_Name] [My_Next_BDC_Name]
#
# Use "password server = *" to automatically locate Domain Controllers.

        security = domain
        passdb backend = tdbsam
        realm = MY_REALM

        password server = <NT-Server-Name>

# ----------------------- Domain Controller Options ------------------------
#
# security = must be set to user for domain controllers.
#
# passdb backend = the backend used to store user information in. New
# installations should use either tdbsam or ldapsam. No additional configuration
# is required for tdbsam. The "smbpasswd" utility is available for backwards
# compatibility.
#
# domain master = specifies Samba to be the Domain Master Browser, allowing
# Samba to collate browse lists between subnets. Do not use the "domain master"
# option if you already have a Windows NT domain controller performing this task                                                 .
#
# domain logons = allows Samba to provide a network logon service for Windows
# workstations.
#
# logon script = specifies a script to run at login time on the client. These
# scripts must be provided in a share named NETLOGON.
#
# logon path = specifies (with a UNC path) where user profiles are stored.
#
#
        security = user
        passdb backend = tdbsam

        domain master = yes
        domain logons = yes

        # the following login script name is determined by the machine name
        # (%m):
        logon script = %m.bat
        # the following login script name is determined by the UNIX user used:
        logon script = %u.bat
        logon path = \\%L\Profiles\%u
        # use an empty path to disable profile support:
        logon path =

        # various scripts can be used on a domain controller or a stand-alone
        # machine to add or delete corresponding UNIX accounts:

        add user script = /usr/sbin/useradd "%u" -n -g users
        add group script = /usr/sbin/groupadd "%g"
        add machine script = /usr/sbin/useradd -n -c "Workstation (%u)" -M -d /n                                                 ohome -s /bin/false "%u"
        delete user script = /usr/sbin/userdel "%u"
        delete user from group script = /usr/sbin/userdel "%u" "%g"
        delete group script = /usr/sbin/groupdel "%g"

# ----------------------- Browser Control Options ----------------------------
#
# local master = when set to no, Samba does not become the master browser on
# your network. When set to yes, normal election rules apply.
#
# os level = determines the precedence the server has in master browser
# elections. The default value should be reasonable.
#
# preferred master = when set to yes, Samba forces a local browser election at
# start up (and gives itself a slightly higher chance of winning the election).
#
        local master = no
        os level = 33
        preferred master = yes

#----------------------------- Name Resolution -------------------------------
#
# This section details the support for the Windows Internet Name Service (WINS).
#
# Note: Samba can be either a WINS server or a WINS client, but not both.
#
# wins support = when set to yes, the NMBD component of Samba enables its WINS
# server.
#
# wins server = tells the NMBD component of Samba to be a WINS client.
#
# wins proxy = when set to yes, Samba answers name resolution queries on behalf
# of a non WINS capable client. For this to work, there must be at least one
# WINS server on the network. The default is no.
#
# dns proxy = when set to yes, Samba attempts to resolve NetBIOS names via DNS
# nslookups.

        wins support = yes
        wins server = w.x.y.z
        wins proxy = yes

        dns proxy = yes

# --------------------------- Printing Options -----------------------------
#
# The options in this section allow you to configure a non-default printing
# system.
#
# load printers = when set you yes, the list of printers is automatically
# loaded, rather than setting them up individually.
#
# cups options = allows you to pass options to the CUPS library. Setting this
# option to raw, for example, allows you to use drivers on your Windows clients.
#
# printcap name = used to specify an alternative printcap file.
#

        load printers = yes
        cups options = raw

        printcap name = /etc/printcap
        # obtain a list of printers automatically on UNIX System V systems:
        printcap name = lpstat
        printing = cups

# --------------------------- File System Options ---------------------------
#
# The options in this section can be un-commented if the file system supports
# extended attributes, and those attributes are enabled (usually via the
# "user_xattr" mount option). These options allow the administrator to specify
# that DOS attributes are stored in extended attributes and also make sure that
# Samba does not change the permission bits.
#
# Note: These options can be used on a per-share basis. Setting them globally
# (in the [global] section) makes them the default for all shares.

        map archive = no
        map hidden = no
        map read only = no
        map system = no
        store dos attributes = yes

#============================ Share Definitions ==============================
[homes]
        comment = Home Directories
        browseable = no
        writable = yes
        valid users = %S
        valid users = MYDOMAIN\%S

[printers]
        comment = All Printers
        path = /var/spool/samba
        browseable = no
        guest ok = no
        writable = no
        printable = yes

# Un-comment the following and create the netlogon directory for Domain Logons:
        [netlogon]
        comment = Network Logon Service
        path = /var/lib/samba/netlogon
        guest ok = yes
        writable = no
        share modes = no

# Un-comment the following to provide a specific roaming profile share.
# The default is to use the user's home directory:
        [Profiles]
        path = /var/lib/samba/profiles
        browseable = no
        guest ok = yes

# A publicly accessible directory that is read only, except for users in the
# "staff" group (which have write permissions):
        [public]
        comment = Public Stuff
        path = /home/samba
        public = yes
        writable = no
        printable = no
        write list = +staff

这是Samba的配置文件实例,里面包含了相关的配置和解释,如果不是运维,则无需了解太多,只需要会配置就行了!

坚壁清野

samba实现CentOS和window上的数据同步的更多相关文章

  1. AppleWatch___学习笔记(三)iPhone和Apple Watch上的数据同步

    WatchKit App类似于之前iOS 8上新推出的App Extension(应用扩展),比如Today Extension(今天扩展)和Share Extension(分享扩展).只要你对iOS ...

  2. rsync (windows 服务端,linux客户端)将windows上的数据同步到linux服务器,反之也可

    一:总体概述. 1.windows上面首先装CW_rsync_Server.4.1.0_installer,安装时要输入的用户名密码要记住哦!接下来就是找到rsyncd.conf进入配置细节 2.li ...

  3. Redis进行数据同步

    数据库中的数据一般都涉及到需要对数据进行备份的,这样可以保证数据的安全性,并且如果将一个主设备的数据同步到多个从设备上,允许用户访问数据时可以从多个从设备进行读取, 这样还可以缓解主设备的压力,Red ...

  4. 几篇关于MySQL数据同步到Elasticsearch的文章---第四篇:使用go-mysql-elasticsearch同步mysql数据库信息到ElasticSearch

    文章转载自: https://www.cnblogs.com/dalaoyang/p/11018541.html 1.go-mysql-elasticsearch简介 go-mysql-elastic ...

  5. 【转帖】Linux上搭建Samba,实现windows与Linux文件数据同步

    Linux上搭建Samba,实现windows与Linux文件数据同步 2018年06月09日 :: m_nanle_xiaobudiu 阅读数 15812更多 分类专栏: Linux Samba 版 ...

  6. CentOS 6.5上安装MySQL-Cluster

    参考博文: CentOS 6.2下MySQL Cluster 7.2 配置数据库集群 CentOS 6.5上安装MySQL-Cluster 7.3.4过程笔记--下一步学习 MySQL Cluster ...

  7. 临时存存储页面上的数据---Web存储

    HTML5 Web存储的两种方法使用 localStorage和sessionStorage 参考: http://www.cnblogs.com/taoweiji/archive/2012/12/0 ...

  8. 基于MVC4+EasyUI的Web开发框架经验总结(10)--在Web界面上实现数据的导入和导出

    数据的导入导出,在很多系统里面都比较常见,这个导入导出的操作,在Winform里面比较容易实现,我曾经在之前的一篇文章<Winform开发框架之通用数据导入导出操作>介绍了在Winform ...

  9. CentOS 6.9上安装mysql-5.6.36

    CentOS 6.9上安装mysql-5.6.36 1.准备数据存放的文件系统 新建一个逻辑卷,并将其挂载至特定目录即可.这里不再给出过程. 这里假设其逻辑卷的挂载目录为/data,而后需要创建/da ...

随机推荐

  1. 手机游戏引擎 Cocos

    Cocos是全球最受欢迎的移动游戏开发解决方案,整合了Cocos 2d-x.Cocos 2d-js.Cocos Studio.Cocos Code IDE等框架及工具,无论您是开发新手还是行业资深人士 ...

  2. [noip2016]洛谷2827

    来一发文字证明~ 数据范围很大... 如果用priority_queue搞的话肯定是会t的. 所以肯定要想一想优化的思路. 我们发现,对于队列来讲,同加,减是不改变这个队列的大小关系的: 但是呢,切开 ...

  3. Tempset 暴风射击

    发售年份 1980 平台 街机 开发商 雅达利(Atari) 类型 射击 https://www.youtube.com/watch?v=AMto2HJJSSA

  4. Python学习:列表、元组、字典、集合

    转载:https://www.cnblogs.com/xc-718/p/9632942.html 列表/元组 列表和元组都是序列结构,它们本身很相似,但又有一点不同: 列表是用方括号标记,如:a=[1 ...

  5. C# 如何获取SQL Server 中指定数据表的所有字段名和字段类型

    如何获取指定数据表的所有字段名和字段类型.SqlConnection.GetSchema方法有2个重载形式,获取指定数据表的所有字段名和字段类型的秘密就在GetSchema (String, Stri ...

  6. <ROS> message_filters 对齐多种传感器数据的时间戳

    联合标定三维雷达和IMU,第一步要先对齐两种传感信息的时间戳. ros官网提供了message_filters用于对齐多种传感信息的时间戳. http://wiki.ros.org/message_f ...

  7. 监听 input 内容 改变

    html: <input class="query_str_input" placeholder="搜索您的需求" type="text&quo ...

  8. CentOS 7系统初始化

    1. 升级系统 $ yum -y update 2.SELinux设置: 禁用 $ vi /etc/selinux/config 修改 SELINUX=disabled

  9. 2.NB-IoT及通信协议

    NB-IoT 1.什么是NB-IoT? NB-IoT全称窄带物联网(Narrow Band IOT),构建于蜂窝网络,只消耗大约180KHz的带宽,可直接部署于GSM网络.UMTS网络或LTE网络,以 ...

  10. c#获取当前系统时间,并提取按格式提取年月日为字符串

    class Program { static void Main(String[] args) { DateTime currentTime = System.DateTime.Now; string ...