Redhat EL5 搭建Samba服务器



1. 在Redhat中,默认只安装Samba客户端,Samba服务端是默认不安装的,需要手动安装。

下载Samba(http://www.samba.org/samba/ftp/stable/samba-3.5.8.tar.gz

http://rpm.pbone.net/index.php3/stat/4/idpl/23866238/dir/redhat_el_5/com/samba-3.6.5-114.1.i386.rpm.html)


2.安装Samba

#cd   samba-3.5.8/source3     //source3目录里是samba-3.x的源文件,source4目录里是samba-4.x的源文件

#./configure --prefix=/usr/local/samba

#make

#make install


3.配置动态链接库路径

# vi /etc/ld.so.conf

添加:/usr/local/samba/lib
# ldconfig        //执行ldconfig让配置生效


4. Samba的配置文件位于/usr/local/samba/lib

#cp .../samba-3.5.8/examples/smb.conf.default /usr/local/samba/lib/smb.conf

#vi /usr/local/samba/lib/smb.conf

[global]
workgroup=WORKGROUP       //定义Samba所在的工作组或者域


server string=linux        //Samba服务器的描述


security=user                //安全级别


encrypt passwords = yes
passdb backend = smbpasswd
smb passwd file = /etc/samba/smbpasswd
username map = /etc/samba/smbusers

client lanman auth = yes                           //这时既可以用smbclient连接,也可以用mount挂载,还可以通过gnome里面的“连接到服务器“来连接,不加会初心lanman认证错误

[share]
comment=samba share
#共享的路径
path=/home/share
public=yes
writeable=yes


5.配置完成后运行testparm检查配置是否正确

#/usr/local/samba/bin/testparm


6.打开端口

#vi /etc/sysconfig/iptables

添加

-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 137 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 138 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT


7.添加Samba服务
# cp /usr/local/samba/sbin/smbd /usr/bin/
# cp /usr/local/samba/sbin/nmbd /usr/bin/
vi /etc/init.d/smb
------------------------------------------------------------
#!/bin/sh
#
# chkconfig: - 91 35
# description: Starts and stops the Samba smbd and nmbd daemons \
#              used to provide SMB network services.
#
# pidfile: /var/run/samba/smbd.pid
# pidfile: /var/run/samba/nmbd.pid
# config:  /etc/samba/smb.conf

# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 1
fi
# Avoid using root's TMPDIR
unset TMPDIR
# Source networking configuration.
. /etc/sysconfig/network
if [ -f /etc/sysconfig/samba ]; then
   . /etc/sysconfig/samba
fi

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 1
# Check that smb.conf exists.
[ -f /etc/samba/smb.conf ] || exit 6
RETVAL=0
start() {
        KIND="SMB"
        echo -n $"Starting $KIND services: "
        daemon smbd $SMBDOPTIONS
        RETVAL=$?
        echo
        KIND="NMB"
        echo -n $"Starting $KIND services: "
        daemon nmbd $NMBDOPTIONS
        RETVAL2=$?
        echo
        [ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] && touch /var/lock/subsys/smb || \
           RETVAL=1
        return $RETVAL
}
stop() {
        KIND="SMB"
        echo -n $"Shutting down $KIND services: "
        killproc smbd
        RETVAL=$?
        echo
        KIND="NMB"
        echo -n $"Shutting down $KIND services: "
        killproc nmbd
        RETVAL2=$?
        [ $RETVAL -eq 0 -a $RETVAL2 -eq 0 ] && rm -f /var/lock/subsys/smb
        echo ""
        return $RETVAL
}
restart() {
        stop
        start
}
reload() {
        echo -n $"Reloading smb.conf file: "
        killproc smbd -HUP
        RETVAL=$?
        echo
        return $RETVAL
}
rhstatus() {
        status smbd
        RETVAL=$?
        status nmbd
        RETVAL2=$?
        if [ $RETVAL -ne 0 ] ; then
                return $RETVAL
        fi
        if [ $RETVAL2 -ne 0 ] ; then
                return $RETVAL2
        fi
}

# Allow status as non-root.
if [ "$1" = status ]; then
       rhstatus
       exit $?
fi
# Check that we can write to it... so non-root users stop here
[ -w /etc/samba/smb.conf ] || exit 4

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  reload)

        reload
        ;;
  status)
        rhstatus
        ;;
  condrestart)
        [ -f /var/lock/subsys/smb ] && restart || :
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|status|condrestart}"
        exit 2
esac
exit $?
---------------------------------------------------------------------------------------------------------------------------
#chmod +x /etc/init.d/smb

# chkconfig --add smb
# chkconfig --list smb
smb             0:关闭  1:关闭  2:关闭  3:关闭  4:关闭  5:关闭  6:关闭
# chkconfig --level 3 smb on
# chkconfig --list smb
smb             0:关闭  1:关闭  2:关闭  3:启用  4:关闭  5:关闭  6:关闭

添加用户
# smbpasswd -a lili         //用户需要存在于/etc/passwd文件,-a参数不能省略
New SMB password:
Retype new SMB password:
Added user lili.












猜你喜欢

转载自blog.csdn.net/w171066/article/details/52240639