阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 7 安装 Gitlab

132次阅读
没有评论

共计 8945 个字符,预计需要花费 23 分钟才能阅读完成。

CentOS 7 安装 Gitlab

安装基本系统与依赖包

安装 Gitlab 依赖的工具

yum -y update
yum -y groupinstall 'Development Tools'
yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui git redis ruby sudo wget crontabs logwatch logrotate perl-Time-HiRes

安装 Redis

访问 http://www.redis.io/download,下载 Redis 源代码。

wget http://download.redis.io/releases/redis-3.0.0.tar.gz
tar zxvf redis-3.0.0.tar.gz
cd redis-3.0.0
make

若在编译过程中出错,则可以执行下面的命令:

sudo make test

安装:

sudo make install
sudo ./utils/install_server.sh

配置

创建 /etc/init.d/redis 并使用下面的代码作为启动脚本。

添加如下内容:

###########################
PATH=/usr/local/bin:/sbin:/usr/bin:/bin

REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis.pid
CONF="/etc/redis/6379.conf"

case "$1" in
    start)
        if [-f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        if ["$?"="0" ]
        then
              echo "Redis is running..."
        fi
        ;;
    stop)
        if [! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $REDIS_CLI -p $REDISPORT SHUTDOWN
                while [-x ${PIDFILE} ]
               do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
   restart|force-reload)
        ${0} stop
        ${0} start
        ;;
  *)
    echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
        exit 1
esac
##############################

保存后,添加可执行权限:

sudo chmod +x /etc/init.d/redis

确保 redis 能随系统启动:

vi /etc/rc.d/rc.local

在文件末尾添加下面这行:

service redis start

然后使用上面同样的命令启动 redis 服务:

service redis start

安装邮件服务器

yum -y install postfix

安装 Git

先删除系统中原有的老版本 git

yum -y remove git
yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel

从官方网站下载源代码进行:

curl --progress https://www.kernel.org/pub/software/scm/git/git-2.4.0.tar.gz | tar xz
cd git-2.4.0/
./configure
make
make prefix=/usr/local install

然后使用下面这个命令检测安装是否有效:

which git

安装 ruby

如果 ruby 的版本低于 2.0 的话,则需要重新安装 ruby

cd ~
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz | tar xz
cd ruby-2.2.2
./configure --disable-install-rdoc
make
make prefix=/usr/local install

为 Gitlab 添加系统用户

adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git

为了包含 /usr/local/bin 到 git 用户的 $PATH,一个方法是编辑超级用户文件。以管理员身份运行:

visudo

然后搜索:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

将其改成:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

安装数据库

MySQL 已经不再包含在 CentOS 7 的源中,而改用了 MariaDB,先搜索 MariaDB 现有的包:

rpm -qa | grep mariadb

然后全部删除:

rpm -e --nodeps mariadb-*

然后创建 /etc/yum.repos.d/MariaDB.repo

vi /etc/yum.repos.d/MariaDB.repo

将以下内容添加至该文件中:

# MariaDB 10.0 CentOS repository list - created 2015-05-04 19:16 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

然后运行下面命令安装 MariaDB 10.0

sudo yum install MariaDB-server MariaDB-client

然后启动 MariaDB 服务:

service mysql start

接着运行 mysql_secure_installation

mysql_secure_installation

登录 MariaDB 并创建相应的数据库用户与数据库:

mysql -uroot -p
CREATE USER 'git'@'localhost' IDENTIFIED BY '$password';
SET storage_engine=INNODB;
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';
\q

尝试使用新用户连接数据库:

sudo -u git -H mysql -u git -p -D gitlabhq_production
\q

安装 Gitlab

克隆源

sudo -u -git cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-10-stable gitlab

配置

cd /home/git/gitlab

# Copy the example GitLab config
# 复制 GitLab 的示例配置文件
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

# Make sure to change "localhost" to the fully-qualified domain name of your host serving GitLab where necessary
# 确保修改“localhost”为你的 GitLab 主机的 FQDN
#
# If you want to use https make sure that you set `https` to `true`. See #using-https for all necessary details.
# 如果你想要使用 https 确保你设置了 `https``true`。具体必要的细节参见 #using-https
#
# If you installed Git from source, change the git bin_path to /usr/local/bin/git
# 如果你从源代码安装了 Git,修改 git 的 bin_path 为 /usr/local/bin/git
sudo -u git -H editor config/gitlab.yml

# Make sure GitLab can write to the log/ and tmp/ directories
# 确保 GitLab 可以写入log/ 和 temp/ 目录
chown -R git {log,tmp}
chmod -R u+rwX  {log,tmp}

# Create directory for satellites
# 为卫星 (?) 创建目录
sudo -u git -H mkdir /home/git/gitlab-satellites
chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites

# Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories
# 确保 GitLab 可以写入 tmp/pids/ 和 temp/sockets/ 目录
chmod -R u+rwX  tmp/{pids,sockets}

# Make sure GitLab can write to the public/uploads/ directory
# 确保 GitLab 可以写入public/uploads/ 目录
chmod -R u+rwX  public/uploads

# Copy the example Unicorn config
# 复制 Unicorn 的示例配置文件
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

# Enable cluster mode if you expect to have a high load instance
# Ex. change amount of workers to 3 for 2GB RAM server
# 启用集群模式如果你期望拥有一个高负载实例
# 附:修改 worker 的数量到 3 用于2GB 内存的服务器
sudo -u git -H editor config/unicorn.rb

# Copy the example Rack attack config
# 复制 Rack attack 的示例配置文件
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

# Configure Git global settings for git user, useful when editing via web
# Edit user.email according to what is set in config/gitlab.yml
# 为 git 用户配置 Git 全局设定,当通过 web 修改时有用
# 修改user.email 根据 config/gitlab.yml 中的设定
sudo -u git -H git config --global user.name "GitLab"
sudo -u git -H git config --global user.email "gitlab@localhost"
sudo -u git -H git config --global core.autocrlf input

数据库配置

# MySQL only:
# 仅限 MySQL:sudo -u git cp config/database.yml.mysql config/database.yml

# MySQL and remote PostgreSQL only:
# Update username/password in config/database.yml.
# You only need to adapt the production settings (first part).
# If you followed the database guide then please do as follows:
# Change 'secure password' with the value you have given to $password
# You can keep the double quotes around the password
# 仅限 MySQL 和远程 PostgreSQL:# 在 config/database.yml 中更新用户名 / 密码;# 你只需要适配生产设定(第一部分);# 如果你跟从数据库向导,请按以下操作:# 修改 'secure password' 使用你刚才设定的 $password;# 你可以保留密码两端的双引号。sudo -u git -H editor config/database.yml

# PostgreSQL and MySQL:
# Make config/database.yml readable to git only
# PostgreSQL 和 MySQL:# 设置 config/database.yml 仅对 git 可读。sudo -u git -H chmod o-rwx config/database.yml

安装 Gems

cd /home/git/gitlab

# For users from China mainland only
# 仅限中国大陆用户
nano /home/git/gitlab/Gemfile
source "http://ruby.taobao.org" // 原始 source "https://rubygems.org/"

# For MySQL (note, the option says "without ... postgres")
sudo -u git -H bundle install --deployment --without development test postgres aws

Install GitLab shell

安装 GitLab Shell

GitLab Shell 是一个专门为 GitLab 开发的 SSH 访问和源管理软件。

# Go to the Gitlab installation folder:
# 转到 GitLab 安装目录:
cd /home/git/gitlab

# For users from China mainland only
# 仅限中国大陆用户
nano /home/git/gitlab/Gemfile
source "http://ruby.taobao.org" // 原始 source "https://rubygems.org/"

# Run the installation task for gitlab-shell (replace `REDIS_URL` if needed):
# 运行 gitlab-shell 的安装任务(替换 `REDIS_URL` 如果有需要的话):
sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.6] REDIS_URL=redis://localhost:6379 RAILS_ENV=production

# By default, the gitlab-shell config is generated from your main gitlab config.
# 默认的,gitlab-shell 的配置文件是由你的 gitlab 主配置文件生成的。
#
# Note: When using GitLab with HTTPS please change the following:
# - Provide paths to the certificates under `ca_file` and `ca_path options.
# - The `gitlab_url` option must point to the https endpoint of GitLab.
# - In case you are using self signed certificate set `self_signed_cert` to `true`.
# See #using-https for all necessary details.
# 提示:当通过 HTTPS 使用 GitLab 时,请做出如下更改:
# - 提供证书的路径在 `ca_file` 和 `ca_path` 选项;
# - `gitlab_url` 选项必须指向 GitLab 的 https 端点;
# - 如果你使用自签名的证书,设置 `self-signed_cert` 为 `true`。
# 所有必需的具体细节参见 #using-https
#
# You can review (and modify) it as follows:
# 你可以检查(并修改该)通过以下方法:
sudo -u git -H editor /home/git/gitlab-shell/config.yml

# Ensure the correct SELinux contexts are set
# Read http://wiki.centos.org/HowTos/Network/SecuringSSH
# 确保正确的 SELinux 上下文被设置
# 阅读 http://wiki.centos.org/HowTos/Network/SecuringSSH
restorecon -Rv /home/git/.ssh

初始化数据库和激活高级功能

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
# Type 'yes' to create the database tables.
# When done you see 'Administrator account created:'

提示:你可以设置管理员密码通过在环境变量 GITLAB_ROOT_PASSWORD 中提供,例如:

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

安装初始化脚本

下载初始化脚本(将放在 /etc/init.d/gitlab):

sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
chkconfig --add gitlab

设置 GitLab 开机启动:

chkconfig gitlab on

设置日志翻转

cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

检查应用状态

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

编译静态文件

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

启动实例

/etc/init.d/gitlab start

更多 GitLab 相关教程见以下内容

Ubuntu 14.04 下安装 GitLab 指南  http://www.linuxidc.com/Linux/2015-12/126876.htm

如何在 Ubuntu Server 14.04 下安装 Gitlab 中文版  http://www.linuxidc.com/Linux/2015-12/126875.htm

CentOS 源码安装 GitLab 汉化版  http://www.linuxidc.com/Linux/2015-10/124648.htm

在 Ubuntu 12.04 上安装 GitLab http://www.linuxidc.com/Linux/2012-12/75249.htm

GitLab 5.3 升级注意事项 http://www.linuxidc.com/Linux/2013-06/86473.htm

在 CentOS 上部署 GitLab (自托管的 Git 项目仓库) http://www.linuxidc.com/Linux/2013-06/85754.htm

在 RHEL6/CentOS6/ScientificLinux6 上安装 GitLab 6.0.2 http://www.linuxidc.com/Linux/2014-03/97831.htm

CentOS 6.5 安装 GitLab 教程及相关问题解决 http://www.linuxidc.com/Linux/2014-05/101526.htm

升级 GitLab 到 8.2.0  http://www.linuxidc.com/Linux/2015-12/126220.htm

GitLab 的详细介绍:请点这里
GitLab 的下载地址:请点这里 

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-07/133617.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计8945字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中