1.修改文件/etc/hostname里的值即可,修改成功后用hostname命令查看当前主机名是否设置成功。
[root@masternode CentOS]# cat /etc/hosts
#127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
#::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.10.10.3 slavenode1.novalocal slavenode1
10.10.10.4 masternode.novalocal masternode
10.10.10.5 slavenode2.novalocal slavenode2
10.10.10.6 slavenode3.novalocal slavenode3
修改hostname
vi /etc/sysconfig/network
Hostname=masternode1
3.在主节点机器上设置ssh免密码登陆
1) 首先在主机器上核对ssh是否安装
[root@masternode ~]# rpm -qa |grep ssh
libssh2-1.4.2-1.el6.x86_64
openssh-5.3p1-104.el6_6.1.x86_64
openssh-server-5.3p1-104.el6_6.1.x86_64
openssh-clients-5.3p1-104.el6_6.1.x86_64
2) 生产密钥
[root@masternode ~]# cd .ssh/
[root@masternode .ssh]# ls
authorized_keys
[root@masternode .ssh]# cd /
[root@masternode /]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/opt/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /opt/.ssh/id_rsa.
Your public key has been saved in /opt/.ssh/id_rsa.pub.
The key fingerprint is:
e8:3d:75:11:0b:6a:a9:f5:39:e5:04:71:2e:94:21:94 root@masternode.novalocal
The key's randomart image is:
+--[ RSA 2048]----+
| .o.*+o |
| E=.= o |
| = . * |
| = . * . |
| o S = o |
| . . . o |
| . o |
| . |
| |
+-----------------+
[root@masternode /]# cd
[root@masternode ~]# cd .ssh/
[root@masternode .ssh]# ls
authorized_keys id_rsa id_rsa.pub 生产的密钥
[root@masternode .ssh]# cat id_rsa.pub >> authorized_keys
3)把密钥传输到其他节点机器上
(1)用ssh-copy-id命令将公钥传送到远程主机上(这里以Slave1node3为例)。
[root@masternode ~]# ssh-copy-id root@slavenode3
(2)如果在用命令ssh-copy-id时发现找不到该命令“ssh-copy-id:Command not found”,则可能是ssh服务的版本太低的原因,比如若你的机器是RedHat系统就可能该问题,解决办法是:手动复制本地的pubkey内容到远程服务器,命令如下:
cat ~/.ssh/id_rsa.pub | ssh root@slavenode3 'cat >> ~/.ssh/authorized_keys'
该命令等价于下面两个命令:
①在本地机器上执行:scp ~/.ssh/id_rsa.pub root@slavenode3:/~
②到远程机器上执行:cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
[root@masternode .ssh]# scp authorized_keys root@125.208.30.89:/opt/.ssh
The authenticity of host '125.208.30.89(125.208.30.89)' can't be established.
RSA key fingerprint is e3:97:c0:29:e4:fa:0d:41:31:6e:df:fe:0c:6b:c7:08.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '125.208.30.89' (RSA) to the list of known hosts.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
lost connection
[root@masternode .ssh]# vi authorized_keys
cat id_rsa.pub >> authorized_keysd_rsa.pub
[root@masternode .ssh]# scp .ssh/authorized_keys root@mslavenode1:~/.ssh/
[root@masternode .ssh]# scp .ssh/authorized_keys root@slavenode2:~/.ssh/
[root@masternode .ssh]# scp .ssh/authorized_keys root@slavenode3:~/.ssh/
4.把主机hosts拷贝到其他从机器上
[root@masternode centos]# scp /etc/hosts root@10.10.10.5:/etc/hosts