安裝、啓動並配置jenkins服務java
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt-get update sudo apt-get install jenkins
systemctl status jenkins.service
● jenkins.service - LSB: Start Jenkins at boot time
Loaded: loaded (/etc/init.d/jenkins; bad; vendor preset: enabled)
Active: failed (Result: exit-code) since 一 2017-09-18 20:02:02 CST; 5min agowebDocs: man:systemd-sysv-generator(8)9月 18 20:02:02 DH9K45ER2 systemd[1]: Starting LSB: Start Jenkins at boot time...
9月 18 20:02:02 DH9K45ER2 jenkins[4785]: ERROR: No Java executable found in current PATH: /bin:/usr/bin:/sbin:/usr/sbin
9月 18 20:02:02 DH9K45ER2 jenkins[4785]: If you actually have java installed on the system make sure the executable is in the aforementioned path and that 't
9月 18 20:02:02 DH9K45ER2 systemd[1]: jenkins.service: Control process exited, code=exited status=1
9月 18 20:02:02 DH9K45ER2 systemd[1]: Failed to start LSB: Start Jenkins at boot time.
9月 18 20:02:02 DH9K45ER2 systemd[1]: jenkins.service: Unit entered failed state.
9月 18 20:02:02 DH9K45ER2 systemd[1]: jenkins.service: Failed with result 'exit-code'.shell
cat /etc/services | grep 8080
http-alt 8080/tcp webcache # WWW caching service
http-alt 8080/udp
從日誌看出Jenkins在默認狀況下從8080端口啓動。在這個系統端口中,8080已經在使用中了。因此在/etc/default/jenkins.修改Jenkins默認端口設置tcp
修改/etc/default/目錄下面的jenkins
文件,將如下內容ui
# port for HTTP connector (default 8080; disable with -1)
HTTP_PORT=8080
修改成:
# port for HTTP connector (default 8080; disable with -1)
HTTP_PORT=8089
啓動中止Jenkinsspa
sudo service jenkins start sudo service jenkins stop
訪問路徑:http://localhost:8089插件
其餘說明日誌
/var/lib/jenkins
/var/log/jenkins/jenkins.log
2、Jenkins初始化配置
1)解鎖Jenkinscode
這裏須要/var/lib/jenkins/secrets/initialAdminPassword的密碼解鎖Jenkins
而後把密碼複製進去。
說明:按照彈框提示,找到該initialAdminPassword文件,我這裏使用Docker啓動Jenkins,而且把jenkins_home目錄掛載到我磁盤指定目錄,因此這裏我只須要複製/Users/wanyang3/jenkins_home/initialAdminPassword便可,若是非掛載方式Docker啓動,則須要進入容器內根據提示路徑找到該文件。xml
2)定製 Jenkins
說明:這裏若選擇Install suggested plugins安裝,那麼jenkins就會給你推薦安裝一些頗有用的插件,若選擇Select plugins to install安裝,那麼就須要本身根據業務須要選擇性安裝某些插件。
3)建立第一個管理員用戶
說明:這裏建立第一個管理員用戶,也能夠不設置,直接點擊「Continue as admin」,進入jenkins之後再設置。
新建Pipeline Job Demo
1)建立一個pipeline job
/var/lib/jenkins/config.xml
<useSecurity>true</useSecurity>
<authorizationStrategy class="hudson.security.GlobalMatrixAuthorizationSt
rategy">
<permission>hudson.model.Computer.Configure:admin</permission> <permission>hudson.model.Computer.Connect:admin</permission> <permission>hudson.model.Computer.Create:admin</permission> <permission>hudson.model.Computer.Delete:admin</permission> <permission>hudson.model.Computer.Disconnect:admin</permission> <permission>hudson.model.Hudson.Administer:admin</permission> <permission>hudson.model.Hudson.Read:admin</permission> <permission>hudson.model.Hudson.Read:anonymous</permission> <permission>hudson.model.Hudson.RunScripts:admin</permission> <permission>hudson.model.Item.Build:admin</permission> <permission>hudson.model.Item.Cancel:admin</permission> <permission>hudson.model.Item.Configure:admin</permission> <permission>hudson.model.Item.Create:admin</permission> <permission>hudson.model.Item.Delete:admin</permission> <permission>hudson.model.Item.Discover:admin</permission> <permission>hudson.model.Item.Read:admin</permission> <permission>hudson.model.Item.Workspace:admin</permission> <permission>hudson.model.Run.Delete:admin</permission> <permission>hudson.model.Run.Update:admin</permission> <permission>hudson.model.View.Configure:admin</permission> <permission>hudson.model.View.Create:admin</permission> <permission>hudson.model.View.Delete:admin</permission> <permission>hudson.model.View.Read:admin</permission> <permission>hudson.scm.SCM.Tag:admin</permission>
</authorizationStrategy>
<securityRealm class="hudson.security.HudsonPrivateSecurityRealm">
<disableSignup>false</disableSignup> <enableCaptcha>false</enableCaptcha>
</securityRealm>
修改用戶密碼
/var/lib/jenkins/users/user/config.xml
<hudson.security.HudsonPrivateSecurityRealm_-Details>
<passwordHash>#jbcrypt:$2a$10$DdaWzN64JgUtLdvxWIflcuQu2fgrrMSAMabF5TSrGK5nXitqK9ZMS</passwordHash>
</hudson.security.HudsonPrivateSecurityRealm_-Details>
注:密碼爲111111