设为首页 收藏本站
查看: 850|回复: 0

[经验分享] 剑握在手

[复制链接]

尚未签到

发表于 2018-1-11 21:00:22 | 显示全部楼层 |阅读模式
  整个搭建用的都是各种默认设置,所以没有用到高深的的东西,比较简单,比较傻瓜式,这篇也仅仅是一个入门。
  另外本文具有时效性,浏览本文请注意发表时间,为防止过时产生误导,本文尽量把 “如何得知应该这样做” 之类的内容放进去。
  1、安装GitLab
  从官网获得安装步骤,并执行(不去官网也可以,本文已经把所有用到的命令放进来了,往下看吧)。
  官网:https://about.gitlab.com/installation/

  选择CentOS7

  进入了社区版的安装步骤说明,gitlab分为社区版(免费)和企业版(收费),社区版目前已经满足我们的需求,直接照着里面的命令敲一遍即可,中间有个命令要下载三百多兆的文件,这里把命令贴出来,省的再去官网了。
  命令如下,加粗标下划线的:
  

1. Install and configure the necessary dependencies  

  
If you
install Postfix to send email please select 'Internet Site' during setup. Instead of using Postfix you can also use Sendmail or configure a custom SMTP server and configure it as an SMTP server.  

  
On CentOS, the commands below will also open HTTP and SSH access
in the system firewall.  

  

sudo yum install curl policycoreutils openssh-server openssh-clients  

sudo systemctl enable sshd  

sudo systemctl start sshd  

sudo yum install postfix  

sudo systemctl enable postfix  

sudo systemctl start postfix  

sudo firewall-cmd --permanent --add-service=http  

sudo systemctl>
  

2. Add the GitLab package server and install the package  

  
curl
-sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash  
sudo yum install gitlab-
ce  

  
If you are not comfortable installing the repository through a piped script, you can
find the entire script here and select and download the package manually and install using  

  
curl
-LJO https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-XXX.rpm/download  
rpm -i gitlab-ce-XXX.rpm
  

  
3. Configure and start GitLab
  

  
sudo gitlab-ctl reconfigure
  

  
4. Browse to the hostname and login
  

  
On your first visit, you'll be redirected to a password reset screen to provide the password for the initial administrator account. Enter your desired password and you'll be redirected back to the login screen.
  

  
The default account's username is root. Provide the password you created earlier and login. After login you can change the username if you wish.
  

  第四条是说你安装完成后的首次登陆会被重定向到一个密码帐号设置页,默认gitlab是跑在80端口的,以上步骤执行完后直接从本地访问localhost,或者用其他机器访问,然后设置密码即可。
  2、登陆gitlab并创建一个仓库
  默认用户是root,密码是你刚才设置的密码,不建议使用该用户登陆,建议注册一个

  用新用户登陆,点击New project,创建一个项目

  填写项目名,选择private可设为私有项目,这样你不添加协作者,他们是没法搞你的项目的,这里选择private

  创建完成后

  中间的地址就是访问地址,至此仓库创建完毕。如何在客户端使用不是本文 讨论范畴,不再赘述,下面我们来看看web hook怎么添加。
  3、创建web hook
  web hook 功能:
  gitlab服务器可以在  用户推送代码到服务器、推送注释到服务器等用户事件发生的时候,将该事件的细节上报给你指定的web url。
  你只需要告诉gitlab服务器,你想让它访问的url和在什么事件产生时访问该url即可。
  新版本的web hook设置的位置稍有改变,在上图所示的页面上,点击右上角的Settings,再选择Integrations,就可以进入web hook创建界面,界面截图如下:

  其中URL就是各种事件的推送地址,Secret Token则可以用来作为验证字符串,这里不填,下边的Trigger则罗列了各种可以选择的事件。填完保存

  保存完后,这条web hook就会出现在这个按钮的下方

  这里可以点Test来测试一下该地址。
  这里配置的地址是http://192.168.31.221:8080/test,选择的事件是Push Events,
  那么一旦有人提交代码到这个仓库,服务器就会访问http://192.168.31.221:8080/test,并把细节作为报文内容发送过去,一般会发送以下内容:
  

{"object_kind": "push","before": "95790bf891e76fee5e1747ab589903a6a1f80f22","after": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7","ref": "refs/heads/master","checkout_sha": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7","user_id": 4,"user_name": "John Smith","user_username": "jsmith","user_email": "john@example.com","user_avatar": "https://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=8://s.gravatar.com/avatar/d4c74594d841139328695756648b6bd6?s=80","project_id": 15,"project":{"name":"Diaspora","description":"","web_url":"http://example.com/mike/diaspora","avatar_url":null,"git_ssh_url":"git@example.com:mike/diaspora.git","git_http_url":"http://example.com/mike/diaspora.git","namespace":"Mike","visibility_level":0,"path_with_namespace":"mike/diaspora","default_branch":"master","homepage":"http://example.com/mike/diaspora","url":"git@example.com:mike/diaspora.git","ssh_url":"git@example.com:mike/diaspora.git","http_url":"http://example.com/mike/diaspora.git"  },
"repository":{"name": "Diaspora","url": "git@example.com:mike/diaspora.git","description": "","homepage": "http://example.com/mike/diaspora","git_http_url":"http://example.com/mike/diaspora.git","git_ssh_url":"git@example.com:mike/diaspora.git","visibility_level":0  },
"commits": [  {
"id": "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327","message": "Update Catalan translation to e38cb41.","timestamp": "2011-12-12T14:27:31+02:00","url": "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327","author": {"name": "Jordi Mallach","email": "jordi@softcatala.org"  },
"added": ["CHANGELOG"],"modified": ["app/controller/application.rb"],"removed": []  },
  {
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7","message": "fixed readme","timestamp": "2012-01-03T23:36:29+02:00","url": "http://example.com/mike/diaspora/commit/da1560886d4f094c3e6c9ef40349f7d38b5d27d7","author": {"name": "GitLab dev user","email": "gitlabdev@dv6700.(none)"  },
"added": ["CHANGELOG"],"modified": ["app/controller/application.rb"],"removed": []  }
  ],
"total_commits_count": 4  
}
  

  各种事件发送的报文内容略有不同,具体可以访问你github服务器上的:
  http://localhost/help/user/project/integrations/webhooks
  地址来查看。
  有了这样一种设置,我们可以自己实现一些功能,比如如果推送了一个符合自己约定规则的标签,那么就自动获取最新代码并发布到某个服务器上,当然,我描述的这个功能Jenkins已经帮我们实现了,这个也不在本文中讨论了。
  以上,希望能对别人有所帮助,完毕。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-434068-1-1.html 上篇帖子: 在win7下使用git和gitlab进行code review 下篇帖子: gitlab在centons环境下的安装及使用
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表