文章目录
- 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期-孙克旭」一起进行文档协作