系统:

CentOS release 6.5


安装包:

samba-4.6.4.tar.gz


安装

$ yum install gcc gcc++ gnutls-devel python python-devel python-lib* libacl-devel openldap-devel -y
$ tar xf samba-4.6.4.tar.gz
$ cd samba-4.6.4
$ ./configure --prefix=/soft/samba
$ make && make install


添加动态链接库

$ echo "/soft/samba/lib" >> /etc/ld.so.conf
$ ldconfig #加载动态链接库


复制、过滤配置文件,可以省略自己生成

$ cp /root/samba-4.6.4/packaging/LSB/smb.conf /soft/samba/etc/
$ cd !$
$ cp smb.conf smb.conf.bak
$ grep -Ev "#|^$|;" smb.conf.bak > smb.conf


配置信息

$ vim smb.conf
[global]
        workgroup = MYGROUP
        server string = Samba Server Version %v
        security = user
        passdb backend = tdbsam
        load printers = yes
        cups options = raw
        map to guest = bad user
        max connections = 0
        log file = /var/log/samba/log.%m
        max log size = 1024
[data]
        comment=Temporary file space
        path=/data
        read only=no
        valid users = mzdata
        write list = mzdata
        printable = no
        create mask = 0755
        directory mask = 0755
        #public=yes


创建用户,注:这里需要系统上已存在的用户,不然会报错

$ useradd mzdata
$ /soft/samba/bin/pdbedit -a -u mzdata
new password:    #输入密码
retype new password:  #再次输入
Unix username:        mzdata
NT username:          
Account Flags:        [U          ]
User SID:             S-1-5-21-2155642128-2869549891-154057661-1000
Primary Group SID:    S-1-5-21-2155642128-2869549891-154057661-513
Full Name:            
Home Directory:       \\nnn-10\mzdata
HomeDir Drive:        
Logon Script:         
Profile Path:         \\nnn-10\mzdata\profile
Domain:               NNN-10
Account desc:         
Workstations:         
Munged dial:          
Logon time:           0
Logoff time:          Wed, 06 Feb 2036 23:06:39 CST
Kickoff time:         Wed, 06 Feb 2036 23:06:39 CST
Password last set:    Fri, 26 May 2017 20:43:59 CST
Password can change:  Fri, 26 May 2017 20:43:59 CST
Password must change: never
Last bad password   : 0
Bad password count  : 0
Logon hours         : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF


查看用户是否创建成功

$ /soft/samba/bin/pdbedit -L
mzdata:500:
$ /soft/samba/sbin/smbd -D   #启动samba服务器
$ /soft/samba/sbin/nmbd -D


这里用官网的脚本来启动、关闭、重启samba服务

$ vim /etc/rc.d/init.d/smb
#!/bin/sh
# Check that the Samba configuration file exists
[ -f /soft/samba/etc/smb.conf ] || exit 0
start(  )
{
        echo -n "Starting SMB services: "
        /soft/samba/sbin/smbd -D
        ERROR=$?
        echo
        echo -n "Starting NMB services: "
        /soft/samba/sbin/nmbd -D
        ERROR2=$?
        if [ $ERROR2 -ne 0 ]
        then
                ERROR=1
        fi
        echo
        return $ERROR
}
stop(  )
{
        echo -n "Shutting down SMB services: "
        /bin/kill -TERM -a smbd
        ERROR=$?
        echo
        echo -n "Shutting down NMB services: "
        /bin/kill -TERM -a nmbd
        ERROR2=$?
        if [ $ERROR2 -ne 0 ]
        then
                ERROR=1
        fi
        echo
        return $ERROR
}
restart(  )
{
        stop
        sleep 2
        start
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac
exit $?


记得给执行权限

$ chmod +x !$

$ service smb start    #开启
$ service smb stop     #关闭
$ service smb restart   #重启

注:关闭服务会有报如下错误,不影响使用,暂时忽略

$ service smb stop
Shutting down SMB services: 
kill smbd: No such process
kill smbd: No such process
Shutting down NMB services: