GitLab服务器搭建

    应团队要求,要为项目组搭建一个私有版本控制系统,上司给推荐了gitlab这款工具。花了几天时间算是把系统搭建好了,用了几天发现其功能确实强大。这里主要记录在配置环境过程中可能遇到的一些问题以及一些解决方案。
    GitLab是一个开源的项目,项目路径:gitlabhq官方安装指南:install.md。这类开源项目的安装最好按照官方提供的文档来操作。安装过程中出现的问题基本可以在issue里面都可以搜索到。

准备步骤

  • 操作系统(CentOS 6.7 latest)
1. 增加包源

    EPEL,即Extra Packages for Enterprise Linux,这个软件仓库里有很多非常常用的软件,而且是专门针对RHEL设计的,对RHEL标准yum源是一个很好的补充,完全免费使用,由Fedora项目维护,所以如果你使用的是RHEL,或者CentOS,Scientific等RHEL系的linux,可以非常放心的使用EPEL的yum源。如果不加这个源默认yum install redis的时候找不到对应的包。

下载并安装GPG key

$ sudo wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://www.fedoraproject.org/static/0608B895.txt
$ sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

检验下是否安装成功

$ sudo rpm -qa gpg*

安装epel-release-6-8.noarch包

$ sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

增加PUIAS安装源
PUIAS Linux是面向桌面和服务器的完整的操作系统,它靠编译Red Hat Enterprise Linux的源代码包来创建。除了这些上游的软件包外,该项目还提供一些其他的软件仓库:“Addons”包含了通常的Red Hat发行中未收入的额外软件包,“Computational”提供专门针对科学计算的软件,“Unsupported”则收入各种各样的测试性软件 包。该发行由美国普林斯顿 大学的高等研究所维护。

创建/etc/yum.repos.d/PUIAS_6_computational.repo,并添加如下内容:

[PUIAS_6_computational]
name=PUIAS computational Base $releasever - $basearch
`mirrorlist=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch/mirrorlist``#baseurl=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch`
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias

下载并安装GPG key

$ sudo wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-puias http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias
$ sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias

检验下是否安装成功

$ sudo rpm -qa gpg*

Tips:安装完EPEL和PUIAS两个源后,可以检测下:

$ sudo yum repolist

安装必要的软件包

1.安装基础开发包
$ yum -y groupinstall 'Development Tools'
$ yum -y install vim-enhanced readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui python-devel redis sudo wget crontabs logwatch logrotate perl-Time-HiRes git

如果提示出错多半是包源的问题

2.安装Git

// 查看当前git版本

$ git --version

// 如果小于1.7.10则先卸载

$ yum remove git

// 下载最新的git并安装

$ wget -O git-src.zip https://github.com/git/git/archive/master.zip
$ unzip git-src.zip
$ cd git-src
$ make prefix=/usr/local all
$ make prefix=/usr/local install
$ ln -fs /usr/local/bin/git* /usr/bin/
3. 配置邮件模块
sudo yum install curl openssh-server postfix cronie
sudo service postfix start
sudo chkconfig postfix on
sudo lokkit -s http -s ssh

邮件log地址:/var/log/maillog,如果在发邮件有问题log信息可以在这里看到。如果你需要用其他邮件模块,官网有文档。

4. 安装ruby

ruby版本需要2.0+,所以先卸载系统已存在的

yum remove ruby

如果是源码安装的

cd (your-ruby-source-path) && make uninstall
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz | tar xz
cd ruby-2.1.2 && ./configure --disable-install-rdoc && make && make prefix=/usr/local install

安装bundler

gem install bundler --no-doc

完成后验证

which ruby
/usr/local/bin/ruby
ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
5.创建一个系统用户

添加git帐号并允许sudo

$ useradd --comment 'GitLab' git
$ echo "git ALL=(ALL)       NOPASSWD: ALL" >>/etc/sudoers
6. 安装mysql
$ yum install mysql mysql-devel mysql-server -y
$ /etc/init.d/mysqld start
$ chkconfig mysqld on

登录mysql创建gitab的帐号和数据库

mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';

测试是否可以用git帐号登录数据库

sudo -u git -H mysql -u gitlab -p -D gitlabhq_production
7.安装Redis
$ yum -y install redis
$ /etc/init.d/redis start
$ chkconfig redis on
8. 安装GitLab
$ /home/git
$ sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-8-stable gitlab
$ cd /home/git/gitlab
$ sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

// 编辑git路径, gitlab的host:port

$ vim config/gitlab.yml
// bin_path: /usr/local/bin/git
// host: localhost
// port: 80 

// 给文件夹添加相应的权限

$ chown -R git log/
$ chown -R git tmp/
$ chmod -R u+rwX  log/
$ chmod -R u+rwX  tmp/

// 创建必要的文件夹,以及复制配置文件

$ sudo -u git -H mkdir /home/git/gitlab-satellites
$ sudo -u git -H mkdir tmp/pids/
$ sudo -u git -H mkdir tmp/sockets/
$ sudo chmod -R u+rwX  tmp/pids/
$ sudo chmod -R u+rwX  tmp/sockets/
$ sudo -u git -H mkdir public/uploads
$ sudo chmod -R u+rwX  public/uploads
$ sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
$ sudo -u git -H cp config/initializers/rack_attack.rb.example
 config/initializers/rack_attack.rb

配置数据库连接信息

$ sudo -u git cp config/database.yml.mysql config/database.yml
$ sudo -u git -H vim  config/database.yml
$ vim config/database.yml
// production:
//     username: gitlab
//     password: "gitlab"
9.安装GitLab-Shell
$ cd /home/git
$ sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v2.6.0
$ cd gitlab-shell/
$ sudo -u git -H cp config.yml.example config.yml

编辑配置文件, 设置gitlab_url, redis-cli, log-level…

$ vim config.yml
// gitlab_url: "http://localhost/"
// /usr/bin/redis-cli

安装git-shell

$ sudo -u git -H ./bin/install
10. 安装需要ruby的gems
$ cd /home/git/gitlab
$ sudo -u git -H bundle install --deployment --without development test postgres aws

初始化数据库(创建GitLab相关表)

$ sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

安装启动文件以及日志切割文件

cp lib/support/init.d/gitlab /etc/init.d/gitlab
cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

设置git帐号信息

$ sudo -u git -H git config --global user.name "chen"
$ sudo -u git -H git config --global user.email "c.lin@holaverse.com"
$ sudo -u git -H git config --global core.autocrlf input
11.安装Nginx
$ yum -y install nginx
$ vim /etc/nginx/nginx.conf
user              root git;
worker_processes  2;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
# GITLAB
# Maintainer: @randx
# App Version: 5.0

upstream gitlab {
  server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}

server {
  listen *:80 default_server;         # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
  server_name YOUR_SERVER_FQDN;     # e.g., server_name source.example.com;
  server_tokens off;     # don't show the version number, a security best practice
  root /home/git/gitlab/public;

  # Set value of client_max_body_size to at least the value of git.max_size in gitlab.yml
  client_max_body_size 5m;

  # individual nginx logs for this gitlab vhost
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;

  location / {
    # serve static files from defined root folder;.
    # @gitlab is a named location for the upstream fallback, see below
    try_files $uri $uri/index.html $uri.html @gitlab;
  }

  # if a file, which is not found in the root folder is requested,
  # then the proxy pass the request to the upsteam (gitlab unicorn)
  location @gitlab {
    proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_redirect     off;

    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;
    proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;

    proxy_pass http://gitlab;
  }
}
}

更改权限,启动nginx

$ nginx -t
$ chown -R git:git /var/lib/nginx/
$ /etc/init.d/nginx start

检测当前环境

sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

拉取gitlab静态资源文件

$ sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

启动gitlab

$ /etc/init.d/gitlab start

检测各个组件是否正常工作

$ sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

PS: 根据检测结果修改配置以及版本信息

Trouble shooting

1. 解决头像显示问题

编辑gitlab.yml , 找到如下部分:
plain_url 的注释去掉,写成如下内容:
plain_url: "http://gravatar.duoshuo.com/avatar/%{hash}?s=%{size}&d=identicon"

2.解决邮件发送失败问题

测试时选择发件人为:xxxxxxx@126.com,收件人选择为:yyyyyyyy@126.com,发送时提示发送成功,但是邮件一会儿就被退回来了,错误信息如下:
553 Requested action not taken: no smtp MX only,mx7,JcmowEBJG0vqkVdSFTfaBA–.1408S2 1381470699
这个错误大概就是因为发件人和收件人在同一个域中(这里为126.com),但是又选择了另一个SMTP服务器进行发送,所以就被126退回来了。
所以就随便填写一个其他的发件人邮箱地址,比如xxxxx@other126.com,重新测试,成功收到邮件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
为了搭建GitLab服务器,您需要按照以下步骤进行操作: 1. 准备服务器: - 获取一台运行Linux操作系统的服务器,推荐使用Ubuntu或CentOS。 - 确保服务器具有足够的资源(处理器、内存、存储空间)来支持您的项目需求。 2. 安装依赖: - 更新服务器上的软件包列表: `sudo apt update`(对于Ubuntu)或 `sudo yum update`(对于CentOS)。 - 安装必要的依赖项: `sudo apt install curl openssh-server ca-certificates postfix`(对于Ubuntu)或 `sudo yum install curl openssh-server postfix`(对于CentOS)。 - 在安装过程中,您需要配置Postfix来设置邮件转发。选择"Internet Site"选项,并将系统邮件名称设置为域名,比如"yourdomain.com"。 3. 安装GitLab: - 添加GitLab软件仓库并安装: ``` curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash sudo EXTERNAL_URL="http://yourdomain.com" apt install gitlab-ee ``` 或者 ``` curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash sudo EXTERNAL_URL="http://yourdomain.com" yum install gitlab-ee ``` 请将"yourdomain.com"替换为您的域名或服务器IP地址。 4. 配置GitLab: - 打开配置文件: `sudo nano /etc/gitlab/gitlab.rb`。 - 根据您的需求,修改配置文件中的参数,如外部URL、SMTP设置、存储设置等。 - 保存并关闭配置文件。 5. 启动GitLab: - 执行命令: `sudo gitlab-ctl reconfigure`。 - 等待一段时间,直到GitLab配置完成。 6. 访问GitLab: - 在浏览器中访问您的服务器IP地址或域名。 - 您将被重定向到GitLab登录页面。 - 创建管理员账户,完成注册。 现在,您已经成功搭建了GitLab服务器,并可以开始管理您的项目了!请注意,这只是一个基本的搭建过程,您可能需要进一步配置和定制以满足您的特定需求。参考GitLab官方文档以获取更多信息和帮助:https://docs.gitlab.com/。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值