1003 linux 网络服务配置<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

内容概要:

如何配置ntp 服务器/ 客户端

如何配置samba 服务器

如何使用linux/windows 访问samba 服务器以及在脚本中的实现

 

1.0 ntp Network Time Procotol )服务器配置

1.1 ntp 服务端配置(192.168.0.102

使用一台 ntp 服务器每天定时通过网络校时,同时提供给网络内所有服务器提供校时服务
安装 ntp 软件( yum install ntp
修改配置文件 /etc/ntp.conf
driftfile /var/lib/ntp/drift

 

restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

 

restrict 127.0.0.1
restrict -6 ::1

 

restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap
restrict 172.16.0.0 mask 255.255.0.0 nomodify notrap

 

server 202.112.10.60

 

server  127.127.1.0    # local clock
fudge   127.127.1.0 stratum 10 

 

includefile /etc/ntp/crypto/pw

 

keys /etc/ntp/keys
chkconfig --level 3 ntpd on           # 开机自动启动
echo '00 1 * * * root /etc/init.d/ntpd restart &&/sbin/hwclock -w' >>/etc/crontab           # 每天 1 点通过 internet 校时
service ntpd start                         # 启动 ntpd 服务
ntpq -p                                       # 检测 ntp 服务状态 * 表示目前选择的主同步服务器
*202.112.10.60   .GPS..           1 u    6   64   77  505.943   15.738  33.965

LOCAL(0)      .LOCL.         <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />10 l   65   64   37    0.000    0.000   0.001

一般需要等待 10-15 分钟

 

1.2 ntp 客户端配置

1.2.1 linux 客户端配置

yum install ntp
chkconfig ntpd off
/usr/sbin/ntpdate 192.168.0.102 ;/sbin/hwclock -w
echo '00 2,14 * * * root /usr/sbin/ntpdate 192.168.0.102 &&/sbin/hwclock -w' >>/etc/crontab

 

1.2.2 windows 客户端配置

修改注册表如下:(最后一次同步过后每 12 个小时同步一次)
Windows Registry Editor Version 5.00

 

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient]
"SpecialPollInterval"=dword:0000A8C0

 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers]
@="1"
"1"="192.168.0.102"
保存为任意名 .reg 后运行

 

cmd 下运行如下命令 :
net time /setsntp:192.168.0.102
net stop w32time
net start w32time
可以通过 net time /querysntp 查看当前 ntp server list

 

2.0 samba 服务器配置

2.1 配置samba 服务端

1 .安装 samba 软件( yum install samba
2 .创建系统用户 updateuer (小技巧:脚本创建带密码的系统用户)
useradd –s /sbin/nologin updateuser &&echo 'updateuserPWD' |passwd --stdin updateuser

3 .创建 smb 用户(小技巧:脚本创建带密码的 smb 用户)
echo -e 'smbPWD\nsmbPWD' |smbpasswd -a -s updateuser

4 .修改配置文件 /etc/samba/smb.conf (详细配置说明见 ( )Samba 服务器配置文件)
5 .配置开机启动
chkconfig --level 3 smb on
6 .启动 / 关闭 smb
service smb start/stop

 

2.2 配置samba 客户端

2.2.1 linux 客户端:

方法一:使用 mount
mount -t cifs //192.168.3.90/Update /mnt/dir -o username='updateuser',passwd='smbPWD'
mount.cifs //192.168.3.90/Update /root/dir -o user='updateuser',pass='smbPWD'
方法二:使用 smbclient
smbclient //192.168.3.90/Update -U 'updateuser'%'smbPWD'
登录成功后即可按类似于 ftp 客户端的操作进行

 

2.2.2 windows 客户端:

方法一:使用 UNC 路径直接访问
在运行框里输入: \\192.168.3.90 ,按提示输入帐密
方法二:使用命令行(特别地是当使用脚本时)
net use z: \\192.168.3.90\Update /user:updateuser smbPWD          # 映射网络驱动器 z
提示命令成功完成即可进行相应操作,如: xcopy "C:\Update\UpdateTemp\*" z:\ /s /e /y /f
net use z: /del /y                                                                 # 断开网络驱动器 z
另外地:
net use \\IP /user:USER PWD           # 打开 IPC$ 管道连接
net use                                                  # 列出已建立连接的映射和 IPC$ 连接
net use * /del /y                                  # 删除本机所有网络映射和 IPC$ 连接

 

By Shaw