在usr下建立java目錄,使用命令下載jdk壓縮包。這裏是安裝在/usr/java,或者能夠使用yum安裝到/usr/lib/jvm。java
$ wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u102-b14/jdk-8u102-linux-x64.tar.gz
或者在本地先下載好再使用scp命令上傳linux
$ scp /本地路徑/jdk-8u102-linux-x64.tar.gz 登陸用戶名@服務器ip:/usr/java
解壓完刪除壓縮包瀏覽器
$ tar xvf jdk-8u102-linux-x64.tar.gz
配置環境變量,將如下腳本添加到/etc/profile文件的末尾bash
JAVA_HOME=/usr/java/jdk1.8.0_102 JRE_HOME=/usr/java/jdk1.8.0_102/jre PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib export JAVA_HOME JRE_HOME PATH CLASSPATH
最後reboot重啓,執行java -version,結果顯示已安裝成功服務器
$ java -version java version "1.8.0_102" Java(TM) SE Runtime Environment (build 1.8.0_102-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
添加jenkins庫cookie
$ wget -O /etc/yum.repos.d/jenkins.repo http://jenkins-ci.org/redhat/jenkins.repo $ rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
接下來使用yum命令來安裝oracle
$ yum install jenkins
下載rpm包過程當中報錯jvm
Downloading Packages: http://pkg.jenkins.io/redhat/jenkins-2.16-1.1.noarch.rpm: [Errno 14] PYCURL ERROR 18 - "transfer closed with 66371436 bytes remaining to read" Trying other mirror. Error Downloading Packages: jenkins-2.16-1.1.noarch: failure: jenkins-2.16-1.1.noarch.rpm from jenkins: [Errno 256] No more mirrors to try.
大概就是下載速度太慢關閉了,這裏的解決辦法是屢次執行install直到下完或者仍是到自已機器下載再上傳到rpm所在目錄,下載連接http://pkg.jenkins-ci.org/red...,個人rpm目錄是/var/cache/yum/x86_64/6/jenkins/packages。ui
執行如下命令,能夠看到jenkins已是開機自啓動的系統服務,它在/etc/init.d目錄下生成了jenkins文件code
$ chkconfig --list | grep jenkins
jenkins 0:關閉 1:關閉 2:關閉 3:啓用 4:關閉 5:啓用 6:關閉
jenkins的war包存放在/usr/lib/jenkins目錄下,配置文件jenkins在/etc/sysconfig,我這裏修改端口爲8888
## Type: integer(0:65535) ## Default: 8080 ## ServiceRestart: jenkins # # Port Jenkins is listening on. # Set to -1 to disable # JENKINS_PORT="8888"
能夠看到jenkins的主目錄
## Path: Development/Jenkins ## Description: Jenkins Continuous Integration Server ## Type: string ## Default: "/var/lib/jenkins" ## ServiceRestart: jenkins # # Directory where Jenkins store its configuration and working # files (checkouts, build reports, artifacts, ...). # JENKINS_HOME="/var/lib/jenkins"
jenkins建立job和slave都會在這個目錄下生成數據,如今是空的,數據遷移時能夠將該目錄下的數據拷貝到新機器的同個目錄下。第一次訪問控制檯後會生成初始數據。
啓動jenkins,直接使用系統服務的啓動命令,結果報錯,找不到java
$ service jenkins start Starting Jenkins bash: /usr/bin/java: No such file or directory [FAILED]
找到/etc/init.d/jenkins文件,在變量candidates後面添加一個路徑/usr/java/jdk1.8.0_102/bin/java。
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/java/jdk1.8.0_102/bin/java "
再啓動就成功了
$ service jenkins start Starting Jenkins [ OK ]
最後在瀏覽器訪問jenkins,輸入:jenkins服務器地址:8888
後續寫如何用jenkins實現一鍵自動部署