天天看點

III 25 git

自動化運維:

網絡層(接入層、彙聚層、核心層);

LB+HA(L4、L7);

服務層(reverse proxy cache、應用層、web層、SOA層、分布式層、DAL);

資料層(分布式緩存、NoSQL、DB);

系統層(環境初始化)

基礎設施(IDC托管、裝置上下架);

自動化實作:

網絡層(SDN,softwaredefinition network);

LB+HA(平台開發、IaaS);

服務層(PaaS or docker(自動化排程、自動化開發、自動化發現(服務發現、服務注冊));reverse proxy cache(第三方平台開發);應用層(自定義開發);web層、SOA層、分布式層、DAL(saltstack,saltcloud,有docker子產品、消息));

資料層(DAL);

基礎裝置、系統層(IaaS,openstack);

安全:

網絡層(firewall);

LB+HA、服務層(WAF,web application firewall)

資料層(如DB權限);

系統層(tcp wrapper);

基礎設施(實體安全);

備份:

網絡層(HSRP、VRRP);

LB+HA(VRRP);

資料層(DB備份);

服務層中的web層(saltstack);

核心層(網關裝置(outside、inside)、防火牆、router);

彙聚層(三層交換;動态路由、靜态路由、EC、端口彙聚);

接入層(二層交換;VTP、SPF、trunk、port安全);

L4(LVS、F5's BigIP、Citrix's Netscaler、A10);

L7(haproxy、nginx);

DAL、專業團隊做(taobao'sTDDL、360);

分布式層(分布式存儲(glusterfs、moosefs、fastDFS);分布式MQ(rabbitMQ、QPID、zeroMQ));

SOA層、服務化(應用服務層duddo、基于restfull api開發);

web層(httpd、nginx、tomcat、jboss、resin);

應用層、應用變更ittle(php、java、python、C、C++);

reverse proxy cache(ATS、squid、varnish;CDN(配置同步;流量統計;預緩存;緩存更新;日志分析;智能DNS));

DB(MySQL、Oracle、postgre SQL、SQLserver、access);

NoSQL(mongodb、redis、couchbase、elasticsearch);

分布式緩存(memcached、redis);

環境初始化(性能優化;監控agent;自動化管理saltstack minion;内部DNS;limit(例如tcp wrapper限制僅跳闆機ssh到server);

裝置上下架(網絡配置;标簽;自檢(配貨單與實物對比);raid;iDrac|ILO|IMM;OS安裝;資産錄入(分層設計)——合同管理(采購方-采購時間-采購人-聯系資訊)——保修時間——地點——配置詳情——MDB配置項(OS類型-IPv4,RIP,VIP,IPMI,hostname)——服務層面);

IDC托管(熟悉各大IDC廠商;根據業務類型選擇;網絡測試;談價格、走合同;裝置采購(需求分析、采購、上下架));

運維标準化(版本、路徑、服務、OS……);

運維邊界:

運維邊界模糊化(掌握盡可能多的知識點);

運維開發(後端>前端,重點在後端);

自動化運維發展階段:

标準化、工具化(标準化運維;運維标準化、操作工具化、變更流程化);

web化、平台化(web化運維;操作web化、權限控制、弱化流程、統計分析、統一排程);

服務化、api化(DNS服務、LB服務、監控服務、分布式緩存服務、分布式存儲服務、CMDB);

智能化;

伺服器生命周期:

伺服器上架-->網絡配置-->raid配置-->IPMI

伺服器上架-->環境部署-->運維變更-->(服務更新-->代碼更新-->服務擴容&縮容);(服務下線,伺服器下線)

環境部署(OS安裝(cobbler);服務部署(saltstack);應用代碼部署(saltstack&shell);監控配置(zabbix);加入運作叢集(LVS&haproxy))

<a href="http://s2.51cto.com/wyfs02/M02/8B/BD/wKiom1hXPU3SeFcAAABhjONHAs0059.jpg" target="_blank"></a>

持續內建、持續部署:

<a href="http://s2.51cto.com/wyfs02/M01/8B/BD/wKiom1hXPVmBCc4eAABQ0dKs5q0922.jpg" target="_blank"></a>

git:

分布式的版本控制系統;

diff(2002年之前)--&gt;bitkeeper(2002年)--&gt;git(不要逼我);

集中式;

分布式(中央伺服器用于交換代碼);

<a href="https://www.git-scm.com/" target="_blank">https://www.git-scm.com/</a>

注:不要拿git與svn相對比,git隻能管理文本檔案,不能管理picture;

https://github.com/jowinchaitest,github源碼托管,開源項目,代碼管理,控制工具;

[root@test1 ~]# yum -y install git

[root@test1 ~]# git --help

usage: git [--version][--exec-path[=GIT_EXEC_PATH]] [--html-path]

          [-p|--paginate|--no-pager] [--no-replace-objects]

          [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]

          [--help] COMMAND [ARGS]

The most commonly used git commands are:

  add        Add file contents tothe index

  bisect     Find by binary searchthe change that introduced a bug

  branch     List, create, or deletebranches

   checkout   Checkout abranch or paths to the working tree

   clone      Clone a repository into a new directory

  commit     Record changes to therepository

  diff       Show changes betweencommits, commit and working tree, etc

  fetch      Download objects andrefs from another repository

  grep       Print lines matching apattern

  init       Create an empty gitrepository or reinitialize an existing one

  log        Show commit logs

   merge      Join two ormore development histories together

  mv         Move or rename a file,a directory, or a symlink

   pull       Fetch fromand merge with another repository or a local branch

  push       Update remote refsalong with associated objects

  rebase     Forward-port local commits to the updatedupstream head

  reset      Reset current HEAD tothe specified state

  rm         Remove files from theworking tree and from the index

  show       Show various types ofobjects

  status     Show the working treestatus

   tag        Create,list, delete or verify a tag object signed with GPG

常用指令:

#git config --list

#git config --global user.name "jowin.chai"

#git config --global user.email "[email protected]"

#git config --global color.ui true

#git init

#git add readme.txt

#git commit -m "modified by jowin.20161123"

#git status

#git log

#git diff readme.txt

#git reflog   #(Manage reflog information.)

#git reset --hard HEAD^   #(一個^表示回退到上一個版本,兩個^表示回退到前兩個版本,三個^表示回退到前三個版本)

#git reset --hard STRING   #(Resetcurrent HEAD to the specified state.回退到#git reflog查詢出的指定的版本)

#git remote add origin [email protected]:jowinchaitest/demo

#cat .git/config

#git pull origin master

#git push -u origin master   #(若出錯,#git push -f;git pull;git push)

#git clone [email protected]:jowinchaitest/demo

#git branch

#git branch dev

#git checkout dev   #(#gitcheckout -b dev,建立并切至dev分支)

#git checkout master

#git merge dev

#git branch -d dev

#git log --graph

#git log --graph --pretty=oneline --abbrev-commit   #(This is a shorthand for "--pretty=oneline --abbrev-commit" used together.)

#git tag v1.0

#git push origin v1.0

#git show v1.0

注:

#git push &lt;REMOTE_HOST&gt; &lt;LOCAL_BRANCH&gt;:&lt;REMOTE_BRANCH&gt;   #(#mangit-push,用于将本地分支的更新推送到遠端主機;若省略遠端分支名,表示将本地分支推送與之存在追蹤關系的遠端分支(通常兩者同名),如果該遠端分支不存在則會被建立)

#git pull &lt;REMOTE_BRANCH&gt;:&lt;LOCAL_BRANCH&gt;

#git push origin master   #(将本地的master分支推送到origin主機的master分支,如果後者不存在則會被建立,如果省略本地分支名表示删除指定的遠端分支,這等同于推送一個空的本地分支到遠端分支)

#git push origin :master

等同于

#git push origin --delete master   #(删除origin主機的master分支)

#git push origin   #(将目前分支推送到origin主機的對應分支;如果目前分支與遠端分支存在追蹤關系,則本地分支和遠端分支都可省略)

#git push  #(如果目前分支隻有一個追蹤分支,那主機名都可省略)

#git push -u origin master   #(将本地的master分支推送到origin主機,同時指定origin為預設主機,之後可不加任何參數使用#git push了;如果目前分支與多個主機存在追蹤關系,可使用-u指定一個預設主機,這樣後面可不加任何參數使用#git push)

不帶任何參數的#git push預設隻推送目前分支,這叫simple方式,此外還有一種matching方式,會推送所有有對應分支的本地分支,git2.0版本之前,預設采用matching方式,現在改為預設使用simple方式,如果要修改這個設定,可采用#git config --globalpush.default matching;

還有一種情況,不管是否存在對應的遠端分支,将本地的所有分支都推送到遠端主機,要使用--all;

如果遠端主機的版本比本地版本更新,推送時會報錯,要求先在本地做git pull合并差異,然後再推送到遠端主機,這時如果一定要往遠端主機推送可使用--force;

#git config --global push.default matching

#git config --global push.default simple

#git push --all origin   #(将所有本地分支都推送到origin主機)

#git push --force origin   #(使用--force會導緻遠端主機産生一個非直進式(non-fast-forward merge)的合并,除非很确定要這樣做,否則應盡量避免使用--force)

#git push origin --tags   #(push所有标簽)

#git push origin v1.0   #(push單個标簽)

[root@test1 ~]# git --version

git version 1.7.1

[root@test1 ~]# git config --global user.name "jowinchai"   #(配置目前使用者資訊,某個開發在送出代碼後,以辨識是誰送出的代碼(誰在幹活))

[root@test1 ~]# git config --global user.email "[email protected]"

[root@test1 ~]# git config --global color.ui true

[root@test1 ~]# git config --list

user.name=jowinchai

[email protected]

color.ui=true

[root@test1 ~]# mkdir -pv /ane/test

mkdir: created directory `/ane'

mkdir: created directory `/ane/test'

[root@test1 ~]# cd !$

cd /ane/test

[root@test1 test]# git init

Initialized empty Git repository in/ane/test/.git/

[root@test1 test]# vim readme.txt

1row test

2row test2

[root@test1 test]# git status

# On branch master

#

# Initial commit

# Untracked files:

#  (use "git add &lt;file&gt;..." to include in what will becommitted)

#   readme.txt

nothing added to commit but untracked filespresent (use "git add" to track)

[root@test1 test]# git add readme.txt

[root@test1 test]# git status

# Changes to be committed:

#  (use "git rm --cached &lt;file&gt;..." to unstage)

#   newfile:   readme.txt

[root@test1 test]# git commit -m "the first commit"

[master (root-commit) 68692db] the firstcommit

 1files changed, 2 insertions(+), 0 deletions(-)

 create mode 100644 readme.txt

nothing to commit (working directory clean)

[root@test1 test]# git log

commit68692dba5bf091ec829ee35c179a2a75948e6477

Author: jowinchai &lt;[email protected]&gt;

Date:  Tue Nov 22 22:34:32 2016 -0800

   the first commit

3row test3

# Changed but not updated:

#  (use "git add &lt;file&gt;..." to update what will becommitted)

#  (use "git checkout -- &lt;file&gt;..." to discard changes inworking directory)

#   modified:   readme.txt

no changes added to commit (use "gitadd" and/or "git commit -a")

[root@test1 test]# git diff readme.txt

diff --git a/readme.txt b/readme.txt

index 696014d..da593d5 100644

--- a/readme.txt

+++ b/readme.txt

@@ -1,2 +1,3 @@

 1rowtest

 2rowtest2

+3row test3

#   (use"git reset HEAD &lt;file&gt;..." to unstage)

[root@test1 test]# git commit -m "add 3row"

[master f9b7739] add 3row

 1files changed, 1 insertions(+), 0 deletions(-)

commitf9b77398c7dbd083dc8e37e63ec1fa0a999a2c62

Date:  Tue Nov 22 22:39:50 2016 -0800

   add 3row

[root@test1 test]# git reflog  

f9b7739 HEAD@{0}: commit: add 3row

68692db HEAD@{1}: commit (initial): thefirst commit

[root@test1 test]# git reset --hard HEAD^

HEAD is now at 68692db the first commit

[root@test1 test]# cat readme.txt

[root@test1 test]# git reflog

68692db HEAD@{0}: HEAD^: updating HEAD

f9b7739 HEAD@{1}: commit: add 3row

[root@test1 test]# git reset --hard f9b7739

HEAD is now at f9b7739 add 3row

[root@test1 test]# cat readme.txt

在https://github.com/中建立使用者--&gt;organization name:jowinchaitest;

點右上角+,New repository,Repository name:demo,Public,Initialize this repository with a README,Createrepository;

<a href="http://s3.51cto.com/wyfs02/M01/8B/B9/wKioL1hXPfriMjHSAABDy4vLwsw410.jpg" target="_blank"></a>

點demo--&gt;Settings--&gt;Deploykeys,Title:localhost-vmware-test1,Key:粘貼本地vmware中test1,/root/.ssh/id_rsa.pub中的内容;

<a href="http://s4.51cto.com/wyfs02/M01/8B/BD/wKiom1hXPgvgqDq5AABHvIw5IXQ028.jpg" target="_blank"></a>

[root@test1 ~]# cd /ane/test/

[root@test1 test]# git remote add origin [email protected]:jowinchaitest/demo

[root@test1 test]# cat .git/config

[core]

    repositoryformatversion= 0

    filemode= true

    bare= false

    logallrefupdates= true

[remote "origin"]

    url= [email protected]:jowinchaitest/demo

    fetch= +refs/heads/*:refs/remotes/origin/*

[root@test1 test]# git pull origin master

The authenticity of host 'github.com(192.30.253.113)' can't be established.

RSA key fingerprint is16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.

Are you sure you want to continueconnecting (yes/no)? yes

Warning: Permanently added'github.com,192.30.253.113' (RSA) to the list of known hosts.

warning: no common commits

remote: Counting objects: 3, done.

remote: Total 3 (delta 0), reused 0 (delta0), pack-reused 0

Unpacking objects: 100% (3/3), done.

From github.com:jowinchaitest/demo

 *branch            master     -&gt; FETCH_HEAD

Merge made by recursive.

 README.md |   2 ++

 create mode 100644 README.md

[root@test1 test]# git push -u origin master

Counting objects: 9, done.

Compressing objects: 100% (4/4), done.

Writing objects: 100% (8/8), 726 bytes,done.

Total 8 (delta 0), reused 0 (delta 0)

To [email protected]:jowinchaitest/demo

  05ffa4e..935f53a  master -&gt;master

Branch master set up to track remote branchmaster from origin.

<a href="http://s3.51cto.com/wyfs02/M02/8B/B9/wKioL1hXPimjZ5siAABkFpmCoKY771.jpg" target="_blank"></a>

網頁上将有本地test1上/ane/test/的readme.txt了

[root@test1 test]#git clone [email protected]:jowinchaitest/demo

Initialized empty Git repository in/ane/test/demo/.git/

Warning: Permanently added the RSA host keyfor IP address '192.30.253.112' to the list of known hosts.

remote: Counting objects: 11, done.

remote: Compressing objects: 100% (5/5),done.

remote: Total 11 (delta 0), reused 8 (delta0), pack-reused 0

Receiving objects: 100% (11/11), done.

[root@test1 test]# ll

total 12

drwxr-xr-x. 3 root root 4096Dec  7 02:12 demo

-rw-r--r--. 1 root root   17 Dec 7 02:08 README.md

-rw-r--r--. 1 root root   32 Nov 22 22:51 readme.txt

建立分支:

[root@test1 test]# git branch   #(檢視目前分支,綠色并用*号開頭表示目前所在分支)

* master

[root@test1 test]# git branch dev   #(建立dev分支;也可用#gitcheckout -b dev建立并切至dev分支)

[root@test1 test]# git branch

  dev

[root@test1 test]# git checkout dev   #(切至dev分支)

Switched to branch 'dev'

* dev

 master

[root@test1 test]# vim dev.txt

1st he

2st hehe

[root@test1 test]# git add dev.txt

[root@test1 test]# git commit -m "adddev.txt"

[dev 1229ea4] add dev.txt

 create mode 100644 dev.txt

[root@test1 test]# git checkout master   #(切至master分支;若要合并兩個分支,要先切至master分支上再用#git merge dev合并)

Switched to branch 'master'

drwxr-xr-x. 3 root root 4096 Dec  7 02:12 demo

[root@test1 test]# git merge dev   #(合并master和dev分支)

Updating 935f53a..1229ea4

Fast-forward

 dev.txt |   2 ++

total 16

-rw-r--r--. 1 root root   16 Dec 9 22:35 dev.txt

[root@test1 test]# git branch -d dev   #(删除一個分支)

Deleted branch dev (was 1229ea4).

模拟沖突conflict:

-rw-r--r--. 1 root root   87 Dec10 00:05 readme.txt

[root@test1 test]# pwd

/ane/test

[root@test1 test]# git checkout -b dev   #(建立并切至dev分支)

Switched to a new branch 'dev'

4row test4

[root@test1 test]# git add readme.txt

[root@test1 test]# git commit -m "devchange"

[dev 1a96c6c] dev change

[root@test1 test]# git checkout master

Your branch is ahead of 'origin/master' by2 commits.

5row test5

[root@test1 test]# git commit -m "master change"

[master 13b119c] master change

[root@test1 test]# git merge dev   #(無法合并,提示有沖突)

Auto-merging readme.txt

CONFLICT (content): Mergeconflict in readme.txt

Automatic merge failed; fixconflicts and then commit the result.

[root@test1 test]# cat readme.txt   #(直接檢視提示的有問題的檔案可擷取哪些地方有問題)

&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD

=======

&gt;&gt;&gt;&gt;&gt;&gt;&gt; dev

[root@test1 test]# git status   #(使用#git status可擷取沖突原因)

# Your branch is ahead of 'origin/master'by 3 commits.

# Unmerged paths:

#  (use "git add/rm &lt;file&gt;..." as appropriate to markresolution)

#   bothmodified:      readme.txt

解決沖突:

[root@test1 test]# vim readme.txt   #(手動編輯好,add到緩存區,再commit,最後合并兩分支)

[root@test1 test]# git commit -m "conflict fixed"

[master 66c9414] conflict fixed

[root@test1 test]# git merge dev

Already up-to-date.

[root@test1 test]# git branch -d dev

Deleted branch dev (was 1a96c6c).

[root@test1 test]# git log --graph --pretty=oneline --abbrev-commit   #(使用#git log--graph,可看到分支的詳細情況,This is a shorthand for"--pretty=oneline --abbrev-commit" used together.)

[root@test1 test]# git log --graph

[root@test1 test]# git push origin master   #(将目前分支推送到origin主機的對應分支,如果目前隻有一個追蹤分支主機名可以忽略)

Counting objects: 15, done.

Compressing objects: 100% (10/10), done.

Writing objects: 100% (13/13), 1.14 KiB,done.

Total 13 (delta 4), reused 0 (delta 0)

remote: Resolving deltas: 100% (4/4),completed with 1 local objects.

  6e62669..66c9414  master -&gt;master

打标簽:

[root@test1 test]# git branch   #(打标簽前,先确定在哪個分支上)

[root@test1 test]# git tag v1.0

[root@test1 test]# git push origin v1.0   #(上傳本地目前代碼到master分支;#git push是上傳本地所有代碼到遠端對應的分支上)

Total 0 (delta 0), reused 0 (delta 0)

 *[new tag]         v1.0 -&gt; v1.0

可在遠端伺服器上檢視:

<a href="http://s3.51cto.com/wyfs02/M02/8B/BD/wKiom1hXPwyCKCY3AABXV-S8Qnw074.jpg" target="_blank"></a>

[root@test1 test]# git show v1.0  

commit66c94144338e45677db687ced4b2c2a6052a6118

Merge: 13b119c 1a96c6c

Date:  Sat Dec 10 00:15:57 2016 -0800

   conflict fixed

diff --cc readme.txt

index 73198d5,d70b440..d8e3e4e

@@@ -1,4 -1,4 +1,5 @@@

 1row test

 2row test2

 3row test3

+ 4row test4

 +5row test5

持續內建:

markdown編輯器:

http://markdownpad.com/   #(windows,markdownpad)

http://25.io/mou/   #(mac,mou)

markdown是一種可以使用普通文本編輯器編寫的标記語言,通過簡單的标記文法,它可以使普通文本内容具有一定的格式;Markdown具有一系列衍生版本,用于擴充Markdown的功能(如表格、腳注、内嵌HTML等等),這些功能原初的Markdown尚不具備,它們能讓Markdown轉換成更多的格式,例如LaTeX,Docbook;

markdown增強版中比較有名的有MarkdownExtra、MultiMarkdown、Maruku等,這些衍生版本要麼基于工具,如Pandoc;要麼基于網站,如GitHub和Wikipedia,在文法上基本相容,但在一些文法和渲染效果上有改動;

markdown的文法簡潔明了、學習容易,而且功能比純文字更強,是以有很多人用它寫部落格,世界上最流行的部落格平台WordPress和大型CMS如Joomla、Drupal都能很好的支援Markdown,完全采用Markdown編輯器的部落格平台有Ghost和Typecho;

markdown用于編寫說明文檔,并且以“README.MD”的檔案名儲存在軟體的目錄下面;

除此之外,現在由于我們有了RStudio這樣的神級編輯器,我們還可以快速将Markdown轉化為演講PPT、Word産品文檔、LaTex論文甚至是用非常少量的代碼完成最小可用原型,在資料科學領域,Markdown已經被确立為科學研究規範,極大地推進了動态可重複性研究的曆史程序;

标題:

标題能顯示出文章的結構,markdown中如果一段文字被定義為标題,隻要在這段文字前加#即可,總共支援六級标題,#與其後的文字用空格分隔,如1個#表示一級标題,##、###、####、#####、######,共支援6級标題

清單:

清單分有序清單和無序清單,無序清單用*或-;隻有空格或tab的就是一個空行;

例:

無序清單:

* 1

* 2

* 3

- 1

- 2

- 3

有序清單:

1. 1

2. 2

3. 3

引用:

&gt; war,this is a reference

[unixhot](http://www.unixhot.com)   #(連結,網頁引用,廣告連結)

![chaijowin](http://jowin.blog.51cto.com/…….pgn)  #(圖檔引用,圖檔廣告)

代碼框:

例1:

&lt;TAB&gt;while true:

&lt;TAB&gt;&lt;TAB&gt;do echo nimei;

&lt;TAB&gt;done

例2:

'while true:

    doecho nimei;

done'

例3:

'yum -y install lrzsz' 'echo nimei'

*的使用:

*我變斜了*   #(文字兩邊各1個*,把文字傾斜)

**我變粗了**   #(文字兩邊用2個*,把文字變粗)

***  #(一行中僅有3個*,表示分割線)

[root@test1 ~]# cd /ane/test/demo/

[root@test1 demo]# vim README.md   #(内容為以上舉例的内容)

[root@test1 demo]# git add README.md

[root@test1 demo]# git commit -m 'justmodified'

[master 59f981e] just modified

 1files changed, 4 insertions(+), 0 deletions(-)

[root@test1 demo]# git push -u origin master -f

Counting objects: 5, done.

Compressing objects: 100% (3/3), done.

Writing objects: 100% (3/3), 332 bytes,done.

Total 3 (delta 1), reused 0 (delta 0)

remote: Resolving deltas: 100% (1/1),completed with 1 local objects.

  b92b2ea..59f981e  master -&gt;master

打開網頁檢視:

<a href="http://s2.51cto.com/wyfs02/M02/8B/B9/wKioL1hXPx2i6Yq6AAB4Mbqu5N0860.jpg" target="_blank"></a>

BitBucket是一家源代碼托管網站,采用Mercurial和Git作為分布式版本控制系統,同時提供商業計劃和免費賬戶;

https://bitbucket.org/

SonarQube是一個用于代碼品質管理的開源平台,用于管理源代碼的品質,通過插件形式,可以支援包括:java,C#,C/C++,PL/SQL,Cobol,JavaScrip,Groovy等等二十幾種程式設計語言的代碼品質管理與檢測;

Gitlab是一個用Ruby onRails開發的開源項目管理程式,可以通過WEB界面進行通路公開的或者私人項目。它和Github有類似的功能,能夠浏覽源代碼,管理缺陷和注釋。

<a href="https://about.gitlab.com/" target="_blank">https://about.gitlab.com/</a>

gitlab.org

gitlab-ce-8.14.4-ce.0.el6.x86_64

[root@test4 ~]# yum -y install curl openssh-server openssh-clients postfix cronie

[root@test4 ~]# service postfix start

[root@test4 ~]# /etc/init.d/postfix restart

Shutting down postfix:                                     [  OK  ]

Starting postfix:                                         [  OK  ]

[root@test4 ~]# chkconfig --list postfix

postfix              0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@test4 ~]# service iptables stop   #(#lokkit -s http -sssh)

iptables: Setting chains to policy ACCEPT:filter          [  OK  ]

iptables: Flushing firewall rules:                         [  OK  ]

iptables: Unloading modules:                               [  OK  ]

[root@test4 ~]# yum -y install gitlab-ce   #(ce,community edition)

……

      *.                  *.

     ***                 ***

    *****               *****

   .******             *******

   ********            ********

  ,,,,,,,,,***********,,,,,,,,,

 ,,,,,,,,,,,*********,,,,,,,,,,,

 .,,,,,,,,,,,*******,,,,,,,,,,,,

     ,,,,,,,,,*****,,,,,,,,,.

        ,,,,,,,****,,,,,,

           .,,,***,,,,

                ,*,.

    _______ __  __          __

    /____(_) /_/ /   ____ _/ /_

   // __/ / __/ /   / __ `/ __ \

  //_/ / / /_/ /___/ /_/ / /_/ /

 \____/_/\__/_____/\__,_/_.___/

[root@test4 ~]# gitlab-ctl reconfigure

Running handlers:

Running handlers complete

Chef Client finished, 234/321 resourcesupdated in 13 minutes 01 seconds

gitlab Reconfigured!

[root@test4 ~]# gitlab-ctl status   #(#gitlab-ctl start|stop|restart)

run: gitlab-workhorse: (pid 51686) 3108s;run: log: (pid 51523) 3765s

run: logrotate: (pid 54441) 139s; run: log:(pid 51605) 3742s

run: nginx: (pid 51569) 3758s; run: log:(pid 51568) 3758s

run: postgresql: (pid 51251) 3834s; run:log: (pid 51250) 3834s

run: redis: (pid 51111) 3845s; run: log:(pid 51110) 3845s

run: sidekiq: (pid 51478) 3772s; run: log:(pid 51477) 3772s

run: unicorn: (pid 51422) 3778s; run: log:(pid 51421) 3778s

[root@test4 ~]# gitlab-ctl tail nginx

[root@test4 ~]# netstat -tnulp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name  

tcp       0      0 127.0.0.1:8080              0.0.0.0:*                   LISTEN      51472/unicorn maste

tcp       0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      51569/nginx        

tcp       0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      2876/sshd          

tcp       0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1805/cupsd         

tcp       0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      3085/master        

tcp       0      0 0.0.0.0:8060                0.0.0.0:*                   LISTEN      51569/nginx        

tcp       0      0 :::22                       :::*                        LISTEN      2876/sshd          

tcp       0      0 ::1:631                     :::*                        LISTEN      1805/cupsd         

tcp       0      0 ::1:25                      :::*                        LISTEN     3085/master        

udp       0      0 0.0.0.0:631                 0.0.0.0:*                               1805/cupsd         

udp       0      0 0.0.0.0:68                  0.0.0.0:*                               1810/dhclient  

[root@test4 ~]# gitlab-ctl help

/opt/gitlab/embedded/bin/omnibus-ctl:command (subcommand)

deploy-page

  Putup the deploy page

remove-accounts

 Delete *all* users and groups used by this package

upgrade

  Runmigrations after a package upgrade

General Commands:

 cleanse

   Delete *all* gitlab data, and start from scratch.

 help

   Print this help message.

 reconfigure

   Reconfigure the application.

 show-config

   Show the configuration that would be generated by reconfigure.

 uninstall

   Kill all processes and uninstall the process supervisor (data will bepreserved).

Service Management Commands:

 graceful-kill

   Attempt a graceful stop, then SIGKILL the entire process group.

  hup

   Send the services a HUP.

  int

   Send the services an INT.

  kill

   Send the services a KILL.

 once

   Start the services if they are down. Do not restart them if they stop.

  restart

   Stop the services if they are running, then start them again.

 service-list

   List all the services (enabled services appear with a *.)

  start

   Start services if they are down, and restart them if they stop.

  status

   Show the status of all the services.

  stop

   Stop the services, and do not restart them.

 tail

   Watch the service logs of all enabled services.

  term

   Send the services a TERM.

Database Commands:

 pg-upgrade

   Upgrade the PostgreSQL DB to the latest supported version

 revert-pg-upgrade

   Run this to revert to the previous version of the database

Container Registry Commands:

 registry-garbage-collect

   Run Container Registry garbage collection.

[root@test4 ~]# vim /var/opt/gitlab/nginx/conf/gitlab-http.conf  #(定義網頁監聽的端口)

[root@test4 ~]# cp /opt/gitlab/etc/gitlab.rb.template /opt/gitlab/etc/gitlab.rb

[root@test4 ~]# vim /opt/gitlab/etc/gitlab.rb   #(/etc/gitlab/gitlab.rb此處會将external_url設為http://YOUR_HOSTNAME;可将external_url改為如下,這個位址很重要,上傳的圖檔什麼的,url會以這個為基準,如果位址寫錯,将無法通路到圖檔等這些資源)

external_url 'http://192.168.23.132'

http://192.168.23.132

<a href="http://s5.51cto.com/wyfs02/M02/8B/B9/wKioL1hXP2jDrG3fAAB-6E7V0FQ620.jpg" target="_blank"></a>

預設user:root,password:wavel!fe

注:第一次啟動的時候,需要初始化大量的東西,經常會出現502錯誤,通常是由于記憶體不足的原因導緻,是以需要準備好足夠的記憶體,官方推薦生産環境中使用2G記憶體,2核CPU,虛拟機中測試1GB記憶體基本就可以了

FAQ:

[root@test1 demo]# git push -u originmaster

 ![rejected]        master -&gt; master(non-fast-forward)

error: failed to push some refs to'[email protected]:jowinchaitest/demo'

To prevent you from losing history,non-fast-forward updates were rejected

Merge the remote changes before pushingagain.  See the 'Note about

fast-forwards' section of 'git push --help'for details.

注:當處于master branch預設的remote就是origin,當在master branch使用#git pull時,沒有指定remote和branch,那git就會采用預設的remote(origin)來merge在masterbranch上的所有改變

出現non-fast-forwards原因:git倉庫已有一部分代碼,不允許直接把本地代碼覆寫到遠端主機上,解決:

1、#git push-f   #(強制,以覆寫方式将本地的代碼替代git倉庫中的内容)

2、#git fetch

#git merge

這兩個指令等價于#git pull,最後#gitpush

應用上線:

擷取代碼--&gt;編譯(可選)--&gt;配置檔案--&gt;打包--&gt;copy到對應伺服器(對應目錄)--&gt;部署節點、移除叢集--&gt;解壓、copy差異檔案--&gt;建立軟連結--&gt;重新開機--&gt;自動化測試--&gt;加入叢集--&gt;列出復原版本--&gt;執行復原--&gt;删除軟連結--&gt;重新建立軟連結--&gt;重新開機(可選)

[root@test1 ~]# vim pro-deploy.sh

---------------------script start------------------

#!/bin/bash

DATE=`date "+%Y-%m-%d"`

TIME=`date "+%Y-%m-%d-%H-%M"`

CODE_DIR=/ane/test/demo

CONFIG_DIR=/ane/test/config

TAR_DIR=/ane/tar

TMP_DIR=/ane/tmp

usage() {

    echo$"Usage: $0 [deploy|rollback-list|rollback-pro VERSION]"

}

git_pro() {

    echo "git pull"

    cd $CODE_DIR &amp;&amp; git pull

    API_VERL=`gitshow | grep commit | cut -d' ' -f2`

    API_VER=`echo${API_VERL:0:6}`

    /bin/cp -r $CODE_DIR $TMP_DIR

config_pro() {

    echo "add pro config"

    /bin/cp $CONFIG_DIR/* $TMP_DIR/demo

    TAR_VER=$API_VER-$TIME

    cd $TMP_DIR &amp;&amp; mv demo pro_demo_"$TAR_VER"

tar_pro() {

    echo "tar_pro"

    cd $TMP_DIR &amp;&amp; tar zcf pro_demo_"$TAR_VER".tar.gz pro_demo_"$TAR_VER"

    echo "tar end"

scp_pro() {

    echo "begin scp"

    /bin/cp$TMP_DIR/pro_demo_"$TMP_VER".tar.gz /tmp/

deploy_pro() {

    echo "begin deploy"

    cd /tmp &amp;&amp; tar zxf pro_demo_"$TAR_VER".tar.gz

    rm -f /var/www/html/demo

    ln -s /tmp/pro_demo_"$TAR_VER" /var/www/html/demo

test_pro() {

    echo "test begin"

    echo "test ok"

rollback_list() {

    ls -l /tmp/*.tar.gz

rollback_pro() {

    ln -s /tmp/$1 /var/www/html/demo

main() {

   case $1 in

    deploy)

        git_pro;

        config_pro;

        tar_pro;

        scp_pro;

        deploy_pro;

        test_pro;

    ;;

    rollback-list)

        rollback_list;

    rollback-pro)

        rollback_pro$2;

    *)

        usage;

   esac

main $1 $2

---------------------scriptend-----------------

[root@test1 test]# git show   #(#git show的第一行)

commit0487226e101b59fd4ea1e63ccbe7760cebe240a2

Date:  Wed Dec 14 22:24:09 2016 -0800

[root@test1 test]# git show | grep commit | cut -d' ' -f2

0487226e101b59fd4ea1e63ccbe7760cebe240a2

#./pro-deploy.sh deploy

#./pro-deploy.sh rollback-list

#./pro-deploy.sh rollback-pro

本文轉自 chaijowin 51CTO部落格,原文連結:http://blog.51cto.com/jowin/1883904,如需轉載請自行聯系原作者

繼續閱讀