1、虚拟机联网
ping
2、安装epel-release
注:Extra Packages for Enterprise Linux是为“红帽系”的操作系统提供额外的软件包,适用于RHEL、CentOS和Scientific Linux。相当于
是一个软件仓库,大多数rpm包在官方 repository 中是找不到的)
yum install -y epel-release
3、安装工具
net-tool:工具包集合,包含ifconfig等命令
yum install -y net-tools
vim:编辑器
yum install -y vim
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld.service
4、创建atguigu用户,并修改密码
useradd atguigu
echo '123456'|passwd --stdin atguigu
5、配置atguigu用户具有root权限
方便后期加sudo执行root权限的命令
vim /etc/sudoers
修改/etc/sudoers文件,在%wheel这行下面添加一行,如下所示:
%wheel ALL=(ALL) ALL
atguigu ALL=(ALL) NOPASSWD:ALL
注意:atguigu这一行不要直接放到root行下面,因为所有用户都属于wheel组,你先配置了atguigu具有免密功能,但是程序执行到%wheel行时,
该功能又被覆盖回需要密码。所以atguigu要放到%wheel这行下面。
6、卸载自带的JDK
rpm -qa | grep -i java | xargs -n1 rpm -e --nodeps
#rpm -qa:查询所安装的所有rpm软件包
#grep -i:忽略大小写
#xargs -n1:表示每次只传递一个参数
#rpm -e –nodeps:强制卸载软件
7、修改主机名和映射
cat /etc/hosts
192.168.10.131 k8s01
192.168.10.132 k8s02
192.168.10.133 k8s03
8、安装jdk
mkdir -p /opt/module/
unzip jdk1.8.0_171.zip
mv jdk1.8.0_171 /opt/module/
chown -R atguigu.atguigu /opt/module/
su - atguigu
sudo vim /etc/profile.d/my_env.sh
#JAVA_HOME
export JAVA_HOME=/opt/module/jdk1.8.0_171
export PATH=$PATH:$JAVA_HOME/bin
. /etc/profile
java -version
9、配置ssh免密登录
[atguigu@k8s01 ~]$ ssh-keygen -t rsa
[atguigu@k8s01 ~]$ ssh-copy-id 192.168.10.131
[atguigu@k8s01 ~]$ ssh-copy-id 192.168.10.132
[atguigu@k8s01 ~]$ ssh-copy-id 192.168.10.133
10、xsync集群分发脚本
[atguigu@k8s01 ~]$ sudo yum install -y rsync
[atguigu@k8s01 ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/atguigu/.local/bin:/home/atguigu/bin:/opt/module/jdk1.8.0_171/bin
[atguigu@k8s01 ~]$ cd /home/atguigu
[atguigu@k8s01 ~]$ ls
[atguigu@k8s01 ~]$ mkdir bin
[atguigu@k8s01 ~]$ cd bin/
[atguigu@k8s01 bin]$ vim xsync
#1. 判断参数个数
if [ $# -lt 1 ]
then
echo Not Enough Arguement!
exit;
fi
#2. 遍历集群所有机器
for host in 192.168.10.131 192.168.10.132 192.168.10.133
do
echo ==================== $host ====================
#3. 遍历所有目录,挨个发送
for file in $@
do
#4. 判断文件是否存在
if [ -e $file ]
then
#5. 获取父目录
pdir=$(cd -P $(dirname $file); pwd)
#6. 获取当前文件的名称
fname=$(basename $file)
ssh $host "mkdir -p $pdir"
rsync -av $pdir/$fname $host:$pdir
else
echo $file does not exists!
fi
done
done
[atguigu@k8s01 bin]$ chmod +x xsync
[atguigu@k8s01 bin]$ xsync /home/atguigu/bin
==================== 192.168.10.131 ====================
sending incremental file list
sent 93 bytes received 17 bytes 220.00 bytes/sec
total size is 754 speedup is 6.85
==================== 192.168.10.132 ====================
sending incremental file list
bin/
bin/xsync
sent 893 bytes received 39 bytes 1,864.00 bytes/sec
total size is 754 speedup is 0.81
==================== 192.168.10.133 ====================
sending incremental file list
bin/
bin/xsync
将脚本复制到/bin中,以便全局调用
[atguigu@k8s01 module]$ sudo cp /home/atguigu/bin/xsync /bin/
11、配置查看Java进程脚本
[atguigu@k8s01 module]$ cd /home/atguigu/bin
[atguigu@k8s01 bin]$ vim jpsall
for host in 192.168.10.131 192.168.10.132 192.168.10.133
do
echo =============== $host ===============
ssh $host jps
done
[atguigu@k8s01 bin]$ chmod +x jpsall
[atguigu@k8s01 bin]$ xsync /home/atguigu/bin/
[atguigu@k8s01 bin]$ jpsall
=============== 192.168.10.131 ===============
9168 Jps
=============== 192.168.10.132 ===============
8772 Jps
=============== 192.168.10.133 ===============
8704 Jps