centos7.4+GitLab部署

GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。
系统环境准备
建议:内存4G以上不然带不动

[[email protected] ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[[email protected] ~]# uname -r
3.10.0-693.el7.x86_64

#关闭firewalld和NetWorkManager

[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# systemctl stop NetWorkManager

#永久关闭

[[email protected] ~]# systemctl disable firewalld
[[email protected] ~]# systemctl disable NetWorkManager

#关闭selinux

[[email protected] ~]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g‘ /etc/selinux/config
[[email protected] ~]# setenforce 0

#更换阿里源和下载epel源

[[email protected] ~]#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[[email protected] ~]#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[[email protected] ~]#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

#yum源更新,重启系统

[[email protected] ~]# yum update && reboot

#安装相应工具

[[email protected] ~]yum install curl policycoreutils openssh-server openssh-clients postfix -y
[[email protected] ~]systemctl start postfix

#新建GitLab源

[[email protected] ~]# 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
[[email protected] ~]# yum makecache
[[email protected] ~]# yum install -y gitlab-ce

#安装git工具

[[email protected] ~]# yum install git -y

通常我们在部署的时候会发现80和8080端口均被占用,那么我们就需要修改gitlab的默认端口。
#gitlab配置文件路径,用于gitlab如何调用80和8080的服务等。

/etc/gitlab/gitlab.rb

编辑配置文件并找到 unicorn 配置,将端口修改成想要的端口
修改/etc/gitlab/gitlab.rb

vim /etc/gitlab/gitlab.rb

#unicorn[‘port‘] = 8080 修改 8070  默认是注释的去掉前面的#
unicorn[‘port‘] = 8070
#nginx[‘listen_port‘] = nil 修改 8090  默认是注释的去掉前面的#
nginx[‘listen_port‘] = 8090

修改/var/opt/gitlab/gitlab-rails/etc/unicorn.rb

vim /var/opt/gitlab/gitlab-rails/etc/unicorn.rb

#listen "127.0.0.1:8080", :tcp_nopush => true
listen "127.0.0.1:8070", :tcp_nopush => true

修改默认的gitlab nginx的web服务80端 /var/opt/gitlab/nginx/conf/gitlab-http.conf

vim /var/opt/gitlab/nginx/conf/gitlab-http.conf

#listen *:80;
listen *:8090;

#加载配置文件并启动,时间稍长

[[email protected] ~]# gitlab-ctl reconfigure

#gitlab-ctl其他命令

启动:gitlib-ctl start
关闭:gitlab-ctl stop
重启:gitlab-ctl restart
重载配置:gitlab-ctl reconfigure
查看状态:gitlab-ctl status

#查看端口保证80端口不被占用

[[email protected] ~]# lsof -i:80
COMMAND PID       USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   700       root    7u  IPv4  16903      0t0  TCP *:http (LISTEN)
nginx   804 gitlab-www    7u  IPv4  16903      0t0  TCP *:http (LISTEN)

浏览器登录gitlab,输入http://服务器ip:配置的nginx端口,进入下图:

设置一个密码后,使用 root 用户进行登录。

新建一个项目

那么我们怎样为 GitLab 的账号添加 SSH keys 呢
1).首先打开 linux 服务器,输入命令:ls -al ~/.ssh,检查是否显示有 id_rsa.pub 或者 id_dsa.pub 存在,如果存在请直接跳至第3步。

2).在 bash 中输入 ssh-keygen -t rsa -C ”[email protected]” ,注意这个地方的邮箱地址地址替换成你自己的邮箱地址即可,在显示如下的输出后一直按回车即可:

[[email protected] ~]# useradd web-gitlab
[[email protected] ~]# su !$
su web-gitlab
[[email protected] root]$
[[email protected] root]$
[[email protected] root]$ ssh-keygen -t rsa -C ”[email protected]”
Generating public/private rsa key pair.
Enter file in which to save the key (/home/web-gitlab/.ssh/id_rsa):
Created directory ‘/home/web-gitlab/.ssh‘.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/web-gitlab/.ssh/id_rsa.
Your public key has been saved in /home/web-gitlab/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:hwumGaUbZy7pD/R1LmaRC4NV42NToJZIuqsv1CMyhuo ”[email protected]”
The key‘s randomart image is:
+---[RSA 2048]----+
|    .   +..      |
|   o . = o       |
|  . . * =        |
|   . * . =       |
|. o * B S o      |
|++ = & = B       |
|=.o O o * .      |
|o. . o o .       |
|oE. ...          |
+----[SHA256]-----+
[[email protected] root]$ 

在这里可以看到 id_rsa 和 id_rsa.pub 已经生成,并且生成的路径为 /home/web-gitlab/.ssh/。

[[email protected] root]$ cd /home/web-gitlab/
[[email protected] ~]$
[[email protected] ~]$
[[email protected] ~]$ ll
total 0
[[email protected] ~]$
[[email protected] ~]$ ll .ssh/
total 8
-rw------- 1 web-gitlab web-gitlab 1679 Apr 28 10:42 id_rsa
-rw-r--r-- 1 web-gitlab web-gitlab  402 Apr 28 10:42 id_rsa.pub

3).打开 id_rsa.pub 文件,并且复制全部内容。

[[email protected] ~]$ cat .ssh/id_rsa.pub 

4).打开 GitLab 账户,添加 SSH Keys:

这样就添加了一个SSH key。
5).完成上面的步骤之后就可以使用ssh来连接GitLab,并进行相应的操作了。
我们可以通过 ssh 来 clone 项目

[[email protected] ~]# su web-gitlab
[[email protected] root]$
[[email protected] root]$ cd /home/web-gitlab/
[[email protected] ~]$ git clone [email protected]服务器IP:root/test-demo.git
Cloning into ‘test-demo‘...
The authenticity of host ‘服务器IP (服务器IP)‘ can‘t be established.
ECDSA key fingerprint is SHA256:+CWe+3ROJVtuClFaH425BsTSYf+c9vTuhHF/6jTr4TI.
ECDSA key fingerprint is MD5:63:c6:8a:1a:59:fa:b8:ec:22:cb:29:dd:68:57:d4:3d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘服务器IP‘ (ECDSA) to the list of known hosts.
warning: You appear to have cloned an empty repository.
[[email protected] ~]$
[[email protected] ~]$ ll
total 4
drwxrwxr-x 3 web-gitlab web-gitlab 4096 Apr 28 11:03 test-demo

这就是我们通过 ssh 克隆下来的项目。

参考资料:

  1. centos7.4+GitLab+Jenkins部署及实现集成记录
  2. gitlab修改默认端口
  3. centos 6.8下部署gitlab服务器并修改默认端口
  4. 为GitLab帐号添加SSH keys并连接GitLab

原文地址:http://blog.51cto.com/shaoniana/2108744

时间: 2024-08-30 02:04:56

centos7.4+GitLab部署的相关文章

gitlab部署迁移升级

一.gitlab部署 1.参考网站 https://about.gitlab.com/downloads/#centos6 2.部署步骤: 2.1. Install and configure the necessary dependencies sudo yum install curl openssh-server openssh-clients postfix cronie sudo service postfix start sudo chkconfig postfix on sudo 

gitlab部署、配置更改、备份及恢复

1.gitlab部署 官网 gitlab.com Ubuntu14.04安装 1.Install and configure the necessary dependencies sudoapt-get install postfix 2. Download the Omnibus package and install everything wgethttps://downloads-packages.s3.amazonaws.com/ubuntu-14.04/gitlab_7.9.4-omn

一次在CentOS7上安装部署Zabbix3.0版本及快速进行基本配置的实例

Zabbix3.0的安装.部署.配置,必须基于LAMP环境或是是LNMP环境. 关于LAMP环境的简单快速搭建,见博客:http://afterdawn.blog.51cto.com/7503144/1923139 注意:以下步骤都是在LAMP配置之后进行的. 本文不会再对zabbix-server和zabbix-agent理论知识再进行介绍,建议看完http://afterdawn.blog.51cto.com/7503144/1922502再进行zabbix实战. Zabbix3.0对软硬件

持续集成与自动化部署 - gitlab部署 (四)

1 gitlab部署 部署gitlab参考链接 GitLab是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目. GitLab拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释.可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库.它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找. 1.基础环境准备 [[email protected] ~]# yum

CentOS7.4下部署hadoop3.1.1

CentOS7.4下部署hadoop3.1.1 契机 由于工作原因要部署hadoop的集群,习惯使用最新的稳定版本2018年的时候由于时间紧破部署了2.7.2版本,最新由于又要部署有研究了一下3.x的部署.这次 研究通了,在这里记录一下,防止以往. 本次部署的是一个可用的集群,不是高可用的,因为高可用的hadoop还要部署zookeeper和ha,搞可用的hadoop以后有需要再研究. 准备工作 规划 软件 软件 版本 位数 说明 Jdk Jdk1.8 64位 稳定版本 Centos Cento

GitLab 部署及管理员账号初始化

至于GitLab 部署网上已有大篇幅的资料,但个人都是试了很久才成功的,以此篇博客记录下来,方便自己提心别人 环境:centos 7 gitlab version: 1.cd /home 1.下载rpm安装包 :https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-8.8.5-ce.1.el7.x86_64.rpm 2.切换到gitlab-ce-8.8.5-ce.1.el7.x86_64.rpm所在目录执行 :rpm -

CentOS7.X系统安装部署Consul1.4.2

本文介绍使用docker方式安装consul和传统方式部署:一.基于docker安装部署consul:1.直接docker run运行consul,下载consul1.4.2镜像 #docker run -d --name consul consul:1.4.2 2.将consul镜像内的/consul目录拷贝至本地保存,数据信息持久化 #export CONSULE_CONTANER_ID=docker ps -aq#docker cp ${containerId}:/consul /soft

CentOS7.X安装部署mysql5.7主从环境

生产搭建环境:操作系统:CentOS7.5内存大小:32GB硬盘:500G主库IP:192.168.8.129 hostname:master从库IP:192.168.8.130 hostname:slave 涉及主从都需要执行的地方,文中只写主库的操作指使,从库请自觉执行相同的命令 目录:1.环境准备与清理2.参数调优3.安装部署 1.系统初始化1.1.1. 主从库环境关闭selinux [[email protected]]# sed -i 's/SELINUX=enforcing/SELI

centos7下Gitlab+Jenkins部署持续集成CI环境

1.基本环境 主机:win10,IP:192.168.0.111:部署机器centos7,IP:192.168.0.65:内存推荐到8G,实测6G以上,以免出现内存不够用而报错. 2.安装gitlab需要的组件 [[email protected] ~]# yum -y install curl policycoreutils-python openssh-server openssh-clients postfix wget vim lrzsz启动邮件功能 [[email protected]