从有道云笔记复制,格式没法保持
前言
环境:CentOS7 + tomcat8
一、Jenkins
先导入仓库
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import http://pkg.jenkins.io/redhat-stable/jenkins.io.key
安装
yum install jenkins
启动
安装JDK后,Jenkins无法启动,需要修改vi /etc/rc.d/init.d/jenkins, 查找,输入/java, 添加新的jre路径
# Search usable Java. We do this because various reports indicated
# that /usr/bin/java may not always point to Java >= 1.6
# see http://www.nabble.com/guinea-pigs-wanted-----Hudson-RPM-for-RedHat-Linux-td25673707.html
candidates="
/etc/alternatives/java
/usr/lib/jvm/java-1.6.0/bin/java
/usr/lib/jvm/jre-1.6.0/bin/java
/usr/lib/jvm/java-1.7.0/bin/java
/usr/lib/jvm/jre-1.7.0/bin/java
/usr/lib/jvm/java-1.8.0/bin/java
/usr/lib/jvm/jre-1.8.0/bin/java
/usr/bin/java
/data/java/jdk1.8.0_101/bin/java
"
#systemctl daemon-reload
#systemctl enable jenkins
#systemctl start jenkins
访问
提示输入密码,在/var/lib/jenkins/secrets/initialAdminPassword中, 默认用户为admin
登录后提示安装插件,点击“推荐的插件”,推荐的插件不包含maven,需要稍后手动安装(Maven Integration plugin)
安装完成后建立一个初始用户,完成 179: admin/admin, 191&192:weipiao/weipiao
卸载方法
#yum remove jenkins
要构建maven项目的话,需要手动配置JDK,Maven,并给本地仓库设置权限(chmod 777 仓库路径),遇到Maven仓库配置时,提示不是maven目录的提示,重新解压后解决,Maven的配置文件从本机复制
二、部署dubbo服务
1. 新建
2. 配置SVN
3. 添加要执行的命令,Goals and options : clean compile exec:java -Dexec.mainClass="Main"
4. 保存后,点击“立即构建”执行,鼠标悬停在当前构建日期上时,有下拉菜单,可以进行相关操作
三、部署web服务
1. 与部署dubbo服务的区别为Goals and options 改为 tomcat7:deploy
2. 配置maven/conf/settings.xml,添加tomcat管理用户
<!-- jenkins使用 -->
<server>
<id>tomcat8</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
3. 配置tomcat/conf/tomcat-users.xml,网上的教程很多都只配置manager,实际要同时有admin与manager的权限才够,如果是tomcat9,需要tomcat\webapps\manager\META-INF\context.xml中
注释
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
tomcat-users.xml:
<!-- jenkins需要 -->
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="admin-jmx"/>
<role rolename="admin-status"/>
<user username="tomcat" password="tomcat" roles="admin-gui,manager-gui,manager-script,manager-jmx,manager-status" />
<user username="admin" password="admin" roles="admin,admin-gui,admin-script,admin-jmx,admin-status" />
四、pom.xml中的配置
service:
<build><defaultGoal>compile</defaultGoal> <resources> <resource> <targetPath>${project.build.directory}/classes</targetPath> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/*.xml</include> <include>**/*.properties</include> </includes> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.4.2</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <classesDirectory>target/classes/</classesDirectory> <archive> <manifest> <!--实际为调用com.alibaba.dubbo.container.Main--> <mainClass>Main</mainClass> <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 --> <useUniqueVersions>false</useUniqueVersions> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> </manifest> <manifestEntries> <Class-Path>.</Class-Path> </manifestEntries> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <type>jar</type> <includeTypes>jar</includeTypes> <!--<useUniqueVersions>false</useUniqueVersions>--> <outputDirectory> ${project.build.directory}/lib </outputDirectory> </configuration> </execution> </executions> </plugin> </plugins> </build>
web:
<build> <finalName>web-demo</finalName> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.1</version> <configuration> <port>9090</port> <uriEncoding>UTF-8</uriEncoding> <url>http://127.0.0.1:9090/manager/text</url> <!--在maven的settings.xml中有配置的--> <server>tomcat8</server> <path>/web-demo</path> </configuration> </plugin> </plugins></build>