一、系统准备 安装多台虚拟机实例,这里是使用的是CentOS 6.10(CentOS610单文件ISO下载); 保证每台虚拟机实例可以联网,至少可以内部互通; 二、环境准备在学习的过程中,有时候就把环境搞坏了,反复反复反复,浪费了很多时间,所以就搞了一个自动化环境配置脚本,在这里记一下
把安装好的虚拟机备份一下,我就直接在原来的安装文件夹压缩了一份
/etc/sysconfig/network-scripts/ifcfg-eth0
,删除其中的HWADDR
和UUID
,我的配置如下(自己的虚拟网关什么的参考vmware的配置):
DEVICE=eth0 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=192.168.100.101 NETMASK=255.255.255.0 GATEWAY=192.168.100.2 DNS1=192.168.100.2 DNS2=8.8.8.8
ping 192.168.1.6
测试,在Win上:ping 192.168.100.101
配置本地yum源,参考我的另一篇文章
CentOS关机,开始克隆集群:
/etc/sysconfig/network-scripts/ifcfg-eth0
,修改IPADDR为自己的机器的IP,其他不用动;其他几台机器也是一样的操作;
删除/etc/udev/rules.d/70-persistent-net.rules
其他几台机器也是一样的操作;注意:有的教程是编辑,我这里直接删除,可以自动生成的;
重启机器:init 6
;
测试网络;
四、将Linux本地文件发布到Apache服务中
安装Apache
yum install -y httpd
/var/www/html中
遇到的问题参考Linux Apache httpd问题总结;
五、自动配置
保存脚本:prepare.sh
,用来配置本地环境以及当前机器与其他机器的免密登录:
#!/bin/bash
SERVERS="192.168.100.101 192.168.100.102 192.168.100.103 192.168.100.104"
PASSWORD=centos610
BASE_SERVER=192.168.100.100
config_ssh_auto_login() {
expect -c "set timeout -1;
spawn ssh-copy-id $1;
expect {
*(yes/no)* {send -- yes
;exp_continue;}
*password:* {send -- $2
;exp_continue;}
eof {exit 0;}
}";
}
config_ssh_auto_login_batch() {
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~ Starting ssh-copy-id ~~~~~~~~~~~~~~~~~~~~~~~~~~
for SERVER in $SERVERS
do
config_ssh_auto_login $SERVER $PASSWORD
done
}
config_local_env() {
yum install -y openssh-clients;
yum install -y expect;
}
config_remote_openssh_clients() {
for SERVER in $SERVERS
do
expect -c "set timeout -1;
spawn ssh root@$SERVER yum install -y openssh-clients;
expect {
*password:* {send -- $PASSWORD
;exp_continue;}
*(yes/no)* {send -- yes
;exp_continue;}
eof {exit 0;}
}";
done
}
make_rsa_key() {
expect -c "set timeout -1;
spawn ssh-keygen;
expect {
*/.ssh/id_rsa* {send --
;exp_continue;}
*empty* {send --
;exp_continue;}
*again* {send --
;exp_continue;}
eof {exit 0;}
}";
}
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~ config local environment ~~~~~~~~~~~~~~~~~~~~~~~~~~
config_local_env
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~ config remote openssh-clients ~~~~~~~~~~~~~~~~~~~~~~~~~~
config_remote_openssh_clients
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~ make rsa key ~~~~~~~~~~~~~~~~~~~~~~~~~~
make_rsa_key
echo ****************************** config ssh auto login ~~~~~~~~~~~~~~~~~~~~~~~~~~
config_ssh_auto_login_batch
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~ copy and execute install.sh ~~~~~~~~~~~~~~~~~~~~~~~~~~
for SERVER in $SERVERS
do
ssh root@$SERVER mkdir /root/scripts
scp install.sh root@$SERVER:/root/scripts
ssh root@$SERVER /root/scripts/install.sh
done
install.sh
#!/bin/bash
BASE_SERVER=192.168.100.100
yum install -y openssh-clients;
yum install -y expect;
yum install -y wget
# Download jdk-8u201-linux-x64.tar.gz
wget $BASE_SERVER/jdk-8u201-linux-x64.tar.gz
tar -zxvf jdk-8u201-linux-x64.tar.gz -C /usr/local/
cat >> /root/.bash_profile << EOF
export JAVA_HOME=/usr/local/jdk1.8.0_201
export PATH=$PATH:$JAVA_HOME/bin
EOF
source /root/.bash_profile
chmod u+x prepare.sh install.sh
prepare.sh
./prepare
VMware下centos7安装k8s(Kubernetes)多master集群