一、gitlab的安装

1)安装依赖包

sudo yum install git vim gcc glibc-statc telnet -y
sudo yum install -y curl policycoreutils-python openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
安装依赖

2)设置防火墙(可选)

sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld
View Code

3)添加gitlab安装源

3.1)设置国内安装源,如设置清华大学的源

vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gbgcheck=0
enable=1
国内清华源

3.2)在国外,设置国外源

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
国外源

4)安装gitlab

4.1)设置域名方式安装

sudo EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ce
域名安装

4.11)可购买真实发域名方式,替换上面的域名

4.12)本地域名测试,在 /etc/hosts里面添加

  192.168.1.20   gitlab.example.com

4.2)不设置域名安装方式

yum install gitlab-ce    安装
gitlab-ctl reconfigure   修改配置

 4.3)如果安装遇到问题解决。--nogpgcheck

   EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ce --nogpgcheck

 安装好修改配置文件

 

 

5)启动查看状态

gitlab-ctl reconfigure
[root@gitlab ~]# gitlab-ctl status
run: alertmanager: (pid 4313) 431s; run: log: (pid 4324) 430s
run: gitaly: (pid 4245) 432s; run: log: (pid 4272) 432s
run: gitlab-monitor: (pid 4284) 432s; run: log: (pid 4287) 431s
run: gitlab-workhorse: (pid 4230) 432s; run: log: (pid 4295) 431s
run: logrotate: (pid 3810) 487s; run: log: (pid 4238) 432s
run: nginx: (pid 3779) 493s; run: log: (pid 4237) 432s
run: node-exporter: (pid 3912) 475s; run: log: (pid 4273) 432s
run: postgres-exporter: (pid 4331) 430s; run: log: (pid 4336) 430s
run: postgresql: (pid 3494) 534s; run: log: (pid 4221) 432s
run: prometheus: (pid 4297) 431s; run: log: (pid 4304) 431s
run: redis: (pid 3432) 540s; run: log: (pid 4220) 432s
run: redis-exporter: (pid 4036) 463s; run: log: (pid 4288) 431s
run: sidekiq: (pid 3744) 501s; run: log: (pid 4223) 432s
run: unicorn: (pid 3704) 507s; run: log: (pid 4222) 432s
启动

6)本地测试访问注意问题

虚拟机中   /etc/hosts里面添加
192.168.0.49   gitlab.example.com

本地电脑中 C:\Windows\System32\drivers\etc\hosts
192.168.0.49   gitlab.example.com
强调hosts文件

访问成功

7)gitlab常用命令

sudo gitlab-ctl start    # 启动所有 gitlab 组件;
sudo gitlab-ctl stop        # 停止所有 gitlab 组件;
sudo gitlab-ctl restart        # 重启所有 gitlab 组件;
sudo gitlab-ctl status        # 查看服务状态;
sudo gitlab-ctl reconfigure        # 启动服务;
sudo vim /etc/gitlab/gitlab.rb        # 修改默认的配置文件;
gitlab-rake gitlab:check SANITIZE=true --trace    # 检查gitlab;
sudo gitlab-ctl tail        # 查看日志;
gitlab常用命令

 二、使用gitlab

1)创建用户名登录

跳转至登录界面

 

 2)添加秘钥设置

在服务器上生成秘钥,复制公钥内容进来

可使用ssh秘钥免费下载

[root@redis02 gitlab_test]# git clone git@192.168.10.239:user/public.git
Cloning into 'public'...
The authenticity of host '192.168.10.239 (192.168.10.239)' can't be established.
RSA key fingerprint is b5:f4:49:a4:92:2f:fd:5d:41:ba:8c:a4:e4:c2:62:5d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.239' (RSA) to the list of known hosts.
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.
Checking connectivity... done.

 修改代码上传

[root@redis02 public]# git config --global user.email "1257073656@qq.com"
[root@redis02 public]# git config --global user.name "user"
[root@redis02 public]# git commit -m "change on linux"
[master 3bb2d0d] change on linux
 1 file changed, 1 insertion(+)
[root@redis02 public]# git push origin master
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 287 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.10.239:caojin/public.git
   18965a3..3bb2d0d  master -> master

 三、新版本gitlab测试

1)取消注册功能

 2)创建项目之前先创建组

2)创建项目。可以选择之前的建立的组

 3)git对提交代码的版本控制

[root@node02 demo]# git show|grep commit
commit f0e08a0c0df9d6e82ebaf4833bd446d7edd48422
[root@node02 demo]# git show|grep commit|cut -d ' ' -f2 
f0e08a0c0df9d6e82ebaf4833bd446d7edd48422
[root@node02 demo]# API_VERL=$(git show|grep commit|cut -d ' ' -f2)
[root@node02 demo]# echo $API_VERL
f0e08a0c0df9d6e82ebaf4833bd446d7edd48422
[root@node02 demo]# echo ${API_VERL:0:6}
f0e08a
[root@node02 demo]# API_VER=$(echo ${API_VERL:0:6})
[root@node02 demo]# echo $API_VER
f0e08a

 4)修改拉取代码的默认url

vim /etc/gitlab/gitlab.rb
.....
# external_url 'http://gitlab.example.com'
external_url 'http://192.168.10.24'
[root@node02 gitlab]# gitlab-ctl reconfigure  重启

 登陆配置oauth配置

--------------------aliyun-sso----------------
external_url 'http://gitlab.www.cn/'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.partner.outlook.cn"
gitlab_rails['smtp_port'] = 587 
gitlab_rails['smtp_user_name'] = "xxxx@pplabs.org"
gitlab_rails['smtp_password'] = "xxxxxxxxxxxxxx"
gitlab_rails['smtp_domain'] = "smtp.partner.outlook.cn"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
gitlab_rails['smtp_openssl_verify_mode'] = 'none'
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'xxxx@pplabs.org'
gitlab_rails['gitlab_email_display_name'] = 'gitlab server'
gitlab_rails['omniauth_enabled'] = true
gitlab_rails['omniauth_allow_single_sign_on'] = ['saml']
gitlab_rails['omniauth_sync_email_from_provider'] = 'saml'
gitlab_rails['omniauth_sync_profile_from_provider'] = ['saml']
gitlab_rails['omniauth_sync_profile_attributes'] = ['mobile','email', 'username', 'nickname']
gitlab_rails['omniauth_auto_sign_in_with_provider'] = 'saml'
gitlab_rails['omniauth_block_auto_created_users'] = false
gitlab_rails['omniauth_auto_link_saml_user'] = true
gitlab_rails['omniauth_providers'] = [
    {
        'name' => 'saml',
        'label' => 'AliYun IDaaS',
        'args' => {
            'assertion_consumer_service_url' => 'https://git.paigod.work/users/auth/saml/callback',
            'idp_cert_fingerprint' => 'd5:25:c0:3f:45:6c:e7:21:79:ef:4e:18:2xxxxxxxxxxxxx:2e:dd:b2',
            'idp_sso_target_url' => 'https://xxxxxx/idaas-cn-hangzhou-dxi0dr49driplugin_saml/sp_sso',
            'issuer' => 'http://gitlab.www.cn',
            'name_identifier_format' => 'urn:oasis:names:tc:xxxx:2.0:nameid-xxxxx:persistent',
        }
    }
]
------------------------------------oauth2------------------
external_url 'http://gitlab.www.cn/'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.partner.outlook.cn"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "xxx@pplabs.org"
gitlab_rails['smtp_password'] = "xxxxxxxxxxxxxxx"
gitlab_rails['smtp_domain'] = "smtp.partner.outlook.cn"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
gitlab_rails['smtp_pool'] = false
gitlab_rails['smtp_openssl_verify_mode'] = 'none'
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'xxx@pplabs.org'
gitlab_rails['gitlab_email_display_name'] = 'gitlab server'
gitlab_rails['omniauth_enabled'] = true
gitlab_rails['omniauth_allow_single_sign_on'] = ['oauth2_generic']
gitlab_rails['omniauth_block_auto_created_users'] = false
gitlab_rails['omniauth_providers'] = [
  {
    name: "oauth2_generic",
    label: "PPIO", # optional label for login button, defaults to "Oauth2 Generic"
    app_id: "abcdedefgba541234566",
    app_secret: "??????????????????????????????????????",
    args: {
      client_options: {
        site: "https://iam.ppio.cloud",
        user_info_url: "https://eee.www.cn/api/userinfo",
        authorize_url: "https://eee.www.cn/login/oauth/authorize",
        token_url: "https://eee.www.cn/api/login/oauth/access_token"
      },
      user_response_structure: {
        root_path: [],
        id_path: ["name"],
        attributes: {
          email: "email",
          name: "name"
        }
      },
      redirect_url: 'http://gitlab.www.cn/users/auth/oauth2_generic/callback',
      authorize_params: {
        scope: "openid profile email"
      },
      strategy_class: "OmniAuth::Strategies::OAuth2Generic"
    }
  }
]
git_data_dirs({
   "default" => {
     "path" => "/data/gitlab/repo"
    }
 })
View Code

更改分组

 

 

posted on 2018-12-24 11:04  可口_可乐  阅读(505)  评论(0编辑  收藏  举报