linux 服务器同步?shell远程执行服务器脚本
今天给各位分享linux 服务器同步的知识,其中也会对shell远程执行服务器脚本进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
在各种Linux系统的服务器上设置时间同步的方法
独立主机
rm-rf/etc/localtime
ln-s/usr/share/zoneinfo/Asia/Shanghai/etc/localtime#修改时区到东8区。
date-R#查看的时区设置。
接下来调整系统时间与时间服务器同步
Debian系统安装NTP校时包:
复制代码代码如下:apt-get install ntpdate#安装ntp
CentOS系统安装NTP校时包:
复制代码代码如下:yum-y install ntpdate ntp#安装ntp
Ubuntu系统安装NTP校时包:
复制代码代码如下:sudo apt-get install-y ntpdate ntp
修改/etc/ntp.conf
vi/etc/ntp.conf就会看到以下内容:
复制代码代码如下:server 0.centos.ntp.org
server time.windows.com
server time.nist.gov
这是默认的ntp同步服务器,大家可以自己改,全球ntp服务器地址:
我改成了:
复制代码代码如下:server cn.pool.ntp.org//这中国的ntp服务器
server time-a.nist.gov
server time.windows.com
server time.nist.gov
然后保存退出(vi退出的方法见: carefully-collected-must-be-familiar-with-vim-shortcut-key-operation.html)
接着输入下面的命令:
复制代码代码如下:ntpdate-d cn.pool.ntp.org#调试查看时间差异
ntpdate cn.pool.ntp.org#同步时间
date-R#检查时间是否同步
修改 ntp的配置文件
复制代码代码如下:vi/etc/sysconfig/ntpd
SYNC_HWCLOCK=yes#同步独立主机的硬件时钟
#配置开机启动ntp服务,定期同步时间
chkconfig--levels 235 ntpd on#启动ntp同步
/etc/init.d/ntpd start
XEN VPS
最好是安装ntp服务,这样可以解决vps在重启后时间不准的问题。有时候,依靠母鸡的硬件时钟,总是差七八分钟。实在没辙了。而已很多的web服务,如Google Authenticator等,如果时间不同步,会导致无法验证的地步,自然就网站都登陆不上了。
复制代码代码如下:rm-rf/etc/localtime
ln-s/usr/share/zoneinfo/Asia/Shanghai/etc/localtime#修改时区到东8区。
date-R#查看的时区设置。
接下来调整系统时间与时间服务器同步
Debian系统安装NTP校时包:
复制代码代码如下:apt-get install ntpdate#安装ntp
CentOS系统安装NTP校时包:
复制代码代码如下:yum-y install ntpdate ntp#安装ntp
Ubuntu系统安装NTP校时包:
复制代码代码如下:sudo apt-get install-y ntpdate ntp
修改/etc/ntp.conf
vi/etc/ntp.conf就会看到以下内容:
复制代码代码如下:server 0.centos.ntp.org
server time.windows.com
server time.nist.gov
这是默认的ntp同步服务器,大家可以自己改,全球ntp服务器地址:
我改成了:
复制代码代码如下:server cn.pool.ntp.org//这中国的ntp服务器
server time-a.nist.gov
server time.windows.com
server time.nist.gov
然后保存退出(vi退出的方法见: carefully-collected-must-be-familiar-with-vim-shortcut-key-operation.html)
接着输入下面的命令:
复制代码代码如下:ntpdate-d cn.pool.ntp.org#调试查看时间差异
ntpdate cn.pool.ntp.org#同步时间
date-R#检查时间是否同步
#配置开机启动ntp服务,定期同步时间
chkconfig--levels 235 ntpd on#启动ntp同步
/etc/init.d/ntpd start
#先设置XEN的VPS使用和系统无关的时间模式
echo 1>/proc/sys/xen/independent_wallclock
然后尝试上面独立主机的配置方法即可。通过配置时间正确后,编辑系统配置文件,让配置永久生效。
复制代码代码如下:vi/etc/sysctl.conf
xen.independent_wallclock=1#在文件中增加并且保存
OpenVZ VPS
(Burst VPS采用)
OpenVZ的VPS直接从物理机读取时间不允许对主机进行时间修改,你只需修改时区。我还没用过openvz vps,所以,不清楚能否用ntp服务不,可以试试安装ntp service看。如果可以的话,请告诉我。
复制代码代码如下:rm-rf/etc/localtime
ln-s/usr/share/zoneinfo/Asia/Shanghai/etc/localtime#修改时区到东8区。
date-R#查看时间和时区
此时如果时间和时区都正确,配置成功,时间如果不对,需要联系主机服务商的技术支持,让他们把母鸡(物理机)时间同步,你的VPS时间就会正常。
linux多服务器之间的目录文件同步
web1:10.80.11.243 web2:10.80.11.244 code:10.80.11.245更新code服务器的代码后,自动同步到web1和web2,删除code服务器文件,web1和web2也删除服务器端的安装(N台WEB都这样配置) 1、首先要求Linux内核在2.6以上,才支持inotify [root@web1 html]# uname-a Linux web1 2.6.18-194.el5#1 SMP Fri Apr 2 14:58:35 EDT 2010 i686 i686 i386 GNU/Linux 2、检查是否安装rsync软件 [root@web1 html]# rpm-qa|grep rsync rsync-2.6.8-3.1如果没有的话,通过yum–y install rsync安装 3、新建rsync配置文件,该软件安装默认没有配置文件#vim/etc/rsyncd.conf motd file=/etc/rsyncd.motd uid=root gid=root max connections=36000 use chroot=no log file=/var/log/rsyncd.log log format=%t%a%m%f%b pid file=/var/run/rsyncd.pid lock file=/var/run/rsyncd.lock timeout= 300 [tongbu] path=/var/www/html list=yes comment= this is comment ignore errors= yes read only= no hosts allow= 10.80.11.245 hosts deny=* auth users backup secrets file=/etc/rsyncd.secrets注:tongbu为发布模块,相当于路径的别名 hosts allow是只允许连接的IP secrets file=/etc/rsyncd.secrets这是密码文件,同步的用户为backup,下面创建同步用户#useradd backup#passwd backup#vim/etc/rsyncd.secrets backup:123456格式为用户名:密码#chmod 600/etc/rsyncd.secrets设置只有root用户才能查看这个文件 4、启动服务/usr/bin/rsync--daemon--config=/etc/rsyncd.conf其他的WEB服务器配置和上面是一样的。如果需要开机启动,加入到/etc/rc.local
发布端的配置 1、发布端主要利用开源软件sersync,网站为: –zxvf sersync2.5RC1_32bit_binary.tar.gz#cd GNU-Linux-x86 2、修改配置文件#vim confxml.xml/var/www/html为发布服务器的源码发布目录主要修改红色标记部分,密码文件为/etc/rsync.pas#vim/etc/rsync.pas 123456#解释:123456代表的是Rsync server端的密码,并且要以"#"做结尾。如果有多个密码,增加多行就行。#chmod 600/etc/rsync.pas 3、启动服务#./sersync2-d–r这种方式常驻进程,如果需要开机启动,加入到/etc/rc.local
这样只要修改发布服务器/var/www/html的文件,web服务器就会自动同步。
**********************************************************************************************************
附录二:rsyncd.onf文件注释
全局参数
uid= root//运行RSYNC守护进程的用户
gid= root//运行RSYNC守护进程的组
use chroot= no//不使用chroot
max connections= 4//最大连接数为4
strict modes=yes//是否检查口令文件的权限
port= 873//默认端口873
模块参数
[backup]//这里是认证的模块名,在client端需要指定
path=/home/backup///需要做镜像的目录,不可缺少!
comment= This is a test//这个模块的注释信息
ignore errors//可以忽略一些无关的IO错误
read only= yes//只读
list= no//不允许列文件
auth users= hening//认证的用户名,如果没有这行则表明是匿名,此用户与系统无关
secrets file=/etc/rsync.pas//密码和用户名对比表,密码文件自己生成
hosts allow= 192.168.1.1, 10.10.10.10//允许主机
hosts deny= 0.0.0.0/0//禁止主机
#transfer logging= yes
注释:下面这些绿色文件是安装完RSYNC服务后自动生成的文件
pid file=/var/run/rsyncd.pid//pid文件的存放位置
lock file=/var/run/rsync.lock//锁文件的存放位置
log file=/var/log/rsyncd.log//日志记录文件的存放位置
如何使两台linux服务器时间同步
Linux自带了ntp服务--/etc/init.d/ntpd,这个服务不仅可以设置让本机和某台/某些机器做时间同步,他本身还可以扮演一个time server的角色,让其他机器和他同步时间。
配置文件就是/etc/ntp.conf。
为了测试,设置让node2-- 192.168.1.102和node1-- 192.168.1.101做时间同步。
第一步,node1做time server,node1本身不和其他机器时间同步,就是取本地时间。
所以,先把node1机器的时间调准了:
[root@node1~]date-s 08/03/2011
[root@node1~]date-s 11:12:00
[root@node1~]clock-w
[root@node1~]hwclock--systohc
后两个命令是把设置的时间写到硬件时间中去(也就是CMOS里面的时间)。
第二步,然后将node1配置成一个time server,修改/etc/ntp.conf,
[root@node1~]vi/etc/ntp.conf
其他的配置不怎么需要改,只需要关注restrict的配置:
1.注释掉原来的restrict default ignore这一行,这一行本身是不响应任何的ntp更新请求,其实也就是禁用了本机的ntp server的功能,所以需要注释掉。
2.加入:restrict 192.168.1.0 mask 255.255.255.0--让192.168.1.0/24网段上的机器能和本机做时间同步
3.这样就可以了,记得下面的:
server 127.127.1.0# local clock
fudge 127.127.1.0 stratum 10
这两行需要,这是让本机的ntpd和本地硬件时间同步。
当然,我们也可以添加server xxx.xxx.xxx.xxx,让他和其他的time server时间同步。
4./etc/init.d/ntpd restart
5. chkconfig ntpd on
6.修改iptables配置,将tcp和udp 123端口开放,这是ntp需要的端口,在/etc/services中可以查到这个端口。
第三步,这样node1就成为一台time server了,现在我们配置node2这台机器,也是修改/etc/ntp.conf,
[root@node2~]vi/etc/ntp.conf
1. restrict default ignore这行保留为注释状态,因为sales不需要做time server
2.注释掉server 127.127.1.0, fudge 127.127.1.0 stratum 10这两行,因为这台机器不需要和本地硬件时钟同步了。
3.加入server 192.168.1.101这行,和node1机器同步。
这样就OK了。看看时间,已经和node1同步了。往后默认配置好像是5分钟和time server同步一次。ntpdate命令是显式的和某台机器做时间同步,以前将ntpdate放到crontab中定期同步也是可以的,但是既然ntpd本身就可以做这个时间
第四步,将ntpdate放到crontab中定期步也是可以的
[root@node2~]#vi ntpupdate.sh
/usr/sbin/ntpdate 192.168.1.101
[root@node2~]#chmod 755 ntpupdate.sh
[root@node2~]#crontab-e
*/1****/root/ntpupdate.sh
[root@node2~]#/etc/init.d/crond restart