1. 在Redhat中,默認只安裝Samba客戶端,Samba服務端是默認不安裝的,需要手動安裝。
下載Samba(http://www.samba.org/samba/ftp/stable/samba-3.5.8.tar.gz
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
# cp /usr/local/samba/sbin/nmbd /usr/bin/
#!/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
unset TMPDIR
. /etc/sysconfig/network
. /etc/sysconfig/samba
fi
[ ${NETWORKING} = "no" ] && exit 1
[ -f /etc/samba/smb.conf ] || exit 6
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
}
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
}
stop
start
}
echo -n $"Reloading smb.conf file: "
killproc smbd -HUP
RETVAL=$?
echo
return $RETVAL
}
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
[ -w /etc/samba/smb.conf ] || exit 4
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
;;
status)
rhstatus
;;
condrestart)
[ -f /var/lock/subsys/smb ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status|condrestart}"
exit 2
esac
# 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:關閉
New SMB password:
Retype new SMB password:
Added user lili.