## link 链接路径
## name 别名
## path 软件源路径
## priority 优先级
## eg. alternatives --install /usr/bin/java java /usr/local/jdk1.8.0/bin/java 100
alternatives --install <link> <name> <path> <priority>
## 使用alternatives 进行版本控制
[root@localhost /]# alternatives --install /usr/bin/java java /usr/local/java6/jdk1.6.0_45/bin/java 6
[root@localhost /]# alternatives --install /usr/bin/java java /usr/local/java8/jdk1.8.0_251/bin/java 8
[root@localhost /]# alternatives --install /usr/bin/javac javac /usr/local/java6/jdk1.6.0_45/bin/javac 6
[root@localhost /]# alternatives --install /usr/bin/javac javac /usr/local/java8/jdk1.8.0_251/bin/javac 8
## 刷新配置
[root@localhost /]# source /etc/profile
[root@localhost /]# java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
[root@localhost /]# javac -version
javac 1.6.0_45
[root@localhost /]# alternatives --config javac
共有 2 个提供“javac”的程序。
选项 命令
-----------------------------------------------
+ 1 /usr/local/java6/jdk1.6.0_45/bin/javac
* 2 /usr/local/java8/jdk1.8.0_251/bin/javac
按 Enter 保留当前选项[+],或者键入选项编号:
[root@localhost /]# clear
[root@localhost /]# java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
[root@localhost /]# javac -version
javac 1.6.0_45
[root@localhost /]# alternatives --config java
共有 2 个提供“java”的程序。
选项 命令
-----------------------------------------------
+ 1 /usr/local/java6/jdk1.6.0_45/bin/java
* 2 /usr/local/java8/jdk1.8.0_251/bin/java
按 Enter 保留当前选项[+],或者键入选项编号:2
[root@localhost /]# alternatives --config javac
共有 2 个提供“javac”的程序。
选项 命令
-----------------------------------------------
+ 1 /usr/local/java6/jdk1.6.0_45/bin/javac
* 2 /usr/local/java8/jdk1.8.0_251/bin/javac
按 Enter 保留当前选项[+],或者键入选项编号:2
[root@localhost /]# java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
[root@localhost /]# javac -version
javac 1.8.0_251
[root@localhost /]#
[root@localhost /]#
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
执行这一步发现报错
然后执行 yum install -y ca-certificates就行了
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum -y install jenkins
sudo vi /etc/sysconfig/jenkins
sudo service jenkins start
1.使用 root 权限更新 yum 包
yum -y update
2.卸载旧版本(如果之前安装过的话)
yum remove docker docker-common docker-selinux docker-engine
3.安装需要的软件包, yum-util 提供yum-config-manager功能,另两个是devicemapper驱动依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
4.设置 阿里yum 源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
5.选择docker版本并安装 ,查看可用版本有哪些
yum list docker-ce --showduplicates | sort -r
6.选择一个版本并安装:yum install docker-ce-版本号
yum -y install docker-ce-18.03.1.ce
7.启动 Docker 并设置开机自启
systemctl start docker
systemctl enable docker
8.查看docekr版本
docker version
如果之前有则删除
git --version
yum -y remove git
yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm
yum -y install git
git --vresion
下载nacos
https://github.com/alibaba/nacos/releases
上传到服务器然后解压
然后进入到nacos里面的bin里面启动nacos
sh startup.sh -m standalone
关闭
sh shutdown.sh
配置开机自启
进入/lib/systemd/system目录, 创建nacos.service文件
cd /lib/systemd/system
touch nacos.service
编辑nacos.service文件, 增加如下信息 (nacos路径替换成自己的路径即可)
[Unit]
Description=nacos
After=network.target
[Service]
Type=forking
ExecStart=/opt/module/nacos/bin/startup.sh -m standalone
ExecReload=/opt/module/nacos/bin/shutdown.sh
ExecStop=/opt/module/nacos/bin/shutdown.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
编辑nacos/bin目录下的startup.sh, 修改JAVA_HOME的路径, 注释其他三行
执行命令
重新加载所有service服务
systemctl daemon-reload
开机启动nacos.service
systemctl enable nacos.service
查看该service是否开机启用
systemctl is-enabled nacos.service
启动该服务
systemctl start nacos.service
查看该服务状态
systemctl status nacos.service
只能手动启动====到nacos/bin下面执行
单机启动
sh startup.sh -m standalone
到官网下载maven
https://maven.apache.org/download.cgi
配置maven仓库,设置阿里镜像仓库,一定要配置一下,国内的下载jar快些,首先进入cd maven-3.8.5目录,创建仓库存储目录,mkdir ck
cd maven--3.8.5 #进入maven-3.6.3目录
mkdir ck #创建ck目录
进入cd conf目录,编辑 vi settings.xml文件,找到·localRepository下面复制一行加上/opt/module/maven-3.8.5/ck, 在找到mirror 加上阿里的仓库配置,配置完成退出
cd conf # 进入conf目录
vi settings.xm # settings.xm文件
<localRepository>/opt/module/maven-3.8.5/ck</localRepository>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
配置环境变量
vi/etc/profile
export MAVEN_HOME=/opt/module/maven-3.8.5
export PATH=$PATH:$MAVEN_HOME/bin
保存退出
source /etc/profile
验证
mvn -v
shell脚本不会只能用现有的知识写一个了
#!/bin/bash
#filename: run_jar.sh
#desc: 启动jar包,关闭jar包程序
#author: tjr
#根据端口停止jar如果有新的微服务记得加
echo "停止jar"
kill -9 `netstat -nlp | grep 9000 | awk '{print $7}'|awk -F/ '{print $1}'`
kill -9 `netstat -nlp | grep 8002 | awk '{print $7}'|awk -F/ '{print $1}'`
echo "停止jar完成"
#删除旧代码
echo "删除旧代码"
rm -rf /opt/java/code/cloud/
echo "删除旧代码完成"
#备份jar如果有新的微服务记得加
echo "备份jar"
cd /opt/java/jar
mv cloud-user-service-1.0.0.jar /opt/java/jar/backup
mv cloud-bean-1.0.0.jar /opt/java/jar/backup
mv cloud-base-1.0.0.jar /opt/java/jar/backup
mv cloud-common-1.0.0.jar /opt/java/jar/backup
mv cloud-mbp-1.0.0.jar /opt/java/jar/backup
mv cloud-app-gateway-1.0.0.jar /opt/java/jar/backup
echo "备份jar完成"
#拉取新代码
echo "拉取新代码"
cd /opt/java/code
git clone [email protected]:6077a32361a945067837c0cd/cloud/cloud.git
echo "拉取新代码完成"
#打jar包如果有新的微服务记得加
echo "打jar包"
cd /opt/java/code/cloud/cloud-parent
mvn clean compile install package -Dmaven.test.skip=true
cd /opt/java/code/cloud/cloud-bean/target/
cp cloud-bean-1.0.0.jar /opt/java/jar/cloud-bean-1.0.0.jar
cd /opt/java/code/cloud/cloud-base/target/
cp cloud-base-1.0.0.jar /opt/java/jar/cloud-base-1.0.0.jar
cd /opt/java/code/cloud/cloud-common/target/
cp cloud-common-1.0.0.jar /opt/java/jar/cloud-common-1.0.0.jar
cd /opt/java/code/cloud/cloud-mbp/target/
cp cloud-mbp-1.0.0.jar /opt/java/jar/cloud-mbp-1.0.0.jar
cd /opt/java/code/cloud/cloud-user-service/target/
cp cloud-user-service-1.0.0.jar /opt/java/jar/cloud-user-service-1.0.0.jar
cd /opt/java/code/cloud/cloud-app-gateway/target/
cp cloud-app-gateway-1.0.0.jar /opt/java/jar/cloud-app-gateway-1.0.0.jar
echo "打jar包完成"
#运行如果有新的微服务记得加
echo "运行"
nohup /opt/module/jdk-15.0.2/bin/java -jar /opt/java/jar/cloud-app-gateway-1.0.0.jar >> /opt/java/log/app-gateway.log 2>&1 &
nohup /opt/module/jdk-15.0.2/bin/java -jar /opt/java/jar/cloud-user-service-1.0.0.jar >> /opt/java/log/user-service.log 2>&1 &
echo "运行完成"