jenkins 配置
实现从git.oschina.net 下载代码,然后发布到服务器上。
代码托管地址: git.oschina.net
jenkins : 192.168.124.131
服务器php环境:192.168.123.132
jenkins 环境安装, 三个目录
[root@jenkins data]# ls
[root@jenkins~]# jdk maven tomcat
[root@agent data]# java -version
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)
[root@agent data]# mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T11:41:47-05:00)
Maven home: /data/maven
Java version: 1.8.0_92, vendor: Oracle Corporation
Java home: /data/jdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-229.el7.x86_64", arch: "amd64", family: "unix"
[root@agent bin]# ./version.sh ###tomcat版本为
Server number: 7.0.55.0
OS Name: Linux
OS Version: 3.10.0-229.el7.x86_64
Architecture: amd64
JVM Version: 1.8.0_92-b14
JVM Vendor: Oracle Corporation
设置环境变量
[root@agent ~]# cat /etc/profile
export JAVA_HOME=/data/jdk
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$JAVA_HOME:$PATH
MAVEN_HOME=/data/maven
export MAVEN_HOME
export PATH=${PATH}:${MAVEN_HOME}/bin
启动jenkins
[root@jenkins~]# cp /root/jenkins.war /data/tomcat/webapps/ 自动后会自动解压缩
修改tomcat server.xml配置文件, 添加URIEncoding = utf-8
启动tomcat
[root@jenkins~]# /data/tomcat/bin/startup.sh
登陆jenkins 页面: http://192.168.124.131/jenkins/
查看/root/.jenkins/secrets/initialAdminPassword 密码文件,填写后,点击继续。
[root@server ~]# cat /root/.jenkins/secrets/initialAdminPassword
495776b1bfb24f15ad4458a9a85ac4ed
插件安装过程中,可能会出现下载失败, 可以记录后,在系统中重现安装,或者下载后,提交安装。
一。 系统管理- jenkins管理 --- 管理插件
安装的基本插件为:
-
Email Extension Plugin
(邮件通知) -
GIT plugin
(可能已经默认安装了) -
Publish Over SSH
(远程Shell) -
Maven lnfo Plugin
二 点击系统设置
发邮件的格式:
<hr/>
(本邮件是程序自动发送的,请勿回复!) <br/><hr/>
项目in过程: $PROJECT_NAME </br><hr/>
Jenkins address: http://192.168.123.131/jenkins
构建编号: $BUILD_NUMBER </br><hr/>
构建状态: $BUILD_STATUS! </br><hr/>
触发原因: ${CAUSE} </br><hr/>
Remote Directory 目录更改为 /data
三。系统管理, 管理jenkins configure Global Security
四 。系统管理, 管理jenkins configure Global Security
###########################################################################################
构建新任务
1. 描述
Remote directory 改成 code
目的:把war包放置在 /data/code目录下
六。服务器端jenkins配置rsync server, 服务器端执行rsync.sh脚本同步数据
vim /etc/rsync.conf
[root@jenkins data]# cat /etc/rsync.conf
uid = nobody
gid = nobody
use chroot = no
max connections = 10
strict modes = yes
pid file = /var/run/rsync.pid
lock file=/var/run/rsync.lock
log file = /var/log/rsync.log
transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
[uchance_php]
path = /root/.jenkins/workspace/test
comment = uchance_salesoft
ignore errors
read only = no
write only = no
hosts allow = *
list = false
uid = root
gid = root
auth users = backup
secrets file=/etc/rsyncd.pass
设置密码文件
[root@jenkins data]# cat /etc/rsyncd.pass
backup:123456
设置rsync权限
[root@jenkins data]# chmod 600 /etc/rsyncd.pass
启动rsync进程
[root@jenkins data]# /usr/bin/rsync --config=/etc/rsync.conf --daemon
########################################################
客户端配置rsync密码,以及脚本
[root@client~]# cat /etc/rsyncd.pass
123456
设置权限
[root@client~]# chmod 600 /etc/rsyncd.pass
rsync.sh 脚本
[root@client~]# cat /root/rsync.sh
#!/bin/bash
/usr/bin/rsync -vzrtopg --delete --progress backup@192.168.124.131::uchance_php /data/phpdata/ --password-file=/etc/rsyncd.pass