文章目錄
- 0. 老男孩思想-傳統文化
- 1. 運維人員對網站集群的關注項
- 2. CI、CD
- 3. DevOps
- 4. 環境
- 5. Git
- 5.1 **為什么叫 “Git”?**
- 5.2 Git的核心設計理念
- 5.3 Git工作空間
- 5.4 分支 branch
- 5.5 命令
- 5.5.1 配置git用戶信息
- 5.5.2 初始化git倉庫
- 5.5.3 將文件放入暫存區
- 5.5.4 提交代碼到本地倉庫
- 5.5.5 提交日志與代碼回溯
- 5.5.6 分支命令
- 5.5.7 tag 標簽
- 5.5.8 遠程倉庫地址
- 5.5.9 push 推送
- 6. Gitee 碼云
- 6.1 創建個人項目倉庫
- 6.2 添加密鑰認證
- 6.3 本地配置遠程倉庫并推送代碼
- 7. GitLab 極狐
- 7.1 安裝gitlab
- 7.2 修改配置文件
- 7.3 前端頁面
- 7.3.1 登錄
- 7.3.2 修改語言和更改密碼
- 7.4 創建新項目
- 7.5 添加密鑰認證
- 7.6 推送代碼
- 8. 思維導圖
0. 老男孩思想-傳統文化
一命二運三風水,四積陰德五讀書,
六名七相八敬神,九交貴人十養生
-
一命
指先天命格 -
二運
后天運勢 -
三風水
周圍環境,最好是天地人和諧相生 -
四積陰德
但行好事莫問前程
-
五讀書
活到老學到老
-
六名
個人聲譽與社會名譽。個人聲譽更直接影響發展機遇。
-
七相
相由心生,注意自身體態和外表
-
八敬神
對超自然力量的敬畏之心。非單指宗教崇拜,更包含"舉頭三尺有神明”的慎獨精神,規范個體行為。
-
九交貴人
學習人際關系的智慧。貴人分兩種:主動結識的伯樂型貴人(如歐陽修提攜蘇軾),與自身優秀吸引來的"吸貴體質”。
-
十養生
健康是根本。《黃帝內經》”上醫治未病"思想,強調順應四時、調和陰陽的養生之道,避免”功業成而元氣傷”。
1. 運維人員對網站集群的關注項
- 網站線上環境穩定性、高可用、備份(備份、高可用、容災)
- 可觀測性(日志(log)、監控項(monitors)、鏈路追蹤(trace))
- 自動化管理與維護(Shell、Ansible、Terraform)
- 安全(漏洞)
- 應急響應(故障、安全問題)
- 代碼發布策略
2. CI、CD
- 持續集成(CI):開發的代碼集成到代碼倉庫
- 持續交付(CD):從代碼倉庫拉取代碼部署到測試環境
- 持續部署(CD):從代碼倉庫拉取代碼部署到生產環境
3. DevOps
DevOps(開發運維一體化)是一種結合軟件開發(Dev)和IT運維(Ops)的實踐方法,旨在通過自動化、協作和持續改進,加速軟件交付并提升系統穩定性。
- dev:開發,develop
- sec:安全,secure
- ops:運維,Operations
- DevOps,使開發的代碼快速看到結果
4. 環境
5. Git
Git 是目前全球最流行的分布式版本控制系統
- 官網:
[Git](https://git-scm.com/)
5.1 為什么叫 “Git”?
- Git 在英語俚語中有“飯桶”“蠢貨”的意思(Linus 自嘲式命名)。
- 另一種解釋是 “Global Information Tracker”(全局信息追蹤器),但 Linus 本人后來開玩笑說:“我只是隨便取了個名字。”
5.2 Git的核心設計理念
- 分布式架構 – 每個開發者都有完整倉庫,不依賴中央服務器
- 高性能 – 快速提交、分支切換(相比 SVN/CVS)
- 數據完整性 – 使用 SHA-1 哈希確保代碼不可篡改
- 非線性開發 – 強大的分支合并能力
5.3 Git工作空間
5.4 分支 branch
Git 分支是 Git 版本控制的核心功能之一,它允許開發者在同一個代碼庫中并行開發多個功能或修復不同的問題,而不會互相干擾。
- 常見分支
main
/master
:穩定版本分支,直接部署生產環境。dev
:集成開發分支,所有功能合并到此后再發布到main
。feature/*
:功能開發分支,基于dev
創建,完成后合并回dev
。release/*
:預發布分支,用于測試和修復 Bug。hotfix/*
:緊急修復分支,基于main
創建,修復后合并到main
和dev
。
5.5 命令
5.5.1 配置git用戶信息
git config
:配置用戶信息--global user.name 'oldboy'
:配置用戶名--global user.email '……@qq.com'
:配置用戶郵箱地址--global color.ui true
:增加顏色提示--global --list
:顯示配置信息
[root@devops-gitlab /app/src/bugc-live]# git config --global user.name "skx"
[root@devops-gitlab /app/src/bugc-live]# git config --global user.email "skx2554798585@qq.com"
[root@devops-gitlab /app/src/bugc-live]# git config --global color.ui true
[root@devops-gitlab /app/src/bugc-live]# git config --global --list
user.name=skx
user.email=skx2554798585@qq.com
color.ui=true
5.5.2 初始化git倉庫
git init
:初始化當前目錄,作為本地代碼倉庫
[root@devops-gitlab /app/src/bugc-live]# git init
重新初始化已存在的 Git 倉庫于 /app/src/bugc-live/.git/
[root@devops-gitlab /app/src/bugc-live]# ll -a
總用量 12
drwxr-xr-x 3 root root 75 8月 1 12:07 .
drwxr-xr-x 4 root root 41 8月 5 17:44 ..
drwxr-xr-x 8 root root 183 8月 5 17:56 .git
5.5.3 將文件放入暫存區
git status
:查看倉庫狀態git add
:將文件放入暫存區
[root@devops-gitlab /app/src/bugc-live]# git status
位于分支 master
您的分支與上游分支 'origin/master' 一致。尚未暫存以備提交的變更:(使用 "git add/rm <文件>..." 更新要提交的內容)(使用 "git restore <文件>..." 丟棄工作區的改動)刪除: blog.html修改: living.html刪除: shopping.html修改尚未加入提交(使用 "git add" 和/或 "git commit -a")[root@devops-gitlab /app/src/bugc-live]# git add .
[root@devops-gitlab /app/src/bugc-live]# git status
位于分支 master
您的分支與上游分支 'origin/master' 一致。要提交的變更:(使用 "git restore --staged <文件>..." 以取消暫存)刪除: blog.html修改: living.html刪除: shopping.html
5.5.4 提交代碼到本地倉庫
git commit
:提交代碼到本地倉庫- -m:提交說明
[root@devops-gitlab /app/src/bugc-live]# git commit -m "直播軟件開發至10%"
[master 5967c79] 直播軟件開發至10%3 files changed, 1 insertion(+), 3 deletions(-)delete mode 100644 blog.htmldelete mode 100644 shopping.html
[root@devops-gitlab /app/src/bugc-live]# git status
位于分支 master
您的分支領先 'origin/master' 共 1 個提交。(使用 "git push" 來發布您的本地提交)無文件要提交,干凈的工作區
5.5.5 提交日志與代碼回溯
git log
、git reflog
:查看提交日志git reset --hard 提交ID
:代碼還原
[root@devops-gitlab /app/src/bugc-live]# git reflog
# 提交ID
5967c79 (HEAD -> master) HEAD@{0}: commit: 直播軟件開發至10%
[root@devops-gitlab /app/src/bugc-live]# ll
總用量 4
-rw-r--r-- 1 root root 9 8月 5 19:05 living.html
[root@devops-gitlab /app/src/bugc-live]# rm living.html
文件,目錄已經移動到回收站:/recyle/tmp.ncXHc4Rhta
[root@devops-gitlab /app/src/bugc-live]# ll
總用量 0
[root@devops-gitlab /app/src/bugc-live]# git reset --hard 5967c79
HEAD 現在位于 5967c79 直播軟件開發至10%
[root@devops-gitlab /app/src/bugc-live]# ll
總用量 4
-rw-r--r-- 1 root root 9 8月 5 19:19 living.html
[root@devops-gitlab /app/src/bugc-live]# cat living.html
live 10%
5.5.6 分支命令
git branch
:查看當前分支- -v:顯示詳細信息
git branch 新分支名稱
:構建新分支git checkout 分支名稱
:切換分支git merge 分支名稱
:合并分支;先切換到master分支再合并
[root@devops-gitlab /app/src/bugc-live]# git branch
* master
[root@devops-gitlab /app/src/bugc-live]# git branch -v
* master 5967c79 [領先 1] 直播軟件開發至10%
[root@devops-gitlab /app/src/bugc-live]# git branch shopping
[root@devops-gitlab /app/src/bugc-live]# git branch -v
* master 5967c79 [領先 1] 直播軟件開發至10%shopping 5967c79 直播軟件開發至10%
[root@devops-gitlab /app/src/bugc-live]# git checkout shopping
切換到分支 'shopping'
[root@devops-gitlab /app/src/bugc-live]# git branch -vmaster 5967c79 [領先 1] 直播軟件開發至10%
* shopping 5967c79 直播軟件開發至10%
[root@devops-gitlab /app/src/bugc-live]# echo web 20% > web.html
[root@devops-gitlab /app/src/bugc-live]# git add .
[root@devops-gitlab /app/src/bugc-live]# git commit -m "前端代碼開發至20%"
[shopping 91cd7b1] 前端代碼開發至20%1 file changed, 1 insertion(+)create mode 100644 web.html
[root@devops-gitlab /app/src/bugc-live]# git branch -vmaster 5967c79 [領先 1] 直播軟件開發至10%
* shopping 91cd7b1 前端代碼開發至20%
[root@devops-gitlab /app/src/bugc-live]# git checkout master
切換到分支 'master'
您的分支領先 'origin/master' 共 1 個提交。(使用 "git push" 來發布您的本地提交)
[root@devops-gitlab /app/src/bugc-live]# git merge shopping
更新 5967c79..91cd7b1
Fast-forwardweb.html | 1 +1 file changed, 1 insertion(+)create mode 100644 web.html
[root@devops-gitlab /app/src/bugc-live]# ll
總用量 8
-rw-r--r-- 1 root root 9 8月 5 19:19 living.html
-rw-r--r-- 1 root root 8 8月 5 20:01 web.html
[root@devops-gitlab /app/src/bugc-live]# git branch -v
* master 91cd7b1 [領先 2] 前端代碼開發至20%shopping 91cd7b1 前端代碼開發至20%
5.5.7 tag 標簽
tag標簽一般用來標注版本號;
git tag
:查看當前tag標簽- -a:指定當前軟件版本
- -m:描述信息
[root@devops-gitlab /app/src/bugc-live]# git add .
[root@devops-gitlab /app/src/bugc-live]# git commit -m "直播功能開發完畢"
[master ddff93e] 直播功能開發完畢1 file changed, 1 insertion(+), 1 deletion(-)
[root@devops-gitlab /app/src/bugc-live]# git tag -a "v1.0" -m "直播軟件"
[root@devops-gitlab /app/src/bugc-live]# git tag
v1.0
5.5.8 遠程倉庫地址
git remote
:查看遠程倉庫- -v:顯示詳細信息
add <別名> <倉庫地址>
:添加遠程倉庫地址,別名不要沖突remove <別名>
:刪除遠程倉庫地址rename <舊名稱> <新名稱>
:重命名遠程倉庫別名
5.5.9 push 推送
Git 的
push
命令用于將本地倉庫的提交推送到遠程倉庫。
git push
:推送到默認遠程分支-u 遠程倉庫別名 分支名稱
:將指定分支推送到指定遠程倉庫遠程倉庫別名 --all
:推送所有分支遠程倉庫別名
--tags
:推送所有標簽
6. Gitee 碼云
- Git遠程倉庫:
- 公有倉庫:gitee(碼云:
https://gitee.com/
),github - 私有倉庫:gitlab(極狐),gogs
- 公有倉庫:gitee(碼云:
6.1 創建個人項目倉庫
6.2 添加密鑰認證
6.3 本地配置遠程倉庫并推送代碼
- 本地已有git倉庫,需要配置git遠程倉庫,再上傳代碼即可
[root@devops-gitlab /app/src/bugc-live]# git remote add origin git@gitee.com:sun-kexu/live.git
[root@devops-gitlab /app/src/bugc-live]# git remote -v
origin git@gitee.com:sun-kexu/live.git (fetch)
origin git@gitee.com:sun-kexu/live.git (push)
[root@devops-gitlab /app/src/bugc-live]# git push -u origin "master"
枚舉對象: 24, 完成.
對象計數中: 100% (24/24), 完成.
使用 2 個線程進行壓縮
壓縮對象中: 100% (13/13), 完成.
寫入對象中: 100% (24/24), 2.11 KiB | 1.05 MiB/s, 完成.
總共 24(差異 0),復用 0(差異 0),包復用 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag 6f43b2a3
To gitee.com:sun-kexu/live.git* [new branch] master -> master
分支 'master' 設置為跟蹤來自 'origin' 的遠程分支 'master'。
[root@devops-gitlab /app/src/bugc-live]# git push --tags
枚舉對象: 1, 完成.
對象計數中: 100% (1/1), 完成.
寫入對象中: 100% (1/1), 173 字節 | 173.00 KiB/s, 完成.
總共 1(差異 0),復用 0(差異 0),包復用 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag 124c4187
To gitee.com:sun-kexu/live.git* [new tag] v1.0 -> v1.0[root@devops-gitlab /app/src/bugc-live]# git status
位于分支 master
您的分支與上游分支 'origin/master' 一致。無文件要提交,干凈的工作區
7. GitLab 極狐
- 官方Linux軟件包下載地址:
[使用 Linux 軟件包安裝 GitLab |GitLab 文檔](https://docs.gitlab.com/install/package/)
- centos7/redhat7軟件包下載地址:
[gitlab/gitlab-ce - Results for '17.7' and el/7 in gitlab/gitlab-ce](https://packages.gitlab.com/app/gitlab/gitlab-ce/search?q=17.7&filter=all&filter=all&dist=el%2F7)
- 清華鏡像站下載地址:
[Index of /gitlab-ce/yum/el7/ | 清華大學開源軟件鏡像站 | Tsinghua Open Source Mirror](https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/)
7.1 安裝gitlab
- 虛擬機:2核4g
# 上傳rpm包后安裝
yum install -y policycoreutils-python-utils.noarch
rpm -ivh --nodeps gitlab-ce-15.9.3-ce.0.el7.x86_64.rpm
7.2 修改配置文件
- 配置文件地址:
/etc/gitlab/gitlab.rb
external_url 'http://gitlab.oldboy.cn' # 配置gitlab的域名
gitlab_rails['smtp_enable'] = false
gitlab_rails['gitlab_email_enabled'] = false
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"
gitlab_rails['backup_archive_permissions'] = 0644
gitlab_rails['store_initial_root_password'] = true
gitlab_rails['registry_enabled'] = false
registry['enable'] = false
puma['ssl_listen'] = nil
puma['ssl_port'] = nil
puma['ssl_certificate'] = nil
puma['ssl_certificate_key'] = nil
puma['ssl_client_certificate'] = nil
puma['ssl_cipher_filter'] = nil
puma['ssl_verify_mode'] = 'none'
puma['exporter_enabled'] = false
postgresql['enable'] = true
postgresql['ssl'] = 'off'
redis['enable'] = true
nginx['enable'] = true
nginx['client_max_body_size'] = '250m'
nginx['redirect_http_to_https'] = false
nginx['redirect_http_to_https_port'] = 80
prometheus['enable'] = false
alertmanager['enable'] = false
node_exporter['enable'] = false
redis_exporter['enable'] = false
postgres_exporter['enable'] = false
gitlab_exporter['enable'] = false
grafana['enable'] = false
letsencrypt['enable'] = false
- 生成各個服務的子配置文件:
gitlab-ctl reconfigure
- 最后重啟服務:
gitlab-ctl restart
7.3 前端頁面
- 主機和服務端添加hosts解析:
7.3.1 登錄
- 默認密碼文件位置:
/etc/gitlab/initial_root_password
,該文件會在24小時候刪除
7.3.2 修改語言和更改密碼
7.4 創建新項目
7.5 添加密鑰認證
- 若不添加密鑰認證,推送代碼時會交互式認證密碼
7.6 推送代碼
[root@devops-gitlab /app/src/bugc-live]# git remote rename origin old-origin
[root@devops-gitlab /app/src/bugc-live]# git remote add origin git@gitlab.oldboy.cn:gitlab-instance-b39d975d/live.git
[root@devops-gitlab /app/src/bugc-live]# git push -u origin --allAuthorized users only. All activities may be monitored and reported.
枚舉對象: 24, 完成.
對象計數中: 100% (24/24), 完成.
使用 2 個線程進行壓縮
壓縮對象中: 100% (13/13), 完成.
寫入對象中: 100% (24/24), 2.11 KiB | 539.00 KiB/s, 完成.
總共 24(差異 0),復用 0(差異 0),包復用 0
remote:
remote: To create a merge request for shopping, visit:
remote: http://gitlab.oldboy.cn/gitlab-instance-b39d975d/live/-/merge_requests/new?merge_request%5Bsource_branch%5D=shopping
remote:
To gitlab.oldboy.cn:gitlab-instance-b39d975d/live.git* [new branch] master -> master* [new branch] shopping -> shopping
分支 'master' 設置為跟蹤來自 'origin' 的遠程分支 'master'。
分支 'shopping' 設置為跟蹤來自 'origin' 的遠程分支 'shopping'。
[root@devops-gitlab /app/src/bugc-live]# git push -u origin --tagsAuthorized users only. All activities may be monitored and reported.
枚舉對象: 1, 完成.
對象計數中: 100% (1/1), 完成.
寫入對象中: 100% (1/1), 173 字節 | 173.00 KiB/s, 完成.
總共 1(差異 0),復用 0(差異 0),包復用 0
To gitlab.oldboy.cn:gitlab-instance-b39d975d/live.git* [new tag] v1.0 -> v1.0
8. 思維導圖
https://kdocs.cn/join/gpuxq6r?f=101\r\n邀請你加入共享群「老男孩教育Linux運維99期-孫克旭」一起進行文檔協作