標籤:jenkins ansible 持續部署
前提:先安裝tomcat,請參考之前寫的在centos7上安裝tomcat的博文
http://12395331.blog.51cto.com/12385331/1884980
安裝jenkins
1> 下載jenkins包。
進入tomcat/webapps/ 目錄下,下載jenkins.war包到這裡,如下載有問題,可自行下載傳到這個目錄下,部署的過程中半天都下不下來,提供了jenkins的附件
wget http://mirrors.jenkins-ci.org/war/latest/jenkins.war
2> Jekins環境變數設定
[[email protected] bin]# sudo vi /etc/profile export JENKINS_HOME=/data/program/tomcat/webapps/Jenkins [[email protected] bin]# . /etc/profile #使設定檔生效
3> 修改tomcat預設連接埠號碼
vi /usr/local/apache-tomcat/conf/server.xml
修改下面這段的port修改為不是8080的其它連接埠,這裡修改為8081,還有個條件:在之前修改iptables的規則檔案時已經開放了8081的連接埠,如果沒有請重新修改,重啟iptables的服務。
<Connector port="8080" protocol="HTTP/1.1"connectionTimeout="20000" redirectPort="8443" />
4> 重啟tomcat,進入tomcat的安裝目錄下的bin目錄
[[email protected] bin]# ./startup.sh
tomcat會解壓war包,產生一個jenkins檔案夾,而且會在root目錄下產生一個.jenkins的檔案夾
5> Jenkins 驗證。在瀏覽器裡,輸入網址:http://localhost:8081/jenkins
6> 輸入密碼 .首次進入jenkins如要輸入密碼
密碼位置:/root/.jenkins/secrets/initialAdminPassword,找不到這個檔案就find . -name .jenkins
7> 安裝需要的外掛程式
第一次進入,會出現預設外掛程式安裝不成功,進入外掛程式管理列表也為空白,點擊advanced下面的CheckNow,即可輸出available的列表,多試幾次。除了基礎安裝的外掛程式外,主要安裝的外掛程式有:git, git Client, gitlab hook等
安裝ansible
前提:要安裝ansible系統中必須要安裝python的版本在2.7及以上。
1> Ansible是屬於Extra Packages for Enterprise Linux (EPEL)庫的一部分,因此要先安裝EPEL
[[email protected] ~]# yum install epel-release
2> 直接安裝ansible,目前預設安裝的版本是2.2,官方持續在更新
[[email protected] ~]# yum install ansible
3> 為支援windows client,要安裝以下的包:安裝Python Winrm模組
pip install “pywinrm>=0.1.1”
4> 底層通訊基於PowerShell,管理機和遠程主機基於Kerbero認證,需額外安裝python-kerbero和MIT krb5依賴庫。
步驟1、 安裝python-kerberos依賴,命令如下:
yum -y install python-devel krb5-devel krb5-libs krb5-workstation
步驟2 、安裝python-kerberos,OSX和Linux發行版均預設安裝,安裝命令如下:
pip install Kerberos
遇到的問題及解決辦法:
1. 連接埠衝突,tomcat的連接埠改成8081. 8080連接埠是jenkins內建的內部連接埠,這也是上面步驟中改8081的目的。
2. tomcat service啟動之後,頁面載入不正常。解決辦法:systemctl start tomcat.service 啟動不行。進入到/usr/local/tomcat/bin,./startup.sh這樣啟動tomcat就可以解決。
本文出自 “ntting” 部落格,請務必保留此出處http://ntting.blog.51cto.com/12385331/1885015
centos7上搭建jenkins+ansible的server