1.前提说明
- VMware 17.5.1 (自行安装),参考
- Debian 12
- maven 3.8.7
- git 2.39.2
- jdk 1.8 / 11 / 17
1.1.Debian 下载
访问(https://www.debian.org/download)
下载 Debian
这是 Debian 12,代号为 bookworm,网络安装,用于 64 位 PC(amd64) debian-12.5.0-amd64-netinst.iso。
2.系统安装
2.1.Vmware 挂载 CD
shell
su -l
mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
ls /mnt/cdrom
cd /mnt/cdrom
tar xzvf VMwareTools-10.3.25-20206839.tar.gz -C /tmp
cd /tmp/vmware-tools-distrib/
sudo ./vmware-install.pl
2.2.设置国内软件源
shell
sudo nano /etc/apt/sources.list
# 注释原文件信息,添加下面信息
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
按下 Ctrl + X,然后按下 Y 保存修改,回车
2.3.更新软件
shell
sudo apt update
3.系统软件安装
3.1.安装多版本jdk
shell
su -l
# debian 12 默认jdk17
sudo apt-get install default-jdk
# 显示默认java安装位置
update-alternatives --display java
which java
# 安装java 8
# https://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html
su root
sudo tar -zxvf jdk-8u391-linux-x64.tar.gz -C /usr/lib/jvm/
# 添加java可选项目
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_391/bin/java 8
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0_391/bin/javac 8
sudo update-alternatives --config java
#sudo update-alternatives --config javac
# 安装java 11
# https://www.oracle.com/java/technologies/javase/jdk11-archive-downloads.html
sudo tar -zxvf jdk-11.0.21_linux-x64_bin.tar.gz -C /usr/lib/jvm/
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.21/bin/java 11
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-11.0.21/bin/javac 11
sudo update-alternatives --config java
#sudo update-alternatives --config javac
3.2.安装maven
shell
sudo apt install maven
# 设置maven的仓库源
cd /etc/maven
sudo nano settings.xml
# 注释原文件信息,添加下面信息
<mirrors>
<mirror>
<id>aliyun-maven</id>
<url>https://maven.aliyun.com/repository/public</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
3.3.安装git
shell
sudo apt install git
3.4.DNS映射
shell
sudo nano /etc/hosts
192.168.73.128 master
192.168.73.129 slave
4.虚拟机克隆
克隆后的新系统执行以下命令,对基本信息进行修改
shell
# 修改用户名为 slave
adduser slave
usermod -aG sudo slave
su - slave
sudo cp -a /home/master /home/slave
sudo usermod -l master master
#sudo usermod -l slave slave
#sudo usermod -d /home/slave slave
usermod -d /home/master master
chown -R master:master /home/master
usermod -d /home/slave slave
chown -R slave:master /home/slave
sudo nano /etc/hostname
#master修改为slave
sudo nano /etc/hosts
#master修改为slave
# 删除用户
sudo deluser --remove-home --remove-all-files master
5.java代码编译以及启动(选)
shell
# mvn 通用编译
mvn -Dfile.encoding=UTF-8 -DskipTests=true clean package -P prod
# 注册中心编译
cd /home/master/gitlab/**/**
mvn -Dfile.encoding=UTF-8 -DskipTests=true clean package -P master
mvn -Dfile.encoding=UTF-8 -DskipTests=true clean package -P slave
# 服务启动说明
## 配置中心
java -jar -Dspring.profiles.active=native **-config-*.*.*.jar
## 服务发现
java -jar -Dspring.profiles.active=master **-discovery-**-master.jar
java -jar -Dspring.profiles.active=slave **-discovery-**-slave.jar
## 其他服务
java -jar -Dspring.profiles.active=prod **.jar