#!bin/bash
#samba4 This shell script takes care of starting and stopping
# samba4 daemons.
#chkconfig: - 58 74
#description: Samba 4.0 will be the next version of the Samba suite
#and incorporates all the technology found in both the Samba4 alpha
#series and the stable 3.x series. The primary additional features
#over Samba 3.6 are support for the Active Directory logon protocols
#used by Windows 2000 and above.
###BEGIN INIT INFO
#Provides: samba4
#Required-Start: $network $local_fs $remote_fs
#Required-Stop: $network $local_fs $remote_fs
#Should-Start: $syslog $named
#Should-Stop: $syslog $named
#Short-Description: start and stop samba4
#Description: Samba 4.0 will be the next version of the Samba suite
#and incorporates all the technology found in both the Samba4 alpha
#series and the stable 3.x series. The primary additional features
#over Samba 3.6 are support for the Active Directory logon protocols
#used by Windows 2000 and above.
###END INIT INFO
#Source function library.
./etc/init.d/functions
#Source networking configuration.
./etc/sysconfig/network
prog=samba
prog_dir=/usr/local/samba/sbin/
lockfile=/var/lock/subsys/$prog
start(){
["$NETWORKING" = "no" ] && exit 1
# [ -x /usr/sbin/ntpd ] || exit 5
#Start daemons.
echo-n $"Starting samba4: "
daemon$prog_dir/$prog -D
RETVAL=$?
echo
[$RETVAL -eq 0 ] && touch $lockfile
return$RETVAL
}
stop(){
["$EUID" != "0" ] && exit 4
echo-n $"Shutting down samba4: "
killproc$prog_dir/$prog
RETVAL=$?
echo
[$RETVAL -eq 0 ] && rm -f $lockfile
return$RETVAL
}
#See how we were called.
case"$1" in
start)
start
;;
stop)
stop
;;
status)
status$prog
;;
restart)
stop
start
;;
reload)
echo"Not implemented yet."
exit3
;;
*)
echo$"Usage: $0 {start|stop|status|restart|reload}"
exit2
esac
保存这个文件,chmod755 改一下权限,放到
#chmod 755 /etc/init.d/samba4
chkconfigsamba4 on
4.配置动态链接库路径
安装完成后,我们需要配置动态链接库路径,因为运行samba的进行smbd和nmbd需要到目录/usr/local/samba/lib下的动态链接库文件。但是该目录不是系统默认的动态链接库文件搜索路径,于是我们需要将该目录添加到文件ld.so.conf中。执行下面的命令
# vi /etc/ld.so.conf
然后,打开ld.so.conf文件,并在该文件中加入下面这一行内容
/usr/local/samba/lib
然后执行命令
# ldconfig
来更新动态链接库缓冲。
5、配置环境变量:
[iyunv@sambar~]# vim .bash_profile
#.bash_profile
#Get the aliases and functions
if[ -f ~/.bashrc ]; then
.~/.bashrc
fi
#User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/samba/bin:/usr/local/samba/sbin
exportPATH
6、建立xfs.com域(如果没有smb.conf时,自动创建到/usr/local/samba/etc/)
备注:删除建立的域
rm-rf /usr/local/samba/etc/smb.conf
rm-rf /usr/local/samba/private/*
#/usr/local/samba/bin/samba-tool domain provision --use-rfc2307--interactive
Realm[BTA.NET.CN]: xfs.com
Domain[xfs]: xfs
ServerRole (dc, member, standalone) [dc]: dc
DNSbackend (SAMBA_INTERNAL, BIND9_FLATFILE, BIND9_DLZ, NONE)[SAMBA_INTERNAL]:
DNSforwarder IP address (write 'none' to disable forwarding)[202.106.0.20]:
Administratorpassword:
Retypepassword:
建立完域后,需要启动samba
servicesamba4 start 或/usr/local/samba/sbin/samba
如果忘记了密码,可以使用命令更改域管理员密码方法:
samba-tooluser setpassword administrator
7、测试建立的域:
[iyunv@hd~]# smbclient -L //localhost -Uadministrator
Enterroot's password:
Domain=[XFS]OS=[Unix] Server=[Samba 4.1.0]
Sharename Type Comment
--------- ---- -------
netlogon Disk
sysvol Disk
IPC$ IPC IPC Service (Samba 4.1.0)
Domain=[XFS]OS=[Unix] Server=[Samba 4.1.0]
Server Comment
--------- -------
Workgroup Master
--------- -------
表明建立成功。
[iyunv@sambar~]# smbclient //localhost/netlogon -Uadministrator%此处输入设置的密码
Domain=[XFS]OS=[Unix] Server=[Samba 4.1.0]
smb:\>
8设置DNS
samba4自带有一个dns服务,也可以自己另外搭建DNS服务。比如用带DLZ的bind9的话,在先前建域的命令中加入参数--dns-backend=BIND9_DLZ。我用的是samba4自带的dns。
修改/etc/resolv.conf
加入domainxfs.com和nameserver 172.16.0.1 “主机的局域网IP”两行,
nameserver要放在其它nameserver前面(如果不止一行nameserver的话)检查一下/usr/local/samba/etc/smb.conf配置文档里[global]项有没有dnsforwarder = “当地的DNS地址”。这是DNS转发功能,可以解析除自己的test.org域名以外的其它网域。
执行
检查DNS端口是否占用:#netstat -tunpe | grep ":53"