Jenkins本身不提供很多功能,我们可以通过使用插件来满足我们的使用。例如从Gitlab拉取代码,使用
Maven构建项目等功能需要依靠插件完成。接下来演示如何下载插件。
Jenkins国外官方插件地址下载速度非常慢,所以可以修改为国内插件地址:
Jenkins->Manage Jenkins->Manage Plugins,点击Available
cd /var/lib/jenkins/updates
sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json
sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json
最后,Manage Plugins点击Advanced,把Update Site改为国内插件下载地址
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
Jenkins->Manage Jenkins->Manage Plugins,点击Available,搜索"Chinese"
Localization: Chinese (Simplified)
安装Role-based Authorization Strategy插件
开启权限全局安全配置
在系统管理页面进入 Manage and Assign Roles
创建角色
我们添加以下三个角色:
在系统管理页面进入 Manage Users
分别创建两个用户:lily/123456,lucy/123456
系统管理页面进入Manage and Assign Roles,点击Assign Roles
绑定规则如下:
lily用户分别绑定baseRole和role1角色
lucy用户分别绑定baseRole和role2角色
使用管理员创建两个项目
role1-test1
role2-test1
结果为:
lily用户登录,只能看到role1项目
lucy用户登录,只能看到role2项目
凭据可以用来存储需要密文保护的数据库密码、Gitlab密码信息、Docker私有仓库密码等,以便
Jenkins可以和这些第三方的应用进行交互。
要在Jenkins使用凭证管理功能,需要安装Credentials Binding插件
安装完成之后:多了个菜单
常用的凭证类型有:
Username with password(用户密码)
SSH Username with private key(SSH密钥)
# 安装
yum install git -y
# 安装后查看版本
git --version
Dashboard->zengqingfa->凭据->用户->全局凭据 (unrestricted)
root/12345678
zhangsan/12345678
创建项目:freestyle-project01
配置gitlab信息:
保存即可。
点击构建:
[root@k8snode1 ~]# cd /var/lib/jenkins/workspace/
[root@k8snode1 workspace]# ll
总用量 0
drwxr-xr-x 4 root root 148 3月 20 21:44 freestyle-project01
drwxr-xr-x 2 root root 6 3月 20 21:44 freestyle-project01@tmp
[root@k8snode1 workspace]# cd freestyle-project01
[root@k8snode1 freestyle-project01]# ll
总用量 16
-rw-r--r-- 1 root root 2636 3月 20 21:44 email.html
-rw-r--r-- 1 root root 1374 3月 20 21:44 Jenkinsfile
-rw-r--r-- 1 root root 620 3月 20 21:44 pom.xml
-rw-r--r-- 1 root root 0 3月 20 21:44 README.md
-rw-r--r-- 1 root root 579 3月 20 21:44 sonar-project.properties
drwxr-xr-x 3 root root 18 3月 20 21:44 src
SSH免密登录示意图
ssh-keygen -t rsa -C "登录gitlab的邮箱"
eg>
[root@k8snode1 ssh]# ssh-keygen -t rsa -C "zengqingfa_java@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:sp/E+DzfXdSp6NYyESKqyVd293uPE4xM+CFtV9feb/E zengqingfa_java@163.com
The key's randomart image is:
+---[RSA 2048]----+
| .|
| +|
| o oo|
| . .o.= ..=|
| o S .*.= .*|
| . B . o= +.E|
| . o = + ..+. o.|
| + . =...= +.+ |
| . =oo.+.=.o|
+----[SHA256]-----+
[root@k8snode1 ssh]# cd /root/.ssh
[root@k8snode1 .ssh]# ll
总用量 8
-rw------- 1 root root 1679 3月 20 21:49 id_rsa
-rw-r--r-- 1 root root 405 3月 20 21:49 id_rsa.pub
[root@k8snode1 .ssh]# cat id_rsa
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAu5WrCLwizd/Jc4+CE55V5L7TVqkGhxqAv9V+0x51nRtTe
xH0S8fGyJVJRXCWhTnr/9ej0qMpkggRG+ELo4nhohymF++YvHo/MvtAQ1INEr8ug
YlskdLxYBL3XveOvMqljnwoUoO/OlwN6DpsMHyABxHm2mWgpWzv6VSgRNnExVW/Y
FYdjZKUAzGO2GloGiWn74jRj9/RXJMKYydYlmUUDTxczhUm5Twu4EULLzYdXWf9d
Sm31wKguvn9GuBjfSVC143Sai2WECMtQvIsbEqPwIzD5kskxovE7EpEOk9JlxETZ
Y2m3UYDQhyiAVcY5P5lAbmmZTJDmh9rhVnmIRQIDAQABAoIBAQCQe1EHI1FzXMDf
X1OXM63xabGzywcfYfnm8Q6/Yf3uGhCn/+GtWeCztcPO9z5vSRSbTCXGFK4NLAaK
Fh1Lrs2NUczA/nySbtMwKPY8qimsZYcMGDzqROUpfMAWttprCemxjcKLhsoow0xO
CIGEqmuFtbNmz5CTTCU+fk3sNTY8xVS5PMTdAt4qylR0hV9RXW31ERDeSYDa5k8t
q2NawFVBpyW7U7hqa+HIYcIR7C+aF08P5xk9yXgagOJUv+7anWGA9I2bJDNvIC7N
Ivl13Ob0uQd4Gz6n3Wi48CRfJ49ZPaM44FBzFSkqrouyxu/+TQhwtFtARqPI2Adm
CXSWNz/pAoGBAONwZ71vihNHIhKiGWCkZrCsRaOs9VU/nT8pQijaO1RKrikjnHdc
7ZcLixBysomc9fgjqW/oAiZq71/KrPloV8+k2DPRuQBwwxHXqhlDsPVxhiQGJBtY
X3MPvneQ40wxlYhVT9jGXf/A5ZX0y1MF3yjf+d7K+jzMDidjm20+DAoGBANMk
CvGR+om1iveqNxVKzFvyd7NJGr/yfpSCMCuU04HJIqWJBXE4X835RzZk8yU4RZ4v
J1BybFkZAC5CGqTk0zoHS0Rufei8eo3LaArecWK2bU69ZdlamLlW5MHTjbw2dJak
gSRXHI2fzVVc6C7xIcDoGuxg4hEodzeZXn/uyDaXAoGBAK6BVFd4+UwJTA9X6HjK
KzBrPZNz5VjfUltf4K9Poi3ujupptGexGWrHJJAeMPZ9RAx78Ek4jk3Dxp6M92L1
uEpNhMVdqMC5xDIwcwandWMdE3sYayPADpxN/CnpNT0E3mKYcoc0zHKrInyIMmkk
gp94V+PWjyjKJT1S/bU6jBLZAoGASDo1MCwiy4b58f0deMAspmuMfR1N9Ems+XqL
pez0aZp3qq7z2KZTR6+1p6ri7mGQlytERKXP4K7HvAtK+At7IoeqPM+bbMlFF0p0
3fr4SK9lNyFdPPxb8FMEUDXhb3gla/78WoUeNGhtIn10w9IjHM2JoEEINJxmI/Po
OtVhUiMCgYALMV4hc5h2WhFaAe/bnt1ao5RdGo/qzvFZA/U61lrdYjvGOnzP8PYx
8oSiP/kiS/+xaDf50Jvz/PbsuIy7twA4fwEC7foypE6jBQ26r59s5q7hbYozZ/Iu
KDYUywdPwLGuxVP/19wB3f2KvMEFG26oNJfxvjwZTjWPFpuoK6TIfA==
-----END RSA PRIVATE KEY-----
[root@k8snode1 .ssh]# cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABA7lasIvCLN38lzj4ItqQTnlXkvtNWqQaHGoC/1X7THnWdG1N7EfRLx8bIlUlFcJaFOev/16PSoymSCBEb4QujieGiHKYX75i8ej8y+0BDUg0Svy6BiWyR0vFgEvde9468yqWOfChSg786XA3oOmwwfIAHEebaZaClbO/pVKBE2cTFVb9gVh2NkpQDMY7YaWgaJafviNGP39FckwpjJ1iWZRQNPFzOFSblPC7gRQsvNh1dZ/11KbfXAqC6+f0a4GN9JULXjdJqLZYQIy1C8ixsSo/AjMPmSyTGi8TsSkQ6T0mXERNljabdRgNCHKIBVxjk/mUBuaZlMkOaH2uFWeYhF zengqingfa_java@163.com
[root@k8snode1 .ssh]#
id_rsa.pub:公钥,复制到gitlab平台配置ssh-key
id_rsa:私钥,复制到jenkins平台配置jenkins凭据
拷贝ssh路径
测试构建:
[root@k8snode1 .ssh]# cd /var/lib/jenkins/workspace/
[root@k8snode1 workspace]# ll
总用量 0
drwxr-xr-x 4 root root 148 3月 20 21:44 freestyle-project01
drwxr-xr-x 2 root root 6 3月 20 22:15 freestyle-project01@tmp
drwxr-xr-x 4 root root 148 3月 20 23:00 freestyle-project02-ssh
drwxr-xr-x 2 root root 6 3月 20 23:00 freestyle-project02-ssh@tmp
[root@k8snode1 workspace]# cd freestyle-project02-ssh
[root@k8snode1 freestyle-project02-ssh]# ll
总用量 16
-rw-r--r-- 1 root root 2636 3月 20 23:00 email.html
-rw-r--r-- 1 root root 1374 3月 20 23:00 Jenkinsfile
-rw-r--r-- 1 root root 620 3月 20 23:00 pom.xml
-rw-r--r-- 1 root root 0 3月 20 23:00 README.md
-rw-r--r-- 1 root root 579 3月 20 23:00 sonar-project.properties
drwxr-xr-x 3 root root 18 3月 20 23:00 src
[root@k8snode1 freestyle-project02-ssh]#
在Jenkins集成服务器上,我们需要安装Maven来编译和打包项目。
上传mavenjar包
# 递归创建目录
mkdir -p /opt/maven
cd /opt/maven
# 解压
tar -xzf apache-maven-3.6.2-bin.tar.gz
cd /opt/maven/apache-maven-3.6.2
vi /etc/profile
# 配置环境变量
export JAVA_HOME=/usr/java/jdk1.8.0_171-amd64
export MAVEN_HOME=/opt/maven/apache-maven-3.6.2
export PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin
# 配置生效
source /etc/profile
# 查找Maven版本
mvn -v
eg>
[root@k8snode1 jdk1.8.0_171-amd64]# vim /etc/profile
[root@k8snode1 jdk1.8.0_171-amd64]# source /etc/profile
[root@k8snode1 jdk1.8.0_171-amd64]# mvn -v
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T23:06:16+08:00)
Maven home: /opt/maven/apache-maven-3.6.2
Java version: 1.8.0_171, vendor: Oracle Corporation, runtime: /usr/java/jdk1.8.0_171-amd64/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-862.11.6.el7.x86_64", arch: "amd64", family: "unix"
查看linux中jdk的安装路径
[root@zqf apache-maven-3.6.2]# which java
/usr/bin/java
[root@zqf apache-maven-3.6.2]# cd /usr/bin/java
-bash: cd: /usr/bin/java: 不是目录
[root@zqf apache-maven-3.6.2]# ls -lrt /usr/bin/java
lrwxrwxrwx. 1 root root 22 4月 6 22:41 /usr/bin/java -> /etc/alternatives/java
[root@zqf apache-maven-3.6.2]# ls -lrt /etc/alternatives/java
lrwxrwxrwx. 1 root root 71 4月 6 22:41 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64/jre/bin/java
[root@zqf apache-maven-3.6.2]# cd /usr/lib/jvm
[root@zqf jvm]# ll
总用量 0
drwxr-xr-x. 3 root root 17 4月 6 22:41 java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64
lrwxrwxrwx. 1 root root 21 4月 6 22:41 jre -> /etc/alternatives/jre
lrwxrwxrwx. 1 root root 27 4月 6 22:41 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
lrwxrwxrwx. 1 root root 35 4月 6 22:41 jre-1.8.0-openjdk -> /etc/alternatives/jre_1.8.0_openjdk
lrwxrwxrwx. 1 root root 49 4月 6 22:41 jre-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64 -> java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64/jre
lrwxrwxrwx. 1 root root 29 4月 6 22:41 jre-openjdk -> /etc/alternatives/jre_openjdk
[root@zqf jvm]# ll
总用量 0
drwxr-xr-x. 3 root root 17 4月 6 22:41 java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64
lrwxrwxrwx. 1 root root 21 4月 6 22:41 jre -> /etc/alternatives/jre
lrwxrwxrwx. 1 root root 27 4月 6 22:41 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
lrwxrwxrwx. 1 root root 35 4月 6 22:41 jre-1.8.0-openjdk -> /etc/alternatives/jre_1.8.0_openjdk
lrwxrwxrwx. 1 root root 49 4月 6 22:41 jre-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64 -> java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64/jre
lrwxrwxrwx. 1 root root 29 4月 6 22:41 jre-openjdk -> /etc/alternatives/jre_openjdk
Jenkins->Global Tool Configuration->JDK->新增JDK,配置如下:
/usr/java/jdk1.8.0_171-amd64
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64/jre
# 创建本地仓库目录
[root@k8snode1 apache-maven-3.6.2]# cd /opt/maven/apache-maven-3.6.2
# 创建仓库地址
[root@k8snode1 apache-maven-3.6.2]# mkdir repository
[root@k8snode1 apache-maven-3.6.2]# cd repository/
[root@k8snode1 repository]# pwd
/opt/maven/apache-maven-3.6.2/repository
# 修改仓库地址,配置阿里云私服地址
vim /opt/maven/apache-maven-3.6.2/conf/settings.xml
eg>
<localRepository>/opt/maven/apache-maven-3.6.2/repository</localRepository>
阿里云私服地址:
<mirrors>
<mirror>
<id>nexus-aliyunid>
<mirrorOf>centralmirrorOf>
<name>Nexus aliyunname>
<url>http://maven.aliyun.com/nexus/content/groups/publicurl>
mirror>
mirrors>
使用之前的gitlab密码测试项目,修改配置
mvn clean package
> git rev-list --no-walk 27f1d24c38d459ecf40cdd07c4fdc9584bdb533b # timeout=10
[test02] $ /bin/sh -xe /tmp/jenkins4976375680064281078.sh
+ mvn clean package
[ERROR] Could not create local repository at /root/repo -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LocalRepositoryNotAccessibleException
Build step 'Execute shell' marked build as failure
#jenkins用户非root用户,为jenkins用户,需要修改jenkins的用户为root
[root@zqf apache-maven-3.6.2]# pwd
/opt/maven/apache-maven-3.6.2
[root@zqf apache-maven-3.6.2]# ll
total 28
drwxr-xr-x. 2 root root 97 Apr 8 12:41 bin
drwxr-xr-x. 2 root root 42 Apr 8 12:41 boot
drwxrwxr-x. 3 zengqingfa zengqingfa 63 Apr 8 19:47 conf
drwxrwxr-x. 4 zengqingfa zengqingfa 4096 Apr 8 12:41 lib
-rw-rw-r--. 1 zengqingfa zengqingfa 12846 Aug 27 2019 LICENSE
-rw-rw-r--. 1 zengqingfa zengqingfa 182 Aug 27 2019 NOTICE
-rw-rw-r--. 1 zengqingfa zengqingfa 2533 Aug 27 2019 README.txt
drwxr-xr-x. 11 root root 160 Apr 8 19:48 repository
服务器:192.168.12.131
上传到服务器
# 安装JDK(已完成) -y表示遇到选择的情况选择y
yum install java-8-openjdk* -y
# 解压
tar -xzf apache-tomcat-8.5.47.tar.gz
# 创建目录
mkdir -p /opt/tomcat
# 移动文件
mv /root/apache-tomcat-8.5.47/* /opt/tomcat
# 启动tomcat
/opt/tomcat/bin/startup.sh
eg>
[root@zengqingfa hello-world-01]# cd /root
[root@zengqingfa ~]# ls
2000 apache-tomcat-8.5.47.tar.gz jdk-8u171-linux-x64.tar.gz repo
apache-maven-3.6.2 a.txt jenkins-2.278-1.1.noarch.rpm sonarqube-6.7.4.zip
apache-maven-3.6.2-bin.tar.gz harbor-offline-installer-v1.9.2.tgz nginx-1.14.2.tar.gz
[root@zengqingfa ~]# tar -xzf apache-tomcat-8.5.47.tar.gz
[root@zengqingfa ~]# mkdir -p /opt/tomcat
[root@zengqingfa ~]# mv /root/apache-tomcat-8.5.47/* /opt/tomcat
[root@zengqingfa ~]# /opt/tomcat/bin/startup.sh
[root@zengqingfa tomcat]# ./bin/startup.sh
Using CATALINA_BASE: /opt/tomcat
Using CATALINA_HOME: /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME: /usr/lib/jvm/java-11-openjdk-11.0.10.0.9-0.el7_9.x86_64/jre
Using CLASSPATH: /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.
启动报错:jdk11默认没有jre
找不到目录:
[root@iZbp1f7db1tbkqgwvhjwl9Z bin]# cat ../logs/catalina.out
/opt/tomcat/bin/catalina.sh: line 467: /usr/lib/jvm/java-11-openjdk-11.0.10.0.9-0.el7_9.x86_64/jre/bin/java: No such file or directory
/opt/tomcat/bin/catalina.sh: line 467: /usr/lib/jvm/java-11-openjdk/jre/bin/java: No such file or directory
/opt/tomcat/bin/catalina.sh: line 467: /usr/lib/jvm/java-11-openjdk/jre/bin/java: No such file or directory
/opt/tomcat/bin/catalina.sh: line 467: /usr/lib/jvm/java-11-openjdk-11.0.10.0.9-0.el7_9.x86_64/jre/bin/java: No such file or directory
安装jre:
[root@iZbp1f7db1tbkqgwvhjwl9Z tomcat]# cd /usr/lib/jvm/java-11-openjdk-11.0.10.0.9-0.el7_9.x86_64
[root@iZbp1f7db1tbkqgwvhjwl9Z java-11-openjdk-11.0.10.0.9-0.el7_9.x86_64]# ll
total 40
drwxr-xr-x 2 root root 4096 Feb 19 16:40 bin
drwxr-xr-x 4 root root 4096 Feb 14 23:49 conf
drwxr-xr-x 4 root root 4096 Feb 14 23:50 demo
drwxr-xr-x 3 root root 4096 Feb 14 23:49 include
drwxr-xr-x 2 root root 4096 Feb 14 23:50 jmods
drwxr-xr-x 73 root root 4096 Jan 22 23:39 legal
drwxr-xr-x 8 root root 4096 Feb 14 23:50 lib
-rw-r--r-- 1 root root 1212 Jan 22 23:39 release
drwxr-xr-x 4 root root 4096 Feb 14 23:50 sample
drwxr-xr-x 2 root root 4096 Feb 14 23:49 tapset
[root@iZbp1f7db1tbkqgwvhjwl9Z java-11-openjdk-11.0.10.0.9-0.el7_9.x86_64]# jlink --module-path jmods --add-modules java.desktop --output jre
[root@iZbp1f7db1tbkqgwvhjwl9Z java-11-openjdk-11.0.10.0.9-0.el7_9.x86_64]# ll
total 44
drwxr-xr-x 2 root root 4096 Feb 19 16:40 bin
drwxr-xr-x 4 root root 4096 Feb 14 23:49 conf
drwxr-xr-x 4 root root 4096 Feb 14 23:50 demo
drwxr-xr-x 3 root root 4096 Feb 14 23:49 include
drwxr-xr-x 2 root root 4096 Feb 14 23:50 jmods
drwxr-xr-x 7 root root 4096 Feb 19 16:41 jre
drwxr-xr-x 73 root root 4096 Jan 22 23:39 legal
drwxr-xr-x 8 root root 4096 Feb 14 23:50 lib
-rw-r--r-- 1 root root 1212 Jan 22 23:39 release
drwxr-xr-x 4 root root 4096 Feb 14 23:50 sample
drwxr-xr-x 2 root root 4096 Feb 14 23:49 tapset
[root@iZbp1f7db1tbkqgwvhjwl9Z java-11-openjdk-11.0.10.0.9-0.el7_9.x86_64]# cd jre/
[root@iZbp1f7db1tbkqgwvhjwl9Z jre]# ll
total 24
drwxr-xr-x 2 root root 4096 Feb 19 16:41 bin
drwxr-xr-x 3 root root 4096 Feb 19 16:41 conf
drwxr-xr-x 3 root root 4096 Feb 19 16:41 include
drwxr-xr-x 7 root root 4096 Feb 19 16:41 legal
drwxr-xr-x 5 root root 4096 Feb 19 16:41 lib
-rw-r--r-- 1 root root 94 Feb 19 16:41 release
配置环境变量:
vim /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.10.0.9-0.el7_9.x86_64
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}
生效:source /etc/profile
继续启动:报错
[root@iZbp1f7db1tbkqgwvhjwl9Z tomcat]# cat ./logs/catalina.out
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
WARNING: Unknown module: java.rmi specified to --add-opens
Exception in thread "main" java.lang.NoClassDefFoundError: java/util/logging/Logger
at org.apache.juli.logging.DirectJDKLog.<init>(DirectJDKLog.java:68)
at org.apache.juli.logging.DirectJDKLog.getInstance(DirectJDKLog.java:188)
at org.apache.juli.logging.LogFactory.getInstance(LogFactory.java:131)
at org.apache.juli.logging.LogFactory.getInstance(LogFactory.java:155)
at org.apache.juli.logging.LogFactory.getLog(LogFactory.java:210)
at org.apache.catalina.startup.Bootstrap.<clinit>(Bootstrap.java:52)
Caused by: java.lang.ClassNotFoundException: java.util.logging.Logger
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 6 more
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.10.0.9-0.el7_9.x86_64
JRE_HOME=$JAVA_HOME
CLASSPATH=$JAVA_HOME/lib
PATH=$JRE_HOME/bin:$JAVA_HOME/bin:$PATH
export PATH JAVA_HOME CLASSPATH
启动成功。
访问:http://121.196.169.191:8080/
默认情况下Tomcat是没有配置用户角色权限的
vim /opt/tomcat/conf/tomcat-users.xml
<tomcat-users>
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="tomcat" password="tomcat" roles="manager-gui,manager-script,manager-status,tomcat,admin-gui,admin-script"/>
tomcat-users>
用户和密码都是:tomcat
注意:为了能够刚才配置的用户登录到Tomcat,还需要修改以下配置
vim /opt/tomcat/webapps/manager/META-INF/context.xml
重启Tomcat,访问测试
/opt/tomcat/bin/shutdown.sh
/opt/tomcat/bin/startup.sh
:http://121.196.169.191:8080/
[外链图片转存中…(img-kjJBY4dD-1666275041474)]
默认情况下Tomcat是没有配置用户角色权限的
[外链图片转存中…(img-iUHOE7Yj-1666275041474)]
vim /opt/tomcat/conf/tomcat-users.xml
<tomcat-users>
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="tomcat" password="tomcat" roles="manager-gui,manager-script,manager-status,tomcat,admin-gui,admin-script"/>
tomcat-users>
用户和密码都是:tomcat
注意:为了能够刚才配置的用户登录到Tomcat,还需要修改以下配置
vim /opt/tomcat/webapps/manager/META-INF/context.xml
重启Tomcat,访问测试
/opt/tomcat/bin/shutdown.sh
/opt/tomcat/bin/startup.sh
[外链图片转存中…(img-wrvwZiDB-1666275041475)]