Linux 集群(克隆虚拟机、ssh远程登录、节点间的无密码访问、crontab 定时器、ntp时间同步)
linux集群
克隆虚拟机
- 更改新增系统的mac地址 vim /etc/udev/rules.d/70-persistent-net.rules
- 更改网卡信息 (setup)(修改satatic ip) vim /etc/sysconfig/network-scripts/ifcfg-eth0
- 设置每个节点的主机名 vi /etc/sysconfig/networkHOSTNAME=node02
- 重启系统生效 reboot
基本的配置
1、关闭防火墙 /etc/init.d/iptables stop
开机不自启 chkconfig iptables off
2、关闭selinux vi /etc/selinux/config
将 SELINUX=enforcing 改为 SELINUX=disabled
3、配置hosts文件(主机名与IP的对应关系) vi /etc/hosts
192.168.100.121 node01 192.168.100.122 node02 192.168.100.123 node03
4、多节点同步(scp 远程文件拷贝)
scp /etc/hosts node02:/etc/
scp /etc/hosts [email protected]:/etc/
ssh远程登录
ssh ip地址 远程登录到指定服务器上(必须知道正确的密码)
节点间的无密码访问
目标:node01免密码登录到node01 node02 node03节点
1、 在node01节点生成公钥和私钥
ssh-****** + 4个回车
2、免密登录node01 ssh-copy-id node01 + node01的密码
免密登录node02 ssh-copy-id node02 + node02的密码
免密登录node03 ssh-copy-id node03 + node01的密码
.ssh目录的下文件:
id_rsa 私钥
id_rsa.pub 公钥
authorized_keys 哪些公钥可以进入本机
crontab 定时器
crontab -e 表示编辑定时
crontab -l 表示查询已经编辑的定时任务
-r remove 删除当前用户所有的crontab任务
编辑格式: * * * * * 命令(操作)
* 一个小时内的第几分钟(0-59)
* 一天内的第几个小时(0-23)
* 一个月内的第几天(1-31)
* 一年内第几个月(1-12)
* 一周中的星期几(0-7)
ntp时间同步
- 联网状态下与互联网上提供的时钟服务器进行同步
同步命令 : ntpdate ntp4.aliyun.com
- 配置离线状态下的时钟同步
1、设置时钟同步服务器的时间(node03 2012-12-12 12:12:12)
将node01 node02时间与node03同步
2、修改第一个配置文件 /etc/ntp.conf
添加如下内容
restrict 192.168.100.0 mask 255.255.255.0 nomodify notrap
server 127.127.1.0 # localclock
fudge 127.127.1.0 stratum 10
注释以后的服务器
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
3、修改第二个配置文件 vi /etc/sysconfig/ntpd
添加如下内容
SYNC_HWLOCK=yes
4、重启ntp服务 /etc/init.d/ntpd restart
5、时钟同步
在node01 node02节点进行同步
命令 ntpdate node03 (时钟服务器)
ntpdate 192.168.100.123(时钟服务器)