1.规划
主机名 | IP |
---|---|
eshop-cache01 | 192.168.135.126 |
eshop-cache02 | 192.168.135.129 |
eshop-cache03 | 192.168.135.130 |
eshop-cache04 | 192.168.135.134 |
2.环境配置
2.1 配置网络
#vi /etc/sysconfig/network-scripts/ifcfg-ens33
BOOTPROTO="static"
ONBOOT="yes"
IPADDR="192.168.135.128"
GATEWAY="1921.168.135.1"
NETMASK="255.255.255.0"
DNS1="221.131.143.69"
DNS2="114.114.114.114"
#systemctl restart network
2.2 配置hosts
#vi /etc/hosts
配置本机的hostname到ip地址的映射
2.3 关闭防火墙
#systemctl stop firewalld.service
#systemctl disable firewalld.service
最好也关闭windows的防火墙,后面要搭建集群,有的大数据技术的集群之间,在本地你给了防火墙的话,可能会没有办法互相连接,会导致搭建失败 --我暂时没有关闭,如果后面有问题的话,再关闭
2.4 禁用SELINUX
#vi /etc/selinux/config
SELINUX=disabled
2.5 使用阿里源
#cd /etc/yum.repos.d
#mv CentOS-Base.repo CentOS-Base.repo.bak
#wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#yum clean all
#yum makecache
2.6 安装JDK 1.8
-
将jdk-linux-x64.rpm通过WinSCP上传到虚拟机中
-
安装JDK:rpm -ivh jdk-linux-x64.rpm
-
配置jdk相关的环境变量
#vi .bashrc export JAVA_HOME=/usr/java/latest export PATH=$PATH:$JAVA_HOME/bin #source .bashrc
-
测试jdk安装是否成功:java -version
2.7 安装Perl
由于我安装操作系统时,选择是服务器版,已存在perl,不需要在安装了。
2.8 配置4台CentOS为ssh免密码互相通信
-
在4台虚拟机中,分别增加其它主机名
#vi /etc/hosts 192.168.135.126 eshop-cache01 192.168.135.129 eshop-cache02 192.168.135.130 eshop-cache03 192.168.135.134 eshop-cache04
-
在eshop-cache01主机中生成公钥
[root@eshop-cache01 ~]# cd [root@eshop-cache01 ~]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:G1I5NlPMGVa4iXHN3k9d0ARUhwc7asL9qJgzhk8psRE root@eshop-cache01 The key's randomart image is: +---[RSA 2048]----+ | o+B..=O+| | .+* o ..=| | E B+ + .o.o| | +.=o.....o| | + S o + o | | = + o o .| | o.+ . . | | .o+o . | | o+o. | +----[SHA256]-----+ [root@eshop-cache01 ~]# cd /root/.ssh [root@eshop-cache01 .ssh]# cp id_rsa.pub authorized_keys [root@eshop-cache01 .ssh]# ssh eshop-cache01 The authenticity of host 'eshop-cache01 (192.168.135.126)' can't be established. ECDSA key fingerprint is SHA256:IMfDHqpF+vUaLMGwqMQcBdgJMXG52mmHeKD647Nckts. ECDSA key fingerprint is MD5:2e:4d:92:fc:fb:68:71:b8:eb:00:2f:42:22:7b:c9:67. Are you sure you want to continue connecting (yes/no)? yes
-
将公钥发放到其它机器中
[root@eshop-cache01 ~]# ssh-copy-id -i eshop-cache02 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host 'eshop-cache02 (192.168.135.129)' can't be established. ECDSA key fingerprint is SHA256:IMfDHqpF+vUaLMGwqMQcBdgJMXG52mmHeKD647Nckts. ECDSA key fingerprint is MD5:2e:4d:92:fc:fb:68:71:b8:eb:00:2f:42:22:7b:c9:67. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@eshop-cache02's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'eshop-cache02'" and check to make sure that only the key(s) you wanted were added. [root@eshop-cache01 ~]# ssh-copy-id -i eshop-cache03 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host 'eshop-cache03 (192.168.135.130)' can't be established. ECDSA key fingerprint is SHA256:IMfDHqpF+vUaLMGwqMQcBdgJMXG52mmHeKD647Nckts. ECDSA key fingerprint is MD5:2e:4d:92:fc:fb:68:71:b8:eb:00:2f:42:22:7b:c9:67. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@eshop-cache03's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'eshop-cache03'" and check to make sure that only the key(s) you wanted were added. [root@eshop-cache01 ~]# ssh-copy-id -i eshop-cache04 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host 'eshop-cache04 (192.168.135.134)' can't be established. ECDSA key fingerprint is SHA256:IMfDHqpF+vUaLMGwqMQcBdgJMXG52mmHeKD647Nckts. ECDSA key fingerprint is MD5:2e:4d:92:fc:fb:68:71:b8:eb:00:2f:42:22:7b:c9:67. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@eshop-cache04's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'eshop-cache04'" and check to make sure that only the key(s) you wanted were added. [root@eshop-cache01 ~]# ssh eshop-cache02 Last login: Tue Jan 12 10:16:01 2021 from 192.168.135.1 [root@eshop-cache02 ~]# exit 登出 Connection to eshop-cache02 closed. [root@eshop-cache01 ~]# ssh eshop-cache03 Last login: Tue Jan 12 09:45:44 2021 from 192.168.135.1 [root@eshop-cache03 ~]# exit 登出 Connection to eshop-cache03 closed. [root@eshop-cache01 ~]# ssh eshop-cache04 Last login: Tue Jan 12 10:15:00 2021 from 192.168.135.1 [root@eshop-cache04 ~]# exit 登出 Connection to eshop-cache04 closed.
-
在其它主机上配置相关免登陆功能
[root@eshop-cache03 .ssh]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:+chlB1L0jDe6Rq5BXbZV7pgHF3Qd77KXxWjhCmD7clg root@eshop-cache03 The key's randomart image is: +---[RSA 2048]----+ | .o .+=| | . + o=| | + o B + +| | . * * = @ | | S E o B *| | o @ + o +o| | * B . ...| | * . | | . | +----[SHA256]-----+ [root@eshop-cache03 .ssh]# ssh-copy-id -i eshop-cache01 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host 'eshop-cache01 (192.168.135.126)' can't be established. ECDSA key fingerprint is SHA256:IMfDHqpF+vUaLMGwqMQcBdgJMXG52mmHeKD647Nckts. ECDSA key fingerprint is MD5:2e:4d:92:fc:fb:68:71:b8:eb:00:2f:42:22:7b:c9:67. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@eshop-cache01's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'eshop-cache01'" and check to make sure that only the key(s) you wanted were added.
-
将eshop-cache01中的authorized_keys拷贝到其它主机中
[root@eshop-cache01 .ssh]# scp /root/.ssh/authorized_keys eshop-cache02:/root/.ssh authorized_keys 100% 1600 1.6MB/s 00:00 [root@eshop-cache01 .ssh]# scp /root/.ssh/authorized_keys eshop-cache03\:/root/.ssh authorized_keys 100% 1600 1.7MB/s 00:00 [root@eshop-cache01 .ssh]# scp /root/.ssh/authorized_keys eshop-cache04:/root/.ssh authorized_keys