1.1
1、GitLab是什么?
1. GitLab实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。
2. GitLab拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。
3. 可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。
4. 它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找
2、gitlab安装
'''1. 初始化环境 ''' [root@linux-node2 ~]# yum install curl policycoreutils openssh-server openssh-clients postfix [root@linux-node2 ~]# systemctl start postfix '''2. 由于网络问题,国内用户,建议使用清华大学的镜像源进行安装''' [root@linux-node2 ~]# vim /etc/yum.repos.d/gitlab-ce.repo ''' [gitlab-ce] name=gitlab-ce baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7 repo_gpgcheck=0 gpgcheck=0 enabled=1 gpgkey=https://packages.gitlab.com/gpg.key ''' [root@linux-node2 ~]# curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash [root@linux-node2 ~]# yum makecache [root@linux-node2 ~]# yum install -y gitlab-ce-10.8.7 '''3.配置并启动gitlab-ce''' [root@linux-node2 ~]# gitlab-ctl reconfigure # 把一些过去的config还原,使用是要小心 [root@linux-node2 ~]# gitlab-ctl status [root@linux-node2 ~]# gitlab-ctl start # 启动gitlab [root@linux-node2 ~]# gitlab-ctl stop # 关闭gitlab [root@linux-node2 ~]# gitlab-ctl restart # 重启gitlab # 注:安装启动gitlab后访问, http://192.168.56.12/
'''4.在浏览器中访问gitlab-ce'''
1. 安装启动gitlab后访问, http://192.168.56.12/
2. 第一次登录gitlab,需要为root用户修改密码,root用户也是gitlab的超级管理员
3、可以对GitLab做以下配置
'''1、可以更改gitlab访问的地址和端口号'''
[root@linux-node2 ~]# vim /etc/gitlab/gitlab.rb
external_url 'http://gitlab.example.com'
'''2、更换gitlab拉取代码的URL'''
[root@linux-node2 ~]# vim /var/opt/gitlab/gitlab-rails/etc/gitlab.yml
gitlab:
# 修改拉取代码的url地址
host: 192.168.56.12
port: 80
https: false
1.2 GitLab基本使用
1、选择 "Create a group"
2、填写组名称
3、在这个组里创建一个项目:选择 "New project"
4、新建一个项目,命名为 "demo"
5、创建完成可以看到有一些提示
'''1. Git global setup: 全局配置用户信息''' git config --global user.name "Administrator" git config --global user.email "admin@example.com" '''2. 提交代码的三种情况''' # 情况1:Create a new repository-本地没有没有仓库,创建一个新仓库 git clone git@192.168.56.12:devopsedu/demo.git cd demo touch README.md git add README.md git commit -m "add README" git push -u origin master # 情况2:Existing folder-本地存在一个文件夹 cd existing_folder git init git remote add origin git@192.168.56.12:devopsedu/demo.git git add . git commit -m "Initial commit" git push -u origin master # 情况3:Existing Git repository-本地以及存在一个git仓库 cd existing_repo git remote rename origin old-origin git remote add origin git@192.168.56.12:devopsedu/demo.git git push -u origin --all git push -u origin --tags