gitlab mysql 搭建_GitLab搭建详细过程

gitlab mysql 搭建_GitLab搭建详细过程一 前提系统 Centos6 5 软件版本 gitlab 7 8 4Selinux 关闭防火墙规则 先清空 搭建好了后续自己添加相关放行规则 二 yum 源配置和相关依赖包 1 添加 epel 源和 PUIAS 6 computationa 源 yum yinstallepel release 创建该文件并添加以下内容 vim etc yum repos d PUIAS 6 computatio

一、前提

系统:Centos 6.5

软件版本:gitlab-7.8.4

Selinux:关闭

防火墙规则:先清空(搭建好了后续自己添加相关放行规则)

二、yum源配置和相关依赖包

1.添加epel源和PUIAS_6_computational源

# yum -y install epel-release

创建该文件并添加以下内容:

# vim /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

获取和导入相关验证文件

# 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

# rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias

# yum repolist

2.安装依赖包

# yum install -y vim lrzsz wget gcc gcc-c++ make makeconf cmake

# 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 redis sudo wget crontabs logwatch logrotate perl-Time-HiRes git cmake libcom_err-devel.i686 libcom_err-devel.x86_64 nodejs cmake libicu-devel libicu openssl openssl-devel

查看安装的git版本,需要1.7.12以上,有PUIAS源会装1.8

# git –version

三、安装Ruby

1.查看是否安装有Ruby

# rpm -qa | grep ruby

2.安装Ruby

# mkdir /tmp/ruby && cd /tmp/ruby

# curl –progress ftp://ftp.ruby-lang.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

3.安装Bundler Gem

# gem install bundler –no-doc

可能会报以下错误,这是因为国内网络导致rubygems.org存放在Amazon S3上面的资源文件间接性链接失败,用国内的RubyGems镜像(参见http://ruby.taobao.org/)替换官方镜像

7f39cfb41ba4e8dac78126c0c1460216.png

更换镜像地址:

# gem sources –remove https://rubygems.org/# 删除原镜像地址

# gem sources -a https://ruby.taobao.org/# 添加新镜像地址

查看是否更换成功:

9bfee1d0ce01c13230ffe9b2f9c76afc.png

再次安装:

260291a3e444ff84e4c25bdd9f51f199.png

四、创建系统用户git

# adduser –system –shell /bin/bash –comment ‘GitLab’ –create-home –home-dir /home/git/ git

让git用户可以找到/usr/local/bin命令,并可以使用sudo

# visudo

找到这一行:

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

在后面添加 /usr/local/bin :

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

再找到这一行:

root ALL=(ALL) ALL

在下一行添加:

git ALL=(ALL) ALL

五、安装MySQL

1.前提

这里的数据库需要安装Mysql 5.5以上的版本,而epel源默认只有5.1,所以需要添加有Mysql 5.5的源

# rpm -qa | grep mysql # 查看是否安装比较低版本的mysql,然后卸载

# yum remove -y mysql*

# yum install -y mysql55-server mysql55-devel mysql55 postfix # 安装5.5版本

# chkconfig mysqld on # 设置开机启动

# service mysqld start

要求是InnoDB引擎,登陆查看是否为InnoDB引擎

67a11f7a9c66114606e660af31ae121f.png

如果不是可以用SET storage_engine=INNODB设置,或者修改my.cnf文件后重启mysql

2.配置GitLab使用的数据库

> 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’ identified by ‘git’;

> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO ‘git’@’127.0.0.1’ identified by ‘git’;

> flush privileges;

> exit;

六、安装Redis

安装Reids

# yum -y install redis

# chkconfig redis on

# cp /etc/redis.conf /etc/redis.conf.orig

下面这条命令会把redis.conf的端口设置为0,而redis.conf.orig不变

# sed ‘s/^port .*/port 0/’ /etc/redis.conf.orig | sudo tee /etc/redis.conf

# echo ‘unixsocket /var/run/redis/redis.sock’ | sudo tee -a /etc/redis.conf

# echo -e ‘unixsocketperm 0770’ | sudo tee -a /etc/redis.conf

授权/var/run/redis给redis权限

# mkdir -p /var/run/redis/

# chown redis:redis /var/run/redis

# chmod 755 /var/run/redis

将git加入redis组,并启动Redis

# usermod -aG redis git

# service redis start

七、安装GitLab

1.克隆GitLab

# su – git

# cd /home/git

# git clone https://gitlab.com/larryli/gitlab.git -b 7-8-zh gitlab

2.配置

切换至GitLab目录下面,复制一份配置文件

# cd gitlab

# cp config/gitlab.yml.example config/gitlab.yml

确保GitLab可以对 log 和 tmp 目录有写入权限

# chown -R git log/

# chown -R git tmp/

# chmod -R u+rwX log/

# chmod -R u+rwX tmp/

为satelites创建目录

# mkdir /home/git/gitlab-satellites

# chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites

确保GitLab可以对 tmp/pids、tmp/sockets、public/uploads目录有写入权限

# chmod -R u+rwX tmp/pids/

# chmod -R u+rwX tmp/sockets/

# chmod -R u+rwX public/uploads

从配置案例复制一份unicorn配置文件,并修改配置文件中的timeout选项的值为600(防止仓库文件太大,拉取时间过长出现超时)

# su –

# cd /home/git/gitlab

# sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

# vim gitlab/config/unicorn.rb

修改timeout 600

从配置案例复制一份rack attack配置文件

# sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

为git用户配置git全局配置

# sudo -u git -H git config –global user.name “GitLab”

# sudo -u git -H git config –global user.email “”

# sudo -u git -H git config –global core.autocrlf input

配置redis连接

# sudo -u git -H cp config/resque.yml.example config/resque.yml

配置GitLab数据库设置

# sudo -u git cp config/database.yml.mysql config/database.yml

# vim config/database.yml

只需配置生产的部分(第一部分),用户名和密码

79d8911684d2b190d9faf18ef8c132b5.png

配置好以后运行该命令

# sudo -u git -H chmod o-rwx config/database.yml

配置GitLab绑定的域名或者IP

# vim config/gitlab.yml

修改host为gitlab的域名为你主机的IP地址(有两项,test一项应该没有影响,不过也修改吧)

host:主机IP

安装Gems

# sudo -u git -H bundle install –deployment –without development test postgres aws

可能会报错,还是大陆访问官网的问题,替换成https://ruby.taobao.org,然后再安装

125b53237f1c6c3af60a72aff0917254.png

替换命令:

# sed -i ‘/^source/s/https\:\/\/rubygems\.org/https\:\/\/ruby\.taobao\.org/’ Gemfile

安装GitLab shell

# sudo -u git -H bundle exec rake gitlab:shell:install[v2.5.4] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production

初始化数据库

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

如果想要自己设置GitLab的root默认登陆密码则运行以下命令:

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

默认登陆账号密码

login………root

password……5iveL!fe

配置启动脚本

# cp lib/support/init.d/gitlab /etc/init.d/

配置日志切割

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

运行命令检测GitLab和它的环境是否正确

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

运行命令结果截图如下:

35391bd0e19bc8de24166679a4d0bee6.png

拉取GitLab静态资源文件

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

修改配置文件的gitlab_url为主机IP或者域名

# vim /home/git/gitlab-shell/config.yml

启动GitLab实例

# service gitlab start

八、配置Nginx

安装和配置开机启动(这里用yum安装,也可以自己编译安装)

# yum install -y nginx

# chkconfig nginx on

下载Nginx配置文件,并命名为gitlab.conf

# wget -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab

把nginx加入到git组

# usermod -a -G git nginx

# chmod g+rx /home/git/

修改gitlab.conf文件

# vim /etc/nginx/conf.d/gitlab.conf

server unix:/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket fail_timeout=0; 修改为 server unix:/home/git/gitlab/tmp/sockets/gitlab.socket fail_timeout=0;

listen 0.0.0.0:80 default_server; 修改为 listen 80;

listen [::]:80 default_server; 该行删除

server_name YOUR_SERVER_FQDN; 修改为 server_name 主机IP

启动Nginx

# service nginx start

九、访问

访问地址,http://主机IP或者域名,第一次登陆后就需要修改root用户的密码,然后再去掉GitLab的用户注册功能。到此GitLab搭建完毕!

95d9b4c87dfa15a5cc5b775e5cc0dbc3.png

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/208935.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月19日 上午10:25
下一篇 2026年3月19日 上午10:26


相关推荐

  • 分手后的唯一

    分手后的唯一

    2021年7月25日
    73
  • navicat mac 激活码【中文破解版】[通俗易懂]

    (navicat mac 激活码)本文适用于JetBrains家族所有ide,包括IntelliJidea,phpstorm,webstorm,pycharm,datagrip等。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/ide…

    2022年3月29日
    68
  • GetModuleFileName函数的用法

    GetModuleFileName函数的用法函数功能 获取 exe 可执行文件的绝对路径 用法 通过获取到 exe 的路径 可以获取到程序路径下 父路径或者子路径 的一些其它文件路径 charbuff MAX PATH 用于存放获取的路径信息 GetModuleFil NULL buff MAX PATH 第一个参数为句柄 NULL 则指向当前程序 第二个参数用于存放地址的指针 第三个参数 系统自带的宏定义 不用管

    2026年3月18日
    2
  • Python中的输出「建议收藏」

    Python中的输出「建议收藏」1.Python的输出语句Python输出语句是print,但是python2.x与3.x又有点区别。python2.x输出print"xxx"能成功执行,而3.x不行,所以

    2022年7月5日
    26
  • NIO与传统IO的区别

    NIO与传统IO的区别传统的socket IO中,需要为每个连接创建一个线程,当并发的连接数量非常巨大时,线程所占用的栈内存和CPU线程切换的开销将非常巨大。使用NIO,不再需要为每个线程创建单独的线程,可以用一个含有限数量线程的线程池,甚至一个线程来为任意数量的连接服务。由于线程数量小于连接数量,所以每个线程进行IO操作时就不能阻塞,如果阻塞的话,有些连接就得不到处理,NIO提供了这种非阻塞的能力。小量的线…

    2022年6月13日
    28
  • 项目分层和解析

    DAO层,Service层,Controller层、View层http://hovertree.com/hvtart/bjae/sko15s3g.htm推荐:http://www.cnblogs.

    2021年12月25日
    54

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号