gitlab安装与gitlab-mirrors同步gitee
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gitlab安装与gitlab-mirrors同步gitee相关的知识,希望对你有一定的参考价值。
参考技术A 1,安装gitlab,参考:[ https://www.jianshu.com/p/d3686bc94ac9]安装完毕配置external_url时把原来的域名改成自己实际的ip地址加上端口号,端口号默认是80,配置最好大于4G内存。
2,可以修改gitlab配置文件,修改默认数据目录和备份文件目录。
3,安装配置gitlab-mirrros,参考:[ https://www.jianshu.com/p/70b138f88514]
安装python setup.py install这一步时如果报如下错误:
“error: Setup script exited with error in urllib3 setup command: 'extras_require' must be a dictionary whose values are strings or lists of strings containing valid project/version requirement specifiers.”
那么就需要更新setuptools的版本,首先yum install python-pip,然后pip install --upgrade setuptools,再执行python setup.py install即可正常安装。
4,添加仓库同步配置,这一步如果报如下错误
“Traceback (most recent call last):
File "lib/manage_gitlab_project.py", line 12, in <module>
raise ImportError("python-gitlab module is not installed. You probably didn't read the install instructions closely enough. See docs/prerequisites.md.")
ImportError: python-gitlab module is not installed. You probably didn't read the install instructions closely enough. See docs/prerequisites.md.
There was an unknown issue with manage_gitlab_project.py
”
那么则按提示安装模块:sudo yum install python-gitlab,然后在添加仓库同步配置即可。
5,同步和备份
编辑vim /etc/crontab
systemctl restart crond
每天夜晚23:50同步所有项目(gitmirror为执行命令的用户名,即为gitlab-mirrors项目中config.sh中配置的system_user)
50 23 * * * gitmirror sh /home/gitmirror/gitlab-mirrors/git-mirrors.sh
每天凌晨4:10备份所有项目
10 4 * * * root /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
gitlab安装与应用
1、gitlab介绍
Gitlab的优势和应用场景:
开源免费,适合中小型公司将代码放置在该系统中;
差异化的版本管理,离线同步以及强大分支管理功能;
便捷的GUI操作界面以及强大账户权限管理功能;
集成度很高,能够集成绝大多数的开发工具;
支持内置HA,保证在高并发下仍旧实现高可用性;
GitLab主要服务构成:
Nginx静态Web服务器;
Gitlab-workhorse轻量级的反向代理服务器;
Gitlab-shell 用于处理Git命令和修改authorized keys列表;
Logrotate 日志文件管理工具
Postgresql 数据库
Redis 缓存服务器
GitLab的工作流程:
创建并克隆项目
创建项目某Feature分支
编写代码并提交至该分支
推送该项目分支至远程Gitlab服务器
进行代码检查并提交Master主分支合并申请
项目领导审查代码并确认合并申请
2、gitlab安装配置
1)安装gitlab-ce
1.安装Gitlab组件 yum-y install curl policycoreutils openssh-server openssh-clients postfix 2.配置YUM仓库 curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash 3.启动postfix邮件服务 systemctl start postfix && systemctl enable postfix 4.安装Gitlab-ce社区版本 使用国内的镜像源,比较快: 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/ gpgcheck=0 enabled=1 yum makecache yum install -y gitlab-ce
2)Gitlab等相关配置初始化并完成安装
1.证书创建与配置加载 [root@gitlab ]# mkdir -p /etc/gitlab/ssl && cd /etc/gitlab/ssl [root@gitlab ssl]# openssl genrsa -out "/etc/gitlab/ssl/gitlab.example.com.key" 2048 [root@gitlab ssl]# cd /etc/gitlab/ssl/ [root@gitlab ssl]# openssl req -new -key "/etc/gitlab/ssl/gitlab.example.com.key" -out "/etc/gitlab/ssl/gitlab.example.com.csr" """ Country Name (2 letter code) [XX]:cn #cn State or Province Name (full name) []:bj #bj Locality Name (eg, city) [Default City]:bj #bj Organization Name (eg, company) [Default Company Ltd]: #回车 Organizational Unit Name (eg, section) []: #回车 Common Name (eg, your name or your server‘s hostname) []:gitlab.example.com #gitlab.example.com Email Address []:admin@example.com #admin@example.com Please enter the following ‘extra‘ attributes to be sent with your certificate request A challenge password []:123456 #123456 An optional company name []: #回车 """ [root@gitlab ssl]# openssl x509 -req -days 365 -in "/etc/gitlab/ssl/gitlab.example.com.csr" -signkey "/etc/gitlab/ssl/gitlab.example.com.key" -out "/etc/gitlab/ssl/gitlab.example.com.crt" [root@gitlab ssl]# openssl dhparam -out /etc/gitlab/ssl/dhparams.pem 2048 [root@gitlab ssl]# chmod 600 * [root@gitlab ssl]# vim /etc/gitlab/gitlab.rb external_url ‘https://gitlab.example.com‘ #29行 nginx[‘redirect_http_to_https‘] = true #1112行,去掉注释改为true #nginx[‘ssl_certificate‘] = "/etc/gitlab/ssl/gitlab.example.com.crt" #1124行 #nginx[‘ssl_certificate_key‘] = "/etc/gitlab/ssl/gitlab.example.com.key" #1125行 #nginx[‘ssl_dhparam‘] = /etc/gitlab/ssl/dhparams.pem #1139行 [root@gitlab ssl]# gitlab-ctl reconfigure 2.Nginx SSL代理服务配置 [root@gitlab ssl]# vim /var/opt/gitlab/nginx/conf/gitlab-http.conf rewrite ^(.*)$ https://$host$1 permanent; #38行 [root@gitlab ssl]# gitlab-ctl restart [root@gitlab ssl]# netstat -ntlp 我的是虚拟机,需要编辑windows本机的hosts写入下面的内容代替DNS解析: 192.168.3.202 gitlab.example.com 3.初始化Gitlab相关服务并完成安装 浏览器打开:gitlab.example.com 需要先改密码; 默认用户root 然后输入你的密码,登录;
说明:生产场景应单独配置gitlab的仓库目录;
3、gitlab初步测试
在 gitlab中创建一个project:test-project
然后在本地的windows中使用Git Bash操作:
#在Git Bash里面可以使用linux命令 Administrator@MSI MINGW64 ~/Desktop $ pwd /c/Users/Administrator/Desktop Administrator@MSI MINGW64 ~/Desktop $ mkdir repo #在桌面上创建一个repo目录 Administrator@MSI MINGW64 ~/Desktop $ cd repo Administrator@MSI MINGW64 ~/Desktop/repo $ git -c http.sslVerify=false clone https://gitlab.example.com/root/test-repo.git # 把刚才创建的project克隆下来 Cloning into ‘test-repo‘... warning: You appear to have cloned an empty repository. Administrator@MSI MINGW64 ~/Desktop/repo $ ls #ls test-repo/ Administrator@MSI MINGW64 ~/Desktop/repo $ cd test-repo/ Administrator@MSI MINGW64 ~/Desktop/repo/test-repo (master) $ vim test.py #进来创建一个测试文件 Administrator@MSI MINGW64 ~/Desktop/repo/test-repo (master) $ cat test.py print("This is a test code") Administrator@MSI MINGW64 ~/Desktop/repo/test-repo (master) $ git add . warning: LF will be replaced by CRLF in test.py. The file will have its original line endings in your working directory. Administrator@MSI MINGW64 ~/Desktop/repo/test-repo (master) $ git config --global user.email "admin@example.com" Administrator@MSI MINGW64 ~/Desktop/repo/test-repo (master) $ git config --global user.name "admin" Administrator@MSI MINGW64 ~/Desktop/repo/test-repo (master) $ git commit -m"First commit" [master (root-commit) c4f1c38] First commit 1 file changed, 1 insertion(+) create mode 100644 test.py Administrator@MSI MINGW64 ~/Desktop/repo/test-repo (master) $ git -c http.sslVerify=false push origin master #上传 Counting objects: 3, done. Writing objects: 100% (3/3), 232 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To https://gitlab.example.com/root/test-repo.git * [new branch] master -> master
上传完成后,取girlab中查看;
4、gitlab的使用
1)gitlab页面管理
系统相关信息:
application.log记录了gitlab的操作信息;production.log记录了gitlab的 访问信息;
健康状况:
2)账号管理
给不同的账号赋予不同的权限:
这样开发人员就可以申请提交代码合并分支的操作,领导账号可以检查同意;
以上是关于gitlab安装与gitlab-mirrors同步gitee的主要内容,如果未能解决你的问题,请参考以下文章