GitLab简介与系统环境概述
GitLab是一款基于Ruby on Rails构建的开源项目管理工具,允许用户通过Web界面访问公开或私有的项目资源。它具备与GitHub相似的核心功能,包括源代码浏览、缺陷跟踪以及代码注释管理等。
下文将具体阐述在Debian/Ubuntu系列发行版以及CentOS系统中部署和配置GitLab的详细流程。
安装基础依赖包
对于Debian/Ubuntu系统:
复制代码 代码如下: sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate
安装Python(需确保版本高于2.5):
sudo apt-get install -y python python-docutils
安装Git(需确保版本高于1.7.10):
sudo apt-get install -y git-core
由于CentOS官方软件仓库中的软件版本通常较旧,建议先添加EPEL源,随后再安装所需的依赖包:
复制代码 代码如下: sudo yum install git patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel git python python-docutils
安装Ruby 2.0
必须安装Ruby 2.0版本,因为软件仓库中默认的Ruby 1.8版本不被支持:
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz
cd ruby-2.0.0-p353
./configure --disable-install-rdoc
make
sudo make install
安装Bundler Gem:
sudo gem install bundler --no-ri --no-rdoc
配置GitLab Shell
创建专用的git用户:
sudo adduser --system --create-home --comment 'GitLab' git
配置GitLab Shell
su - git -c "git clone https://github.com/gitlabhq/gitlab-shell.git"
su - git -c "cd gitlab-shell && git checkout v1.3.0"
su - git -c "cp gitlab-shell/config.yml.example gitlab-shell/config.yml"
sed -i "s/localhost/gitlab.51yip.com/g" /home/git/gitlab-shell/config.yml
su - git -c "gitlab-shell/bin/install"
chmod 600 /home/git/.ssh/authorized_keys
chmod 700 /home/git/.ssh
数据库配置
GitLab兼容MySQL和PostgreSQL数据库。此处以MySQL为例介绍安装方法:
在Debian/Ubuntu系统中使用以下命令安装:
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
在CentOS系统中使用以下命令:
sudo yum install mysql-server
sudo chkconfig mysqld on
配置MySQL数据库:
sudo echo "CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';" | mysql -u root
sudo echo "UPDATE mysql.user SET Password=PASSWORD('123456') WHERE User='root'; FLUSH PRIVILEGES;" | mysql -u root
请注意,请将示例中的密码“123456”替换为您实际设置的密码。
安装并配置GitLab主程序
su - git -c "git clone https://github.com/gitlabhq/gitlabhq.git gitlab"
su - git -c "cd gitlab;git checkout 5-1-stable"
su git -c "cp config/gitlab.yml.example config/gitlab.yml"
su git -c "mkdir /home/git/gitlab-satellites"
su git -c "mkdir public/uploads"
su git -c "mkdir -p tmp/sockets/"
su git -c "mkdir -p tmp/pids/"
sed -i "s/ host: localhost/ host: gitlab.segmentfault.com/g" config/gitlab.yml
sed -i "s/from: gitlab@localhost/from: gitlab@gitlab.segmentfault.com/g" config/gitlab.yml
su git -c "cp config/puma.rb.example config/puma.rb"
su git -c 'git config --global user.name "GitLab"'
su git -c 'git config --global user.email "gitlab@gitlab.segmentfault.com"'
注意将示例中的域名“gitlab.segmentfault.com”替换为您自己的服务器域名。
配置数据库连接信息:
sudo su git -c "cp config/database.yml.mysql config/database.yml"
sudo sed -i "s/secure password/mysql的root密码/g" config/database.yml
安装MySQL所需的Gems组件
sudo -u git -H bundle install --deployment --without development test postgres aws
执行初始化操作:
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo chmod +x /etc/init.d/gitlab
sudo update-rc.d gitlab defaults 21
检查配置是否已正确完成:
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
重启GitLab服务:
sudo service gitlab start
配置Nginx Web服务器
Debian/Ubuntu系统下:
sudo apt-get install -y nginx
CentOS系统下:
sudo yum install nginx
下载配置文件样例:
sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
修改 /etc/nginx/sites-available/gitlab 文件,务必将 YOUR_SERVER_FQDN 更改为您的实际域名。
重启Nginx服务:
sudo service nginx restart
至此,您可以登录GitLab了。默认安装后的管理员用户名是 admin@local.host,初始密码为 5iveL!fe。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持本站。