设为首页 收藏本站
查看: 1017|回复: 0

[经验分享] III 25 git-Linux运维重难点学习笔记

[复制链接]

尚未签到

发表于 2018-9-17 08:46:50 | 显示全部楼层 |阅读模式
  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))
DSC0000.jpg

  持续集成、持续部署:
DSC0001.jpg

  git:
  分布式的版本控制系统;
  diff(2002年之前)-->bitkeeper(2002年)-->git(不要逼我);
  集中式;
  分布式(中央服务器用于交换代码);
  https://www.git-scm.com/
  注:不要拿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 "jowinchai@163.com"
  #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 git@github.com:jowinchaitest/demo
  #cat .git/config
  #git pull origin master
  #git push -u origin master   #(若出错,#git push -f;git pull;git push)
  #git clone git@github.com: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  :   #(#mangit-push,用于将本地分支的更新推送到远程主机;若省略远程分支名,表示将本地分支推送与之存在追踪关系的远程分支(通常两者同名),如果该远程分支不存在则会被新建)
  #git pull :
  #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 "jowinchai@163.com"
  [root@test1 ~]# git config --global color.ui true
  [root@test1 ~]# git config --list
  user.name=jowinchai
  user.email=jowinchai@163.com
  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 ..." 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
  # On branch master
  #
  # Initial commit
  #
  # Changes to be committed:
  #  (use "git rm --cached ..." 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
  [root@test1 test]# git status
  # On branch master
  nothing to commit (working directory clean)
  [root@test1 test]# git log
  commit68692dba5bf091ec829ee35c179a2a75948e6477
  Author: jowinchai
  Date:  Tue Nov 22 22:34:32 2016 -0800
  the first commit
  [root@test1 test]# vim readme.txt
  1row test
  2row test2
  3row test3
  [root@test1 test]# git status
  # On branch master
  # Changed but not updated:
  #  (use "git add ..." to update what will becommitted)
  #  (use "git checkout -- ..." 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
  [root@test1 test]# git add readme.txt
  [root@test1 test]# git status
  # On branch master
  # Changes to be committed:
  #   (use"git reset HEAD ..." to unstage)
  #
  #   modified:   readme.txt
  #
  [root@test1 test]# git commit -m "add 3row"
  [master f9b7739] add 3row
  1files changed, 1 insertions(+), 0 deletions(-)
  [root@test1 test]# git status
  # On branch master
  nothing to commit (working directory clean)
  [root@test1 test]# git log
  commitf9b77398c7dbd083dc8e37e63ec1fa0a999a2c62
  Author: jowinchai
  Date:  Tue Nov 22 22:39:50 2016 -0800
  add 3row
  commit68692dba5bf091ec829ee35c179a2a75948e6477
  Author: jowinchai
  Date:  Tue Nov 22 22:34:32 2016 -0800
  the first commit
  [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
  1row test
  2row test2
  [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
  1row test
  2row test2
  3row test3
  在https://github.com/中创建用户-->organization name:jowinchaitest;
  得到https://github.com/jowinchaitest;
  点右上角+,New repository,Repository name:demo,Public,Initialize this repository with a README,Createrepository;
DSC0002.jpg

  点demo-->Settings-->Deploykeys,Title:localhost-vmware-test1,Key:粘贴本地vmware中test1,/root/.ssh/id_rsa.pub中的内容;
DSC0003.jpg

  [root@test1 ~]# cd /ane/test/
  [root@test1 test]# git remote add origin git@github.com:jowinchaitest/demo
  [root@test1 test]# cat .git/config
  [core]
  repositoryformatversion= 0
  filemode= true
  bare= false
  logallrefupdates= true
  [remote "origin"]
  url= git@github.com: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     -> FETCH_HEAD
  Merge made by recursive.
  README.md |   2 ++
  1files changed, 2 insertions(+), 0 deletions(-)
  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 git@github.com:jowinchaitest/demo
  05ffa4e..935f53a  master ->master
  Branch master set up to track remote branchmaster from origin.
DSC0004.jpg

  网页上将有本地test1上/ane/test/的readme.txt了
  [root@test1 test]#git clone git@github.com: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
  * master
  [root@test1 test]# git checkout dev   #(切至dev分支)
  Switched to branch 'dev'
  [root@test1 test]# git branch
  * 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
  1files changed, 2 insertions(+), 0 deletions(-)
  create mode 100644 dev.txt
  [root@test1 test]# git checkout master   #(切至master分支;若要合并两个分支,要先切至master分支上再用#git merge dev合并)
  Switched to branch 'master'
  [root@test1 test]# ll
  total 12
  drwxr-xr-x. 3 root root 4096 Dec  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 merge dev   #(合并master和dev分支)
  Updating 935f53a..1229ea4
  Fast-forward
  dev.txt |   2 ++
  1files changed, 2 insertions(+), 0 deletions(-)
  create mode 100644 dev.txt
  [root@test1 test]# ll
  total 16
  drwxr-xr-x. 3 root root 4096 Dec  7 02:12 demo
  -rw-r--r--. 1 root root   16 Dec 9 22:35 dev.txt
  -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
  dev
  * master
  [root@test1 test]# git branch -d dev   #(删除一个分支)
  Deleted branch dev (was 1229ea4).
  [root@test1 test]# git branch
  * master
  模拟冲突conflict:
  [root@test1 test]# ll
  total 12
  drwxr-xr-x. 3 root root 4096 Dec  7 02:12 demo
  -rw-r--r--. 1 root root   17 Dec 7 02:08 README.md
  -rw-r--r--. 1 root root   87 Dec10 00:05 readme.txt
  [root@test1 test]# pwd
  /ane/test
  [root@test1 test]# git branch
  * master
  [root@test1 test]# git checkout -b dev   #(创建并切至dev分支)
  Switched to a new branch 'dev'
  [root@test1 test]# git branch
  * dev
  master
  [root@test1 test]# vim readme.txt
  1row test
  2row test2
  3row test3
  4row test4
  [root@test1 test]# git add readme.txt
  [root@test1 test]# git commit -m "devchange"
  [dev 1a96c6c] dev change
  1files changed, 1 insertions(+), 0 deletions(-)
  [root@test1 test]# git checkout master
  Switched to branch 'master'
  Your branch is ahead of 'origin/master' by2 commits.
  [root@test1 test]# vim readme.txt
  1row test
  2row test2
  3row test3
  5row test5
  [root@test1 test]# git add readme.txt
  [root@test1 test]# git commit -m "master change"
  [master 13b119c] master change
  1files changed, 1 insertions(+), 0 deletions(-)
  [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]# git branch
  dev
  * master
  [root@test1 test]# cat readme.txt   #(直接查看提示的有问题的文件可获取哪些地方有问题)
  1row test
  2row test2
  3row test3
  > dev
  [root@test1 test]# git status   #(使用#git status可获取冲突原因)
  # On branch master
  # Your branch is ahead of 'origin/master'by 3 commits.
  #
  # Unmerged paths:
  #  (use "git add/rm ..." as appropriate to markresolution)
  #
  #   bothmodified:      readme.txt
  #
  no changes added to commit (use "gitadd" and/or "git commit -a")
  解决冲突:
  [root@test1 test]# vim readme.txt   #(手动编辑好,add到缓存区,再commit,最后合并两分支)
  1row test
  2row test2
  3row test3
  4row test4
  5row test5
  [root@test1 test]# git add readme.txt
  [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]# cat readme.txt
  1row test
  2row test2
  3row test3
  4row test4
  5row test5
  [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.
  To git@github.com:jowinchaitest/demo
  6e62669..66c9414  master ->master
  打标签:
  [root@test1 test]# git branch   #(打标签前,先确定在哪个分支上)
  * master
  [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)
  To git@github.com:jowinchaitest/demo
  *[new tag]         v1.0 -> v1.0
  可在远程服务器上查看:
DSC0005.jpg

  [root@test1 test]# git show v1.0
  commit66c94144338e45677db687ced4b2c2a6052a6118
  Merge: 13b119c 1a96c6c
  Author: jowinchai
  Date:  Sat Dec 10 00:15:57 2016 -0800
  conflict fixed
  diff --cc readme.txt
  index 73198d5,d70b440..d8e3e4e
  --- a/readme.txt
  +++ b/readme.txt
  @@@ -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
  引用:
  例:
  > war,this is a reference
  [unixhot](http://www.unixhot.com)   #(链接,网页引用,广告链接)
  ![chaijowin](http://jowin.blog.51cto.com/…….pgn)  #(图片引用,图片广告)
  代码框:
  例1:
  while true:
  do echo nimei;
  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 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.
  To git@github.com:jowinchaitest/demo
  b92b2ea..59f981e  master ->master
  Branch master set up to track remote branchmaster from origin.
  打开网页查看:
DSC0006.jpg

  BitBucket是一家源代码托管网站,采用Mercurial和Git作为分布式版本控制系统,同时提供商业计划和免费账户;
  https://bitbucket.org/
  SonarQube是一个用于代码质量管理的开源平台,用于管理源代码的质量,通过插件形式,可以支持包括:java,C#,C/C++,PL/SQL,Cobol,JavaScrip,Groovy等等二十几种编程语言的代码质量管理与检测;
  Gitlab是一个用Ruby onRails开发的开源项目管理程序,可以通过WEB界面进行访问公开的或者私人项目。它和Github有类似的功能,能够浏览源代码,管理缺陷和注释。
  https://about.gitlab.com/
  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 ~]# curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh  | bash
  [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
DSC0007.jpg

  默认user:root,password:wavel!fe
  注:第一次启动的时候,需要初始化大量的东西,经常会出现502错误,通常是由于内存不足的原因导致,所以需要准备好足够的内存,官方推荐生产环境中使用2G内存,2核CPU,虚拟机中测试1GB内存基本就可以了
  FAQ:
  [root@test1 demo]# git push -u originmaster
  To git@github.com:jowinchaitest/demo
  ![rejected]        master -> master(non-fast-forward)
  error: failed to push some refs to'git@github.com: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
  应用上线:
  获取代码-->编译(可选)-->配置文件-->打包-->copy到对应服务器(对应目录)-->部署节点、移除集群-->解压、copy差异文件-->创建软链接-->重启-->自动化测试-->加入集群-->列出回滚版本-->执行回滚-->删除软链接-->重新创建软链接-->重启(可选)
  [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 && 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 && mv demo pro_demo_"$TAR_VER"
  }
  tar_pro() {
  echo "tar_pro"
  cd $TMP_DIR && 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 && 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() {
  rm -f /var/www/html/demo
  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
  Author: jowinchai
  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


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-588066-1-1.html 上篇帖子: GIT版本管理 下篇帖子: git小技巧:git blame && git show 查看某一行代码的修改历史
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表