原创:实现Solaris 与Windows 间的文件共享

Posted Jeremy.Tian

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了原创:实现Solaris 与Windows 间的文件共享相关的知识,希望对你有一定的参考价值。

背景:

现行作业方式无法实现账号权限的管控,并且每次访问都需要创建新的连接。

Solaris访问windows共享目录通过以下命令

/usr/sfw/bin/smbclient //XXXXXXX(服务器名/地址)/TK_XXXXXXX_test(目录名称) -U tk_test(用户)

Password: (此处输入用户密码即可)

 

Windows访问solaris共享目录现在没有设定权限。

只要输入IP即可访问solaris共享目录。

 

部署完后实现Solaris 与Windows 间的文件共享映射。

Program Server :solaris和windows之间的文件共享已经进行调整

Solaris访问windows共享目录

已经将windows系统XXXXXXX/TK_XXXXXXX_test(此目录可修改配置)目录挂载到solaris系统mnt目录(此目录可修改配置)

 

Windows访问solaris共享目录

使用帐号user1

密码12345678

 

一、      安装软体

a)        samba-3.6.4-sol10-sparc-local.gz

b)        sharity.3.9.solaris-sun4.tar.gz

 

二、      Samba概述

Samba提供了Unix系统和Windows之间的文件和打印机共享服务。一台Solaris的机器,如果配置了Samba Server,就能充当共享服务器;同时也能作为客户机访问网络中其它Windows系统上的共享文件,或其它安装了Samba Server的Solaris/Linux系统上的共享文件。

 

三、      安装Samba

a)      下载 samba for Solaris 的安装软件包:samba-3.6.4-sol10-sparc-local.gz

注:Solaris系统分为Sparc和x86两个版本。Samba版本需要和Solaris版本一致

b)      解压并安装samba软件包:

#gunzip samba-3.6.4-sol10-sparc-local.gz

注:检查是否已经安装samba使用pkginfo命令

#pkgadd –d samba-3.6.4-sol10-sparc-local

注:pkgadd –d如果不加-d则需要将安装包放置于/var/spool/pkg目录

安装完毕后,到默认安装目录/usr/local下可以看到安装的软件包samba目录。

c)      启动Solaris 10系统的Samba 服务

在安装完软件包后,我们把/usr/local/samba/sbin 下面的3个应用程序,nmbd,smbd,winbindd复制到/usr/local/samba/bin下面去。

samba server服务是 由3个守护进程组成,

nmbd—Netbios名称服务器,该进程使用UDP协议提供Netbios名称服务和浏览支持,处理命名注册和决策请求。该进程应当是被首先启动。

smbd —SMB服务器,使用TCP协议给SMB客户提供文件和打印服务;应当在nmbd进程后立即启动。

Winbindd—当Samba服务器是windows NT 或 ADS域中的成员时,此时当启动该守护进程。

通常在修改了配置文件smb.conf后,我们需要从新启动这3个进程,以便参数的设置起效.

 

d)     开启samba服务

#svcadm enable samba

(关闭samba服务 #svcadm disable samba; 重启samba服务 #svcadm restart samba)

e)      查看samba服务

# svcs -v | grep samba

 

f)       查看MDB进程

#ps -ef | grep mbd       

 

 

四、       配置Samba

Samba的共享方式包括share、user、server、domain 和ads。(厂内目前使用user的共享方式)

a)      配置share共享方式

采用share方式,用户不需要输入帐号和密码就可以登陆samba服务器。其配置步骤为:

                                       i.              创建一个Samba共享目录

# mkdir -p /export/home/user1

                                     ii.              创建Samba配置文件

# cp /etc/sfw/smb.conf-example /etc/sfw/smb.conf

# vi /etc/sfw/smb.conf

===== ===== /usr/sfw/smb.conf ==========

security = share

[homes]

comment = Home Directories

browseable = yes

writable = yes

path = /export/home/user1

guest ok = yes

guest account = user1

这里用户是通过默认的user1来登陆的。用户登陆之后,可以看到user1 所共享的文件和所有系统共享文件,其他用户共享的文件能够看得到,但是不一定能够使用或者进的去。如果不设置guest account的话,则用户就以默认的nobody进行登陆,只能够使用系统设置的共享文件。其他用户设置的文件不一定能够使用。

                                    iii.              启动Samba服务

# svcadm enable samba

# svcs | grep samba

online1:19:02svc:/network/samba:default

# ps -eaf | grep mbd

root 24453 1 0 01:19:02 ? 0:00 /usr/sfw/bin/smbd -D

root 24450 1 0 01:19:02 ? 0:00 /usr/sfw/bin/nmbd -D

root 24454 24453 0 01:19:02 ? 0:00 /usr/sfw/bin/smbd -D

b)     配置user共享方式(新建user1用户。此处用户名可自定义)

配置成user方式需要提供用户名和密码进行验证。这里Samba用户必须是 Solaris系统用户。而对同一个用户来说,samba密码和系统密码不必一定相同。

 

                                       i.              添加一个系统用户(用已经存在的也可以)

# useradd -d /export/home/user1 -m -s /usr/bin/bash user1

                                      ii.              用smbpasswd添加Samba用户

# /usr/sfw/bin/smbpasswd -a user1

New SMB password: <password>

Retype new SMB password: <password>

Added user user1.

/usr/sfw/bin/smbpasswd -e user1

Enabled user user1

                                    iii.              编辑配置文件smb.conf

===== ===== /usr/sfw/smb.conf ==========

security = user                                          #使用user认证方式

[homes]

comment = Home Directories for %S

valid users = %S                                            #只有所有者能访问该共享

browseable = no                                           #该共享对其它用户不可见

writable = yes

create mask = 0640                                      #创建文件时的权限掩码

directory mask = 0750                                  #创建目录时的权限掩码

 

这里%S通配符可以扩展成实际的共享名。这样user1共享的注释将是 “Home Directories for user1”。

                                    iv.              重新启动Samba服务

# svcadm restart samba

c)      Solaris访问 Windows的共享资源

Samba包中已经包括了smbclient、smbmount等的实用程序。smbclient程序提供了一个类似FTP 的模式界面,允许用户共享Windows、Linux的资源,还可以用户列出服务器上的可用共享资源。smbmount类似mount命令,将 Windows的共享目录安装到Linux的本地目录。

  1. 查询网络上的Samba服务器

# /usr/sfw/bin/findsmb

每个找到的服务器都会显示其 IP 地址、NetBIOS 名称、工作组名称、操作系统、以及 SMB 服务器版本。

  1. 列出Samba服务器上的可用资源

# /usr/sfw/bin/smbclient -L <hostname>

如果是 user共享方式,就要加“-U <user>”选项如下。

# /usr/sfw/bin/smbclient -L <hostname> -U <user>

Password: <password>

如果是 share共享方式,可以不必理会用户和密码,要求输入密码时直接回车即可。

  1. 连接Samba共享

# /usr/sfw/bin/smbclient //<hostname/<share> [-U <username>]

例如要访问上文中的share共享时,可用

# /usr/sfw/bin/smbclient //hostname/homes

Password: <ENTER>

Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.0.21b]

smb:>

要访问上文中的user共享时,可用

# /usr/sfw/bin/smbclient //hostname/user1 -U user1

Password: <user1_password>

Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.0.21b]

smb:>

连接后,就能象FTP用户一样上传和下载文件。用put表示上传,用get表示下载。键入help获得可用的命令列表。

  1. 挂载Samba共享

Solaris 尚不支持smbfs和smbmount命令。解决方法之一就是使用Sharity。其安装和使用都很简单。

       此时Samba即安装完成。也初步实现Solaris和Windows之间的文件共享功能。但此存在以下问题:

1、每次Solaris访问Windows共享文件夹时,需使用以下命令进行文件共享连接

/usr/sfw/bin/smbclient //XXXXXXX(服务器名/地址)/TK_XXXXXXX_test(目录名称) -U tk_test(用户)

Password: (此处输入用户密码即可)

2、需使用FTP命令进行数据交换,这样对用户的要求比较高,难以掌握。

3、无法实现机台自动获取信息。机台无法在每次获取数据时自动输入命令。

 

五、            安装配置sharity

a)        解压sharity文件

# gunzip -c sharity.3.9.solaris-sun4.tar.gz | tar xf -

b)       进入sharity解压目录

cd sharity.3.9.solaris-sun4(此处最好书写解压目录全路径)

c)        安装sharity

# ./setup

d)       安装流程:

-----------------------------------------------------------------------

Type 1 and press Enter for an installation in English language.

Tippen Sie 2 und dann Enter um in deutscher Sprache zu installieren.

-----------------------------------------------------------------------
Default answer: 1

-----------------------------------------------------------------------
WELCOME TO SHARITY 3 INSTALLATION

This is the install script for Sharity 3. The script will first ask a
couple of questions, then give a summary of your choices and give you a
chance to start over again.

The installation will not begin before the questionnaire is complete. You can
type ^C at any time during the questionnaire to abort the installation.

Please press Enter to start.
-----------------------------------------------------------------------

-----------------------------------------------------------------------
INSTALLATION DIRECTORY

Where do you want to install Sharity? We recommend locations like
/usr/local/sharity3 or /opt/sharity3.
-----------------------------------------------------------------------
Default answer: /usr/local/sharity3

-----------------------------------------------------------------------
SYMLINKS FOR BINARIES?

Sharity comes with binaries which should be in your search path. This can be
accomplished either by adding /usr/local/sharity3/bin
to your search path or by making symlinks from an existing bin directory
to Sharity‘s binaries.

If you want to create the symlinks, please specify your preferred binary
directory where the symlinks should be created (e.g. /usr/local/bin):
-----------------------------------------------------------------------
Default answer: <none>

-----------------------------------------------------------------------
NETWORK BROWSING DIRECTORY

Sharity provides a network browser similar to the Windows Network
Neighborhood. Where do you want to mount this browser? If you don‘t want
the browser, answer none (without the quotes).
-----------------------------------------------------------------------
Default answer: /CIFS

-----------------------------------------------------------------------
WORKGROUP OR DOMAIN

Sharity works best if it knows your Windows workgroup or domain. If you know
your workgroup or domain name (fully qualified DNS domain name, if possible),
please enter it below. Otherwise leave it blank. You can always change this
setting later in the Sharity GUI or in the file
/usr/local/sharity3/var/user.cfg.
-----------------------------------------------------------------------
Default answer: <none>

-----------------------------------------------------------------------
WINS SERVER

If your network uses a WINS server (Netbios name server), Sharity should know
about it. If you don‘t know what a WINS server is, please leave it blank. You
can always set it through the Sharity GUI or in the file
/usr/local/sharity3/var/user.cfg.

If you know your WINS server IP-address, please enter it here. Remember:
we need an IP address (or a DNS name), not a Netbios name of the computer.
-----------------------------------------------------------------------
Default answer: <none>

-----------------------------------------------------------------------
SUMMARY

Summary of your choices:
Installation root directory: "/usr/local/sharity3"
Upgrade or new install: install
Link binaries to directory: ""
Network browser directory: "/CIFS"
Workgroup or Domain: ""
WINS server: ""

Are these values OK? [Y/n]
-----------------------------------------------------------------------
Default answer: yes

Copying files...
Editing and creating customized files...
Fixing permissions and ownership...
Starting Sharity service...
Starting Sharity daemon:
odcfgparse/info: Reading file "/usr/local/sharity3/etc/config/cifs.cfg"
odcfgparse/info: Reading file "/usr/local/sharity3/etc/config/main.cfg"
odcfgparse/info: Reading file "var/local.cfg"
odcfgparse/info: Reading file "var/user.cfg"
Warning: The master pass phrase for your key chain has been chosen
randomly by the system. Please use "sharity keychain setpass" to
set your own master pass phrase. The master pass phrase is needed
after an upgrade or restore from backup!
done.

-----------------------------------------------------------------------
You must choose a master pass phrase to protect your keychain. The keychain
contains passwords and other secret data. You need this pass phrase after
an upgrade or a restore from backup. Please choose something which can not
be guessed easily (no dictionary words) and which you can remember, although
you don‘t need it regularly. If you can‘t decide now, type ^C and use

/usr/local/sharity3/bin/sharity keychain setpass

or the GUI application

/usr/local/sharity3/bin/sharitygui

later to set your pass phrase.
-----------------------------------------------------------------------
New master pass phrase:
Type again to verify:
Pass phrase successfully changed.

-----------------------------------------------------------------------
COMPLETED

The installation has finished. You should start the GUI application now.
It can be found at the path

/usr/local/sharity3/bin/sharitygui

The GUI application asks for passwords when required and can be used to
configure Sharity. You must run it under the same account which uses the
Sharity mounts in order to get login dialogs for the correct account.

If you don‘t have a license key yet, please visit
http://www.obdev.at/products/sharity/.
-----------------------------------------------------------------------

e)        启动和停止Sharity

重启机器后,Sharity会自动运行

# svcs | grep sharity

legacy_run 0:38:06 lrc:/etc/rc2_d/S80sharity3

legacy_run 0:38:14 lrc:/etc/rc3_d/S80sharity3

停止 Sharity

# /usr/local/sharity3/sbin/sharity.init stop

启动 Sharity

# /usr/local/sharity3/sbin/sharity.init start

f)         配置sharity

  1. 进入sharity目录

# cd /usr/local/sharity3/bin (默认路径)

  1. 检查sharity安装

# ./sharity -h

  1. 挂载:登录到windows

# ./sharity login smb://XXXXXXX/TK_XXXXXXX_test –U tk_test –P 12345678

注:此处服务器地址为windows文件共享服务器地址;目录为共享文件目录;用户问windows文件共享服务器用户;密码为对应用户密码

  1. 挂载:至solaris mnt目录

# ./sharity mount smb://XXXXXXX/TK_XXXXXXX_test /mnt

  1. 查看挂载情况

# df

  1. 卸载挂载

# ./sharity umount -a

  1. 查看挂载情况

# df

  1. 退出windows会话

# ./sharity logout –a

 

以上是关于原创:实现Solaris 与Windows 间的文件共享的主要内容,如果未能解决你的问题,请参考以下文章

原创-angularjs2不同组件间的通信

如何实现虚拟机(VirtualBox)中的Ubuntu与Windows XP间的数据共享

原创三台CentOS7非root用户间实现相互间的免密登录

在 Linux 上构建 Solaris 软件包?

在 Solaris、Linux、Windows 和 Mac 上用 C 语言清除屏幕

Windows中利用共享内存来实现不同进程间的通信