CAS WAR Overlays是CAS官网最为推荐的安装部署方式,为何最为推荐,可阅读《CAS 部署建议》了解。本篇文章详细介绍CAS WAR Overlays部署步骤。
一、安装JDK 11
安装JDK 11具体步骤本文不赘述,请另行参考。
二、下载CAS WAR Overlays 模板工程
项目下载地址:https://github.com/apereo/cas-overlay-template
使用git命令下载最新的CAS WAR Overlays 模板工程
git clone https://github.com/apereo/cas-overlay-template.git
三、构建前准备
配置阿里云gradle镜像:
cd cas-overlay-template
vim build.gradle
将mavenCentral() 和 jcenter()注释掉,添加阿里的maven仓库地址,如下:
buildscript {
repositories {
mavenLocal()
//mavenCentral()
//jcenter()
maven { url 'https://maven.aliyun.com/repository/google'}
maven { url 'https://maven.aliyun.com/repository/gradle-plugin'}
maven { url 'https://maven.aliyun.com/repository/public'}
maven { url 'https://maven.aliyun.com/repository/jcenter'}
}
dependencies {
classpath "de.undercouch:gradle-download-task:${project.gradleDownloadTaskVersion}"
classpath "org.springframework.boot:spring-boot-gradle-plugin:${project.springBootVersion}"
classpath "gradle.plugin.com.google.cloud.tools:jib-gradle-plugin:${project.jibVersion}"
classpath "io.freefair.gradle:maven-plugin:${project.gradleMavenPluginVersion}"
}
}
repositories {
mavenLocal()
//mavenCentral()
//jcenter()
maven { url 'https://maven.aliyun.com/repository/google'}
maven { url 'https://maven.aliyun.com/repository/gradle-plugin'}
maven { url 'https://maven.aliyun.com/repository/public'}
maven { url 'https://maven.aliyun.com/repository/jcenter'}
}
四、构建项目
cd cas-overlay-template
./gradlew clean build
如果您想观察详细构建过程和细节,可使用 --info 或 --debug 打印构建日志(示例:./gradlew clean build --info)
[root@bogon cas-overlay-template]# ./gradlew clean build --info
Initialized native services in: /root/.gradle/native
Removing 0 daemon stop events from registry
Starting a Gradle Daemon (subsequent builds will be faster)
Starting process 'Gradle build daemon'. Working directory: /root/.gradle/daemon/5.6.3
……
BUILD SUCCESSFUL in 16s
3 actionable tasks: 3 executed
如果出现以下错误请切换其他分支进行构建:
例如切换到 6.1版本分支
git checkout 6.1
然后重新执行编译命令
五、查看CAS的gradlew的可用任务
./gradlew tasks
[root@bogon cas-overlay-template]# ./gradlew tasks
> Task :tasks
------------------------------------------------------------
Tasks runnable from root project
------------------------------------------------------------
Build tasks
-----------
allDependencies - Display a graph of all project dependencies
allDependenciesInsight - Produce insight information for all dependencies
assemble - Assembles the outputs of this project.
bootJar - Assembles an executable jar archive containing the main classes and their dependencies.
bootWar - Assembles an executable war archive containing webapp content, and the main classes and their dependencies.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
casVersion - Display the current CAS version
classes - Assembles main classes.
clean - Deletes the build directory.
copyCasConfiguration - Copy the CAS configuration from this project to /etc/cas/config
createKeystore - Create CAS keystore
debug - Debug the CAS web application in embedded mode on port 5005
executable - Run the CAS web application in standalone executable mode
explodeWar - Explodes the CAS archive and resources jar from the CAS web application archive
explodeWarOnly - Explodes the CAS web application archive
getResource - Fetch a CAS resource and move it into the overlay
jar - Assembles a jar archive containing the main classes.
listTemplateViews - List all CAS views
run - Run the CAS web application in embedded container mode
setExecutable - Configure the project to run in executable mode
showConfiguration - Show configurations for each dependency, etc
testClasses - Assembles test classes.
war - Generates a war archive with all the compiled classes, the web-app content and the libraries.
Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.
Docker tasks
------------
copyConfigIntoJib - Copy the CAS configuration into Docker image
copyWebAppIntoJib - Copy the web application into Docker image
deleteWebAppFromJib - Explodes the CAS web application archive
Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.
Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'cas'.
components - Displays the components produced by root project 'cas'. [incubating]
dependencies - Displays all dependencies declared in root project 'cas'.
dependencyInsight - Displays the insight into a specific dependency in root project 'cas'.
dependentComponents - Displays the dependent components of components in root project 'cas'. [incubating]
help - Displays a help message.
model - Displays the configuration model of root project 'cas'. [incubating]
projects - Displays the sub-projects of root project 'cas'.
properties - Displays the properties of root project 'cas'.
tasks - Displays the tasks runnable from root project 'cas'.
IDE tasks
---------
cleanEclipse - Cleans all Eclipse files.
cleanEclipseWtp - Cleans Eclipse wtp configuration files.
cleanIdea - Cleans IDEA project files (IML, IPR)
eclipse - Generates all Eclipse files.
eclipseWtp - Generates Eclipse wtp configuration files.
idea - Generates IDEA project files (IML, IPR, IWS)
openIdea - Opens the IDEA project
Jib tasks
---------
jib - Builds a container image to a registry.
jibBuildTar - Builds a container image to a tarball.
jibDockerBuild - Builds a container image to a Docker daemon.
Shell tasks
-----------
debugShell - Run the CAS shell with debug options, wait for debugger on port 5005
downloadShell - Download CAS shell jar from snapshot or release maven repo
runShell - Run the CAS shell
Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.
Rules
-----
Pattern: clean<TaskName>: Cleans the output files of a task.
Pattern: build<ConfigurationName>: Assembles the artifacts of a configuration.
Pattern: upload<ConfigurationName>: Assembles and uploads the artifacts belonging to a configuration.
……
BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
六、下载并启动CAS 命令行工具
./gradlew downloadShell runShell
七、获取或覆盖CAS的资源(resource)或UI(view)
资源清单可查看:
./gradlew getResource -PresourceName=[resource-name]
八、列出CAS的视图和模板清单
./gradlew listTemplateViews
九、解压CAS web应用程序文件和内部资源的jar
./gradlew explodeWar
十、配置CAS
CAS的配置文件被放置在CAS WAR Overlays 模板工程的etc目录下,我们在启动CAS时需要将其拷贝到系统的/etc/cas/config目录,可以使用以下命令完成拷贝:
./gradlew copyCasConfiguration
十一、添加其他CAS模块
首先需要编辑build.gradle文件,将需要添加的模块加入以下依赖描述中:
dependencies {
compile "org.apereo.cas:cas-server-some-module:${project.casVersion}"
...
}
然后执行以下命令将依赖下载并加入到项目中:
./gradlew allDependencies
十二、清除Gradle的缓存
仅当真实需要的时候才执行,例如缓存的jar有错误
rm -rf $HOME/.gradle/caches/
十三、部署CAS Server步骤
1.创建密钥/证书
可以使用JDK的keytool来生成,也可以通过以下命令来完成:
./gradlew createKeystore
2.具体的部署安装步骤可参考以下博文
《手把手教Apereo CAS5.2.3服务端Server的开发环境》https://blog.csdn.net/u010588262/article/details/79741626