1.安装JDK7
1.1 下载JDK7
可能不能直接使用wget下载,可使用迅雷下载
http://download.oracle.com/otn-pub/java/jdk/7/jdk-7-linux-i586.tar.gz
拷贝到目录/usr/local
1.2 解压安装包[root@localhost local]#tar -zxvf jdk-7-linux-i586.tar.gz1.3修改环境变量
[root@localhost local]# vi /etc/profile添加下面几行
exportJAVA_HOME=/usr/local/jdk1.7.0 exportJRE_HOME=/usr/local/jdk1.7.0/jre exportCLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH exportPATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
1.4 执行命令
[root@bogonopt]# source /etc/profile
这样环境变量的修改就生效了
1.5 验证JDK安装结果
[root@localhostjdk1.7.0]# java -version java version"1.7.0" Java(TM) SERuntime Environment (build 1.7.0-b147) Java HotSpot(TM)Client VM (build 21.0-b17,mixed mode) ng:1.0pt;}
2.安装maven
2.1 下载maven
[root@localhostlocal]# wget http://mirrors.cnnic.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
2.2 解压maven
[root@localhostlocal]# tar -zxvf apache-maven-3.3.9-bin.tar.gz
2.3 配置maven安装路径
MAVEN_HOME=/usr/local/apache-maven-3.3.9 export MAVEN_HOME export PATH=${PATH}:${MAVEN_HOME}/bin
让修改生效
[root@localhost local]# source /etc/profile
2.4 验证安装结果
[root@localhost local]# mvn -v Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T08:41:47-08:00) Maven home: /usr/local/apache-maven-3.3.9 Java version: 1.7.0,vendor: Oracle Corporation Java home: /usr/local/jdk1.7.0/jre Default locale: en_US,platform encoding: UTF-8 OS name: "linux",version: "2.6.32-431.el6.i686",arch: "i386",family: "unix"
3.安装Jenkins
3.1 下载jenkins
http://ftp.yz.yamagata-u.ac.jp/pub/misc/jenkins/redhat/jenkins-1.638-1.1.noarch.rpm
将安装包拷贝到目录/usr/local
3.2.安装jenkins
[root@localhost local]# rpm -ivh jenkins-1.638-1.1.noarch.rpmjenkins的安装目录是 /usr/lib/jenkins,里面有个WAR包 jenkins.war
添加下面一行
/usr/local/jdk1.7.0/bin/java
[root@localhost jenkins]# vi /etc/sysconfig/jenkins 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 /usr/local/jdk1.7.0/bin/java"
3.4 启动jenkins
[root@localhostjenkins]# service jenkins start StartingJenkins [ OK ]3.5 开放端口8080
jenkins的默认端口号是8080,防火墙要开放这个端口,外部才能访问。
添加下面一行
A INPUT -mstate --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
[root@localhostjenkins]# vi /etc/sysconfig/iptables # Firewallconfiguration written by system-config-firewall # Manualcustomization of this file is not recommended. *filter :INPUT ACCEPT[0:0] :FORWARD ACCEPT[0:0] :OUTPUT ACCEPT[0:0] -A INPUT -mstate --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp-j ACCEPT -A INPUT -i lo-j ACCEPT -A INPUT -mstate --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -mstate --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -mstate --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT3.6 重启防火墙
[root@localhostjenkins]# service iptables restart iptables:Setting chains to policy ACCEPT: filter [ OK ] iptables:Flushing firewall rules: [ OK ] iptables:Unloading modules: [ OK ] iptables:Applying firewall rules: [ OK ]
3.7 浏览器访问jenkins
http://192.168.1.1:8080
用户名是:admin
密码:2929ee78adaf4a72a5bbfcd56130a8bd
密码保存在文件:/var/lib/jenkins/secrets/initialAdminPassword
</pre><pre name="code" class="java"><pre code_snippet_id="1876506" snippet_file_name="blog_20160911_10_8522264" name="code" class="java">[root@localhostjenkins]<span style="font-family: Arial,Helvetica,sans-serif;"># more /var/lib/jenkins/secrets/initialAdminPassword</span>2929ee78adaf4a72a5bbfcd56130a8bd
3.8 配置jenkins参数
查看运行日志
[root@localhost jenkins]# more /var/log/jenkins/jenkins.log
1) 配置jdk参数
2)配置maven参数
1)配置subversion参数
输入用户名和密码
2)配置maven
再选择一个安装好的Maven版本,输入Maven命令如clean install -Pdev_profile就可以了,其中-P参数后台跟着的是MAVEN Profile的名称,在通常情况下,Maven本地、开发环境、测试环境、生产环境都有不同的参数,通常会给每个环境都配一个配置文件,在Maven打包时,就通过参数-P来区分是要打哪个环境的安装包。
比如:clean install -Pdev_profile 打的是开发环境的安装包
clean install -Ptest_profile 打的是测试环境的安装包
clean install -Pprod_profile 打的是生产环境的安装包
3)配置shell脚本
输入以下shell脚本
SERVER=192.168.1.2 ssh root@$SERVER "ps -ef | grep usr/local/apache-tomcat | grep -v ' grep ' | awk '{print \$2}' | xargs kill -9" ssh root@$SERVER "cd /usr" ssh root@$SERVER "rm -rf /usr/local/apache-tomcat-7.0.67/webapps/test" ssh root@$SERVER "rm /usr/local/apache-tomcat-7.0.67/webapps/test.war" ssh root@$SERVER "sh /usr/local/apache-tomcat-7.0.67/bin/startup.sh" ssh root@$SERVER "sleep 1m"4)安装TOMCAT插件
[root@161-manage ~]# vi /etc/passwd jenkins:x:496:491:Jenkins Continuous Integration Server:/var/lib/jenkins:/bin/false/bin/false改成/bin/bash
安装jenkins时,会默认给系统添加一个用户jenkins,将用户jenkins设置成允许执行脚本,这样用户jenkins就可以免密登陆了.
2) 服务器ServerA生成密钥
ServerA进入用户jenkins的目录
[root@localhost jenkins]# su - jenkins -bash-4.1$ pwd /var/lib/jenkinsServerA上执行命令:
-bash-4.1$ ssh-keygen -t rsa生成的密钥在目录下
/var/lib/jenkins/.ssh/
包含三个文件
authorized_keys、id_rsa、id_rsa.pub
将密钥文件id_rsa.pub从ServerA拷贝到ServerB中的temp中
-bash-4.1$ cd /var/lib/jenkins/.ssh/ -bash-4.1$ scp ./id_rsa.pub root@192.168.1.2:/root/.ssh/temp3) 拷贝证书到ServerB
注意:密钥要使用命令导入文件,造成不要使用手动拷贝插入。
将ServerB中的文件/root/.ssh/temp中的密钥加入文件/root/.ssh/authorized_keys中
[root@localhost jenkins]# cat temp >> authorized_keys4) ServerA验证ssh 免登陆 ServerA中执行命令ssh 192.168.1.2 其中192.168.1.2是ServerB的IP地址,如果能免登陆就进入ServerB,说明ssh免登陆设置成功。 这样就可以构建jenkins项目了,一键打包和部署。 原文链接:https://www.f2er.com/centos/380765.html