gitlab机器环境搭建私有仓库和客户端提交代码到gitlab和从gitlab下载代码(cent6.5+gitlab7.9)

gitlab机器环境搭建私有仓库和客户端提交代码到gitlab和从gitlab下载代码(cent6.5+gitlab7.9 

1.gitlab环境搭建私有仓库和客户端和gitlab远程私有仓库之间的推送和下载

1)192.168.224.128机器上:gitlab机器搭建gitlab服务并建立私有仓库(自带web服务,nginx代理,redis等服务)

[root@bogon ~]# /etc/init.d/iptables stop   其实不关闭防火墙也可以

[root@bogon ~]# yum -y install openssh-server

[root@bogon ~]# yum -y install postfix    #安装邮件服务,启动邮件服务后,就不用管了,注册时会给你邮箱发邮件,你认证后才能注册

[root@bogon ~]# yum -y install cronie

[root@bogon ~]# /etc/init.d/postfix start

[root@bogon ~]# chkconfig postfix on

[root@bogon ~]# lokkit -s http -s ssh

下载并上传gitlab的rpm包,

[root@bogon ~]# ls

gitlab-7.9.0_omnibus.2-1.el6.x86_64.rpm

[root@bogon ~]# rpm -ivh gitlab-7.9.0_omnibus.2-1.el6.x86_64.rpm

Preparing...                ########################################### [100%]

1:gitlab                 ########################################### [100%]

hostname: Host name lookup failure

Thank you for installing GitLab!

Configure and start GitLab by running the following command:

sudo gitlab-ctl reconfigure

GitLab should be reachable at http://gitlab.example.com

Otherwise configure GitLab for your system by editing /etc/gitlab/gitlab.rb file

And running reconfigure again.

For a comprehensive list of configuration options please see the Omnibus GitLab readme

README.md · master · GitLab.org / omnibus-gitlab · GitLab

[root@bogon ~]# netstat -anput |grep 80   无端口,还没启动服务

[root@bogon ~]# netstat -anput |grep 8080  无端口,还没启动服务

[root@bogon ~]# ps -ef |grep redis     无redis服务

[root@bogon ~]# vim /etc/gitlab/gitlab.rb

external_url 'http://192.168.224.128' #修改成自己服务器的ip或者能解析的域名,建立仓库时会以该地址形成链接下载地址

配置与启动GitLab 
执行下面的命令即可 #gitlab-ctl reconfigure 

[root@bogon ~]# gitlab-ctl reconfigure #配置和启动服务(第一次启动服务需用命令)

出现下图表示配置和启动成功:

 [root@bogon ~]# gitlab-ctl status  #查看服务状态,#gitlab-ctl stop/start停止/启动服务(配置启动后后用的命令)

run: logrotate: (pid 3001) 810s; run: log: (pid 3000) 810s

run: nginx: (pid 2936) 816s; run: log: (pid 2935) 816s

run: postgresql: (pid 2761) 855s; run: log: (pid 2760) 855s

run: redis: (pid 2645) 866s; run: log: (pid 2644) 866s

run: sidekiq: (pid 2888) 822s; run: log: (pid 2887) 822s

run: unicorn: (pid 2845) 828s; run: log: (pid 2844) 828s

服务启动成功后,会启动两个端口80和8080,redis也会有自己端口,但是随机的

[root@bogon ~]# netstat -anput |grep 80

tcp        0      0 127.0.0.1:8080              0.0.0.0:*                   LISTEN      2883/unicorn master

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      2936/nginx          

[root@bogon ~]# netstat -anput |grep 8080

tcp        0      0 127.0.0.1:8080              0.0.0.0:*                   LISTEN      2883/unicorn master

[root@bogon ~]# netstat -anput |grep redis

tcp        0      0 127.0.0.1:55685             0.0.0.0:*                   LISTEN      2578/redis-server 1

[root@bogon ~]# ps -ef |grep unicorn

有进程

[root@bogon ~]# ps -ef |grep nginx

有进程

[root@bogon ~]# ps -ef |grep redis

有进程

#注意:第一次启动服务需用命令:gitlab-ctl reconfigure配置和启动服务,此后,可以用命令:gitlab-ctl status查看状态,gitlab-ctl stop停止服务,gitlab-ctl start启动服务等操作。(且自动会启动两个端口80和8080端口,自动从自身nginx代理到后面8080端口服务,gitlab服务配置启动后,会自带启动一些服务,内置nginx服务和unicorn服务(web服务)和redis服务,若gitlab-ctl stop后,gitlb服务和自带的服务也就跟着停止了,当再gitlab-ctl start后,自带的服务也跟着起来)

浏览器访问: http://服务器ip即可,如下:http://192.168.224.128 回车即可

回车即可跳转到gitlab注册页面,如下:

 (1)默认的Administrator的账号和密码 
Username: root Password: 5iveL!fe 
(2)第一次登录,会自动跳转到修改密码页面,修改成想要的密码即可。 
(3)管理员登录后可以修改自己的邮件信息等 

输入默认的用户名和密码:root/5iveL!fe登录后,如下:

设置新密码为:root/123456.com,再使用新密码登录后,如下:

就可以创建仓库等操作了。

点击创建一个仓库new project,如下:

 

两个地址区别:

http://192.168.224.128/root/test.git   #使用用户密码root/123456.com推送和clone的地址

git@192.168.224.128:root/test.git      #在gitlab仓库中部署客户端机器的公钥时,可在客户端无需密码clone,但推送时候一般还是使用用户名和密码方式

使用密码时候推送到远程仓库和从远程仓库下载到本地:

推送到远程仓库:      #git push http://root@192.168.224.128/root/test.git master           #root是用户名

从远程仓库下载到本地:#git clone -b master http://root@192.168.224.128/root/test.git       #root是用户名

 2)192.168.224.129机器上:客户端机器安装git并提交代码到上面新建的远程私有仓库中(用用户名和密码)

在客户端机器上安装git,并提交代码到上面新建的远程私有仓库中

[root@bogon ~]# yum -y install git

[root@bogon ~]# git config --global user.name shi                  #你是谁

[root@bogon ~]# git config --global user.email 1441107787@qq.com   #怎么联系到你

[root@bogon ~]# mkdir /test                         #建立一个空目录

[root@bogon ~]# cd /test/

[root@bogon test]# git init                         #将空目录初始化仓库

Initialized empty Git repository in /test/.git/     #将空目录初始化成本地仓库

[root@bogon test]# ls -a

.  ..  .git

在上面初始化的仓库test中进行开发代码,提交到本地仓库并推送到远程gitlab机器仓库,如下:(使用用户名和密码推送到远程仓库)

进入初始化的仓库文件夹,在里面创建开发文件即可。或者利用软件工具开发代码,将开发文件保存到该本地仓库目录中即可。此处将codingcoding测试环境story-java代码上传到本地test仓库中,如下:

[root@bogon test]# ls

hotread03-story-java-develop.zip

[root@bogon test]# unzip hotread03-story-java-develop.zip

[root@bogon test]# ls

hotread03-story-java-develop.zip  story-java-develop

[root@bogon test]# ls story-java-develop/

README.md  story-app   story-core   story-output  story-share  story-wap       story-web

story-api  story-back  story-event  story-push    story-task   story-wap-girl

[root@bogon test]# git status

[root@bogon test]# git add .

[root@bogon test]# git status

[root@bogon test]# git commit -m"tijiao code dao test cangku"  #将文件从暂存区提交到本地的版本库

[root@bogon test]# git status

[root@bogon test]# git push http://root@192.168.224.128/root/test.git master   #root是用户名,推送到远程仓库

Password:  #输入密码:123456.com

Counting objects: 2978, done.

Compressing objects: 100% (2868/2868), done.

Writing objects: 100% (2978/2978), 34.13 MiB | 29.85 MiB/s, done.

Total 2978 (delta 662), reused 0 (delta 0)

To http://root@192.168.224.128/root/test.git

 * [new branch]      master -> master

192.168.224.128机器上:gitlab机器:

推送成功后,到远程仓库查看(192.168.224.128机器上),如下:

 

3)在gitlab仓库中部署客户端的公钥,可以使客户端无需密码即可将远程私有仓库代码下载到客户端本地(无需密码)

客户端机器:192.168.224.129,从远程gitlab仓库克隆到本地(没配公钥时候失败)

[root@bogon test]# mkdir /test2

[root@bogon test]# cd /test2

[root@bogon test2]# git clone -b master git@192.168.224.128:root/test.git  #用ssh地址克隆不下来(未配公钥)

[root@bogon test2]# ssh-keygen

[root@bogon test2]# ls /root/.ssh/

id_rsa  id_rsa.pub  known_hosts

[root@bogon test2]# cat /root/.ssh/id_rsa.pub

ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA9acUs7IARHhF8RR8NJq6KTcAQpaRQGtoX4EEH4CcsZeevKslWgmdPxfzLGo9QCR21l+8D+qnMWuZGnYxNKLuDN5po3IO/UNpVgyw28WZCwgDTnu3WNuG+gY5cVs3/117UOnskf0Ag6WKhJBRlosxv3jfhaJwIl8ceUDykKTRQJr3+JIJwHJ2ERBcKoed3troBS8GjXz6kYaASmIO0VW+00/sdqJzlhkZKL/5nJWdxf/qNv7b9IsBvxg+Nkert+Gzn4+qTnQk+CLWH/5ZpV3Tf2+YuqJ5gCYsQ00ZGR/6cZ9jc2NShcPTNsLUCJQebJMidCoc9Uk6oowSVTP+gDQeRQ== root@bogon

将客户端机器的公钥粘贴在gitlab机器的配置公钥处,如下:

192.168.224.128机器上部署客户端的公钥:gitlab机器

 

客户端机器:192.168.224.129,从远程gitlab仓库克隆到本地(配置公钥时候成功)

[root@bogon test]# cd /test2

[root@bogon test2]# git clone -b master git@192.168.224.128:root/test.git  #用ssh地址能克隆下来(配置了公钥)

Initialized empty Git repository in /test2/test/.git/

reverse mapping checking getaddrinfo for bogon [192.168.224.128] failed - POSSIBLE BREAK-IN ATTEMPT!

remote: Counting objects: 2978, done.

remote: Compressing objects: 100% (2206/2206), done.

remote: Total 2978 (delta 662), reused 2978 (delta 662)

Receiving objects: 100% (2978/2978), 34.13 MiB | 26.17 MiB/s, done.

Resolving deltas: 100% (662/662), done.

[root@bogon test2]# ls

test

[root@bogon test2]# ls test/

hotread03-story-java-develop.zip  story-java-develop

[root@bogon test2]# ls test/story-java-develop/

README.md  story-app   story-core   story-output  story-share  story-wap       story-web

story-api  story-back  story-event  story-push    story-task   story-wap-girl

推送到远程仓库一般还是使用用户名和密码方式

使用密码时候推送到远程仓库和从远程仓库下载到本地:

推送到远程仓库:      #git push http://root@192.168.224.128/root/test.git master           #root是用户名

从远程仓库下载到本地:#git clone -b master http://root@192.168.224.128/root/test.git       #root是用户名

2.gitlab上注册新用户   shi1/123456789

如下图,在下面注册位置填写相关信息:

填写注册相关信息,如下:

 点击sign up,如下:

然后登录填写的邮箱,点击进去,认证,如下:

 

点击确认,如下:

 

 点击继续访问,如下:

认证后,shi1/123456789即可注册完成,重新回到登录界面登录即可,如下:

 

点击sign in,如下:

 即可登录成功,可以创建自己的仓库等操作。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维实战课程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值