前置条件:
- 系统:阿里云CentOS Linux release 7.8.2003 (Core)
- Gitlab:
一、Git安装
1、Centos安装:yum -y install git
安装位置:
yum安装位置一般在/usr/bin/git
[root@iZwz9ga2spyeb5u9tdq8t5Z bin]# whereis git
git: /usr/bin/git /usr/share/man/man1/git.1.gz
安装版本:
git --version
[root@iZwz9ga2spyeb5u9tdq8t5Z default]# git --version
git version 1.8.3.1
2、配置邮箱用户
git config --global user.name "erxiao" 配置用户名
git config --global user.emai "erxiao@sina.cn 配置邮箱
git config --global color.ui true 配置颜色,可以忽略
[root@iZwz9ga2spyeb5u9tdq8t5Z ~]# ll .gitconfig
-rw-r--r-- 1 root root 66 5月 30 17:08 .gitconfig
[root@iZwz9ga2spyeb5u9tdq8t5Z ~]# cat .gitconfig
[user]
name = erxiao
emai = 879056705@qq.com
[color]
ui = true
3、创建本地仓库
-
创建目录:
mkdir demo,并cd到该目录下 -
初始化:
git init
[root@iZwz9ga2spyeb5u9tdq8t5Z demo]# git init
初始化空的 Git 版本库于 /etc/default/demo/.git/
4、生成密钥:ssh-keygen或者ssh-keygen -t rsa -C "xxxxx@xx.com"
,不设置密码的话就一路回车
[root@iZwz9ga2spyeb5u9tdq8t5Z default]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:M5eny+DG+hKXEx94YfeNU/Vgy74WcBDVy+8GP2MI8gc root@iZwz9ga2spyeb5u9tdq8t5Z
The key's randomart image is:
+---[RSA 2048]----+
| oo+.o|
| o .+ o+|
| o o..=+o|
| o o. ++o.|
| S=o.. o..|
| . +=.E .o.|
| +..+ o ++ |
| ..oo o + ++|
| .=o o . ..o|
+----[SHA256]-----+
-
查看公钥:
cat ~/.ssh/id_rsa.pub
5、Git常用命令
-
修改已提交的文件名:
git mv file1.txt file2.txt
[root@iZwz9ga2spyeb5u9tdq8t5Z demo]# git mv file.txt file1.txt
[root@iZwz9ga2spyeb5u9tdq8t5Z demo]# git status
# 位于分支 master
# 要提交的变更:
# (使用 "git reset HEAD <file>..." 撤出暂存区)
#
# 重命名: file.txt -> file1.txt
#
[root@iZwz9ga2spyeb5u9tdq8t5Z demo]# git commit -m "changename"
[master 3c131cf] changename
1 file changed, 0 insertions(+), 0 deletions(-)
rename file.txt => file1.txt (100%)
[root@iZwz9ga2spyeb5u9tdq8t5Z demo]# git status
# 位于分支 master
无文件要提交,干净的工作区
-
查看缓存区与本地仓库的区别:
git diff --cached file.txt
[root@iZwz9ga2spyeb5u9tdq8t5Z demo]# echo "byelily" >> file1.txt
[root@iZwz9ga2spyeb5u9tdq8t5Z demo]# git add .
[root@iZwz9ga2spyeb5u9tdq8t5Z demo]# git diff --cached file1.txt
diff --git a/file1.txt b/file1.txt
index fe970ef..a86c0e0 100644
--- a/file1.txt #表示变动前的
+++ b/file1.txt #表示变动后的
@@ -1 +1,2 @@
hellppython
+byelily
-
清空文件里的内容:
> file.txt -
给当前最新的提交打标签:
git tag -a "v1.0" -m "我是打标签的描述",可加上变更号 -
查询标签内容:
git show v1.0 -
查看变更日志:
git log --pretty=oneline,简要字符: git log --oneline
[root@iZwz9ga2spyeb5u9tdq8t5Z demo]# git log --oneline
3c131cf changename
8ab15b7 hellopython
[root@iZwz9ga2spyeb5u9tdq8t5Z demo]# git log --pretty=oneline
3c131cff0333d7aa71f5227f627c31fca8a755af changename
8ab15b7053f4b4d0f6e29d86fa07cab59a8534f5 hellopython
二、Gitlab安装
1、下载gitlab:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/
2、安装依赖:yum install -y curl postfix policycoreutils-python openssh-server perl
-
启动sshd:
systemctl start sshd -
设置开机启动:
systemctl enable sshd -
启动postfix:
systemctl start postfix -
设置开机启动:
systemctl enable postfix
3、上传安装gitlab的rpm包:yum localinstall gitlab-ce-11.10.0-ce.0.el6.x86_64.rpm
4、修改配置:/etc/gitlab/gitlab.rb
- 修改url和端口
## GitLab URL
##! URL on which GitLab will be reachable.
##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
external_url 'http://120.78.160.194:82'
## Roles for multi-instance GitLab
- 配置邮箱和smtp
### Email Settings
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'erxiao@foxmail.com'
gitlab_rails['gitlab_email_display_name'] = 'erxiao'
# gitlab_rails['gitlab_email_reply_to'] = 'noreply@example.com'
# gitlab_rails['gitlab_email_subject_suffix'] = ''
# gitlab_rails['gitlab_email_smime_enabled'] = false
# gitlab_rails['gitlab_email_smime_key_file'] = '/etc/gitlab/ssl/gitlab_smime.key'
# gitlab_rails['gitlab_email_smime_cert_file'] = '/etc/gitlab/ssl/gitlab_smime.crt'
###! **Use smtp instead of sendmail/postfix.**
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.server"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "erxiao@qq.com"
gitlab_rails['smtp_password'] = "xxxxxxxx"
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
- 关掉Prometheus
prometheus['enable'] = false
# prometheus['monitor_kubernetes'] = true
# prometheus['username'] = 'gitlab-prometheus'
# prometheus['group'] = 'gitlab-prometheus'
# prometheus['uid'] = nil
# prometheus['gid'] = nil
5、初始化gitlab服务:gitlab-ctl reconfigure
,第一次时间久一点
6、重启gitlab:gitlab-ctl restart
,即可登录:IP:82
7、创建项目相关
-
创建组
1)Group name组名一定要写
2)组的能见度,一般设为自己组内成员建,即Private
-
创建项目
-
创建用户
1)用户类型一般都是普通用户,邮箱一定是真实邮箱
2)创建后会收到邮箱修改密码即可
将用户添加到组erxiao
[图片上传失败...(image-5a95d5-1622553195820)]