一、系统配置
- 环境
- 虚拟机:VMware Pro 14
- 创建三台虚拟机,系统为Centos7(CentOS-7-x86_64-DVD-1708.iso)
- 创建/mnt/cdrom,将系统挂在到该目录
- 手动挂载:mount -t iso9660 /dev/cdrom /mnt/cdrom
- 配置开机挂载:修改/etc/fstab文件(照已有修改)
/dev/cdrom /mnt/cdrom iso9660 defaults 0 0
- 修改IP
/etc/sysconfig/network-scriptsTYPE=Ethernet BOOTPROTO=static NAME=ens32 UUID=977bdf5c-1139-4130-a373-57b9baf00d13 DEVICE=ens32 ONBOOT=yes IPADDR=192.168.33.3 NETMASK=255.255.255.0 GATEWAY=192.168.33.1
二、配置本地源YUM
- 前提
挂载上CentOS-7-x86_64-DVD-1708.iso - 修改配置
cd /etc/yum.repos.d/ rename .repo .repo.bak * vi CentOS-Local.repo [base] name=CentOS-Local baseurl=file:///mnt/cdrom gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
- 无网络可以安装软件
- 清理缓存
yum clean all - 列出可用的yum源
yum repolist - 安装软件
yum install -y httpd
- 清理缓存
- 启动httpd
service httpd start
访问80端口 - 若无法访问注意防火强
firewall-cmd --state
systemctl stop firewalld.service
systemctl start firewalld.service
systemctl disable firewalld.service #禁止开机自启
三、免密登陆配置
- 生成公钥私钥
ssh-keygen - 将公钥发送给要登陆的服务器
ssh-copy-id 192.168.33.3
按提示输入密码,其他默认(直接回车)
四、脚本自动安装jdk
- 原理
- 将jdk-8u144-linux-x64.tar.gz放到 /var/www/html/soft目录下,可以让其他服务器wget到,然后自行下载安装
脚本文件boot.sh
- 将jdk-8u144-linux-x64.tar.gz放到 /var/www/html/soft目录下,可以让其他服务器wget到,然后自行下载安装
SERVERS="192.168.33.3 192.168.33.4"
PASSWORD=hjx969190
BASE_SERVER=192.168.33.2
auto_ssh_copy_id() {
expect -c "set timeout -1;
spawn ssh-copy-id $1;
expect {
*(yes/no)* {send -- yes\r;exp_continue;}
*assword:* {send -- $2\r;exp_continue;}
eof {exit 0;}
}";
}
ssh_copy_id_to_all() {
for SERVER in $SERVERS
do
auto_ssh_copy_id $SERVER $PASSWORD
done
}
ssh_copy_id_to_all
for SERVER in $SERVERS
do
scp install_everyone.sh root@$SERVER:/root
ssh root@$SERVER /root/install_everyone.sh
done
/install_everyone.sh脚本
#!/bin/bash
BASE_SERVER=192.168.33.2
yum install -y wget
wget $BASE_SERVER/soft/jdk-8u144-linux-x64.tar.gz
tar -zxvf jdk-8u144-linux-x64.tar.gz -C /usr/local
cat >> /etc/profile << EOF
export JAVA_HOME=/usr/local/jdk1.8.0_144
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
source /etc/profile