четверг, 4 июня 2009 г.

Samba FreeBSD server - быстрое развёртывание

Задача: организовать ежедневное резервное копирование файла с Windows сервера на сервер под управлением FreeBSD.

Сначало хотел использовать NFS решение. Но посмотрев решения клинетов NFS под Windows я рсстроился. Так-как либо они платыне либо предоставляемые копрорацией Microsoft на диске Kit for Windows 2003 server. Так-как такого диска под рукой не оказалось решил сделать на samba сервере. Так-как клиент есть по умолчанию во всех версиях Windows.

Шаг # 1: Install samba из портов FreeBSD
Шаг # 2: Ищем sample config samba и копируем его под именем smb.conf в директорию /usr/local/etc/
Шаг # 3: У меня получилось такое:


[global]
workgroup = Example
server string = Smb server
security = user
log file = /var/log/samba/log.%m
# Use password server option only with security = server
# The argument list may include:
# password server = Name


# Most people will find that this option gives better performance.
# See the chapter 'Samba performance issues' in the Samba HOWTO Collection
# and the manual pages for details.
# You may want to add the following on a Linux system:
socket options = SO_RCVBUF=8192 SO_SNDBUF=8192

# Browser Control Options:
# set local master to no if you don't want Samba to become a master
# browser on your network. Otherwise the normal election rules apply
local master = no

# Domain Master specifies Samba to be the Domain Master Browser. This
# allows Samba to collate browse lists between subnets. Don't use this
# if you already have a Windows NT domain controller doing this job
domain master = no

# Preferred Master causes Samba to force a local browser election on startup
# and gives it a slightly higher chance of winning the election
preferred master = no

# Enable this if you want Samba to be a domain logon server for
# Windows95 workstations.
domain logons = no

# if you enable domain logons then you may want a per-machine or
# per user logon script
# run a specific logon batch file per workstation (machine)
; logon script = %m.bat
# run a specific logon batch file per username
; logon script = %U.bat

# Where to store roving profiles (only for Win95 and WinNT)
# %L substitutes for this servers netbios name, %U is username
# You must uncomment the [Profiles] share below
; logon path = \\%L\Profiles\%U
# Windows Internet Name Serving Support Section:
# WINS Support - Tells the NMBD component of Samba to enable it's WINS Server
; wins support = yes

# WINS Server - Tells the NMBD components of Samba to be a WINS Client
# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
; wins server = w.x.y.z

# WINS Proxy - Tells Samba to answer 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.
; wins proxy = yes

# DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names
# via DNS nslookups. The default is NO.
dns proxy = no

# Charset settings
display charset = koi8-r
unix charset = koi8-r
dos charset = cp866

# Use extended attributes to store file modes
; store dos attributes = yes
; map hidden = no
; map system = no
; map archive = no

# Use inherited ACLs for directories
# nt acl support = yes
# inherit acls = yes
# map acl inherit = yes

# These scripts are used on a domain controller or stand-alone
# machine to add or delete corresponding unix accounts
#; add user script = /usr/sbin/useradd %u
#; add group script = /usr/sbin/groupadd %g
#; add machine script = /usr/sbin/adduser -n -g machines -c Machine -d /dev/null -s /bin/false %u
#; delete user script = /usr/sbin/userdel %u
#; delete user from group script = /usr/sbin/deluser %u %g
#; delete group script = /usr/sbin/groupdel %g


#============================ Share Definitions ==============================
[1cv8_backup]
comment = for 1cv8 user only
path = /ad6/samba
valid users = 1cv8
read only = no
public = no
writable = yes
printable = no
browseable = yes
create mode = 766
directory mode = 644
# write list = @staff

# Other examples.
#
# A private printer, usable only by fred. Spool data will be placed in fred's
# home directory. Note that fred must have write access to the spool directory,
# wherever it is.
#;[fredsprn]
#; comment = Fred's Printer
#; valid users = fred
#; path = /homes/fred
#; printer = freds_printer
#; public = no
#; writable = no
#; printable = yes

# A private directory, usable only by fred. Note that fred requires write
# access to the directory.
;[fredsdir]
; comment = Fred's Service
; path = /usr/somewhere/private
; valid users = fred
; public = no
; writable = yes
; printable = no

# a service which has a different directory for each machine that connects
# this allows you to tailor configurations to incoming machines. You could
# also use the %U option to tailor it by user name.
# The %m gets replaced with the machine name that is connecting.
;[pchome]
; comment = PC Directories
; path = /usr/pc/%m
; public = no
; writable = yes
# A publicly accessible directory, read/write to all users. Note that all files
# created in the directory by users will be owned by the default user, so
# any user with access can delete any other user's files. Obviously this
# directory must be writable by the default user. Another user could of course
# be specified, in which case all files would be owned by that user instead.
;[public]
; path = /usr/somewhere/else/public
; public = yes
; only guest = yes
; writable = yes
; printable = no

# The following two entries demonstrate how to share a directory so that two
# users can place files there that will be owned by the specific users. In this
# setup, the directory should be writable by both users and should have the
# sticky bit set on it to prevent abuse. Obviously this could be extended to
# as many users as required.
;[myshare]
; comment = Mary's and Fred's stuff
; path = /usr/somewhere/shared
; valid users = mary fred
; public = no
; writable = yes
; printable = no
; create mask = 0765


Шаг # 4: Необходимо добавить пользователя в реальную ОС, для доступа к smb если используется опция
security = user
в
smb.conf


Я добавляю пользователя 1cv8 так-как мне необходимо делать полные резервные копии БД 1cv8.

Дайте эти команды от пользователя root в зависимости от OS:

Для Linux

# useradd 1cv8

# passwd 1cv8


Для FreeBSD

adduser 1cv8


Шаг # 5: Добавим пользователя из ОС в samba использовав следующую команду:

# smbpasswd -a 1cv8


Шаг # 6: Перезапускаем samba server
Для Linux (Ubuntu 9.04)
$ sudo /etc/init.d/samba restart


Для FreeBSD (6.3)
# /usr/local/etc/rc.d/samba restart


Конец.

На этом шаге можно уже монтировать нашу созданную директорию в Windows окружении.
У меня для этих целей написан cmd script который делает всё автоматически в 3.00 AM

net use P: /delete /y & net use P: \\FreeBSD\1cv8_backup my_password_here /user:1cv8 & copy /V /Z D:\AutoBackUp_DB\Data_base_buh_%date:~0,2%%date:~3,2%%date:~8,2%.dt P:\ 


Часть скрипта которая отвечает за монтирование, и копирование копии.

Подробнее можно узнать использовав

net use /?
man samba
man smb.conf


При подготовке статьи я использовал свой опыт, а также зарубежный блог: http://www.cyberciti.biz/faq/adding-a-user-to-a-samba-smb-share/

Комментариев нет: