gitlab部署
admin
2023-06-04 11:01:27
0

一、配置epel源

wget   http://mirrors.aliyun.com/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm  -ivh  epel-release-6-8.noarch.rpm


二、安装依赖包

yum -y install libicu-devel patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make cmake autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker


三、安装git

下载链接:

wget -O git-src.zip https://github.com/git/git/archive/master.zip


[root@localhost ~]# unzip git-src.zip
[root@localhost ~]# cd git-master/
[root@localhost git-master]# make prefix=/usr/local all
[root@localhost git-master]# make prefix=/usr/local install
[root@localhost git-master]# ln -fs /usr/local/bin/git* /usr/bin/


四、安装ruby

[root@localhost src]# wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-2.1.5.tar.gz
[root@localhost src]# tar-zxf ruby-2.1.5.tar.gz
[root@localhost src]# cd ruby-2.1.5
[root@localhost ruby-2.1.5]# ./configure --disable-install-rdoc && make && make install
[root@localhost ~]# ln -s /usr/local/bin/ruby /usr/bin/ruby
[root@localhost ~]# ln -s /usr/local/bin/gem /usr/bin/gem
[root@localhost ~]# gem install bundler --no-ri --no-rdoc
[root@localhost ~]# ln -s /usr/local/bin/bundle /usr/bin/bundle


五、安装mysql并初始化gitlab

[root@localhost ~]# yum -y install mysql mysql-devel mysql-server
[root@localhost ~]# service mysqld start
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# mysql
mysql> create database gitlab;
mysql> grant all privileges on gitlab.* to 'gitlab'@'localhost' identified by 'gitlab';


 

测试是否可以用gitlab登录数据库:

[root@localhost ~]# mysql -u gitlab -p -D gitlab
Enter password:


 

六、安装redis

[root@localhost ~]# yum -y install redis
[root@localhost ~]# vi /etc/redis.conf
  36 unixsocket /tmp/redis.sock
 37 unixsocket perm 755
[root@localhost ~]# service redis start
[root@localhost ~]# chkconfig redis on


七、创建git用户并允许sudo

[root@localhost ~]# useradd git
echo "git ALL=(ALL)       NOPASSWD: ALL" >> /etc/sudoers


八、安装gitlab

[root@localhost ~]# cd /home/git/
[root@localhost git]# sudo -u git -H git clone   -b 7-8-stable gitlab
[root@localhost git]# cd gitlab
[root@localhost gitlab]# cp config/gitlab.yml.example config/gitlab.yml
[root@localhost gitlab]# vi config/gitlab.yml
  20     host: localhost
  21     port: 80
  267    bin_path: /usr/bin/git
[root@localhost gitlab]# chown -R git log/
[root@localhost gitlab]# chown -R git tmp/
[root@localhost gitlab]# chmod -R u+rwX log/
[root@localhost gitlab]# chmod -R u+rwX tmp/
[root@localhost gitlab]# sudo -u git -H mkdir /home/git/gitlab-satellites
[root@localhost gitlab]# sudo chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
[root@localhost gitlab]# chmod -R u+rwX tmp/pids/
[root@localhost gitlab]# chmod -R u+rwX tmp/sockets
[root@localhost gitlab]# chmod -R u+rwX public/uploads/
[root@localhost gitlab]# cp config/unicorn.rb.example  config/unicorn.rb
[root@localhost gitlab]# cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb


以上不存在的目录,手动创建。

配置数据库:

[root@localhost gitlab]# cp config/database.yml.mysql config/database.yml
[root@localhost gitlab]# vi config/database.yml
  9  database: gitlab       #这里的数据库要跟在mysql中创建的库名一致。
 10  pool: 10
 11  username: gitlab
 12  password: gitlab


九、安装gitlab-shell

[root@localhost ~]# cd /home/git/
[root@localhost git]# sudo -u git -H git clone   -b v2.6.0
[root@localhost git]# cd gitlab-shell/
[root@localhost gitlab-shell]# cp config.yml.example config.yml
[root@localhost gitlab-shell]# vi config.yml
  9      gitlab_url: http://localhost:8080/
  30   bin: /usr/bin/redis-cli
[root@localhostgitlab-shell]# sudo -u git -H ./bin/install


十、nginx安装

[root@localhost src]# tar -zxf pcre-8.38.tar.gz
[root@localhost src]# cd pcre-8.38
[root@localhostp cre-8.38]# ./configure --prefix=/usr/local/pcre-8.38 && make && make install
[root@localhost src]# wget http://124.205.69.171/files/8095000002FE839E/nginx.org/download/nginx-1.8.1.tar.gz
[root@localhost src]# tar -zxf nginx-1.8.1.tar.gz
[root@localhost src]# cd nginx-1.8.1
[root@localhost nginx-1.8.1]# ./configure  --prefix=/usr/local/nginx --user=git  --group=git--with-http_ssl_module  --with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.38/  && make  && make install


十一、安装需要的gems

[root@localhost ~]# cd /home/git/gitlab
[root@localhost gitlab]# sudo -u git -H bundle install --deployment --without development testpostgres aws


十二、初始化数据库

[root@localhost gitlab]# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production


十三、拷贝启动文件脚本及日志切割文件

[root@localhost gitlab]# cp lib/support/init.d/gitlab /etc/init.d/gitlab
[root@localhost gitlab]# cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
[root@localhost gitlab]# cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab


十四、设置git账号信息

[root@localhost gitlab]# sudo -u git -H "/usr/bin/git" config --global user.name  "GitLab"
[root@localhost gitlab]# sudo -u git -H "/usr/bin/git" config --global user.email "example@example.com"
[root@localhost gitlab]# sudo -u git -H "/usr/bin/git" config --global core.autocrlf "input"


十五、配置nginx

[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf
    upstream gitlab {
        server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
    }
    server {
        listen       80;
        server_name  localhost;
 
        access_log  /var/log/nginx/gitlab_access.log;
        error_log   /var/log/nginx/gitlab_error.log;
 
        root  /home/git/gitlab/public;
 
        location / {
            try_files $uri $uri/index.html $uri.html @gitlab;
        }
 
        location @gitlab {
            proxy_read_timeout 300;
            proxy_connect_timeout 300;
            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;
        }
 
}
[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R git:git/var/log/nginx/
[root@localhost ~]# chown -R git:git /usr/local/nginx/
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
[root@localhost gitlab]# service nginx restart


十六、检测当前环境

[root@localhostgitlab]# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production


可能会有报错:Error: Table 'gitlab.projects' doesn't exist

这时重新初始化数据库,执行以下命令:

[root@localhost gitlab]# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production


会发现,执行结束时生成了一个登录账号和密码:

login.........root
password......5iveL!fe 用来登录gitlab


再次执行环境检测命令……OK

十七、拉取gitlab静态资源文件

[root@localhost gitlab]# sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production


十八、启动gitlab

[root@localhost gitlab]# /etc/init.d/gitlab start
[root@localhost gitlab]# sudo chmod -R ug+rwX,o-rwx /home/git/repositories/
[root@localhost gitlab]# sudo chmod -R ug-s /home/git/repositories/
[root@localhost gitlab]# find /home/git/repositories/ -type d -print0 | sudo xargs -0 chmod g+s


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

[root@localhost gitlab]#sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production


错误一:Send ping to redisserver: Could not connect to Redis at /tmp/redis.sock: Permission denied

[root@localhost gitlab]#vi /home/git/gitlab-shell/config.yml
35   #socket: /tmp/redis.sock # Comment out thisline if you want to use TCP

错误二:用浏览器访问时,出现“502 Bad Gateway

编译nginx时指定 --user=git --group=git

[root@localhost ~]# vi/usr/local/nginx/conf/nginx.conf
  2 user git;



相关内容

热门资讯

伊朗官员称已与阿曼就霍尔木兹海... △当地时间8月5日,霍尔木兹海峡总台记者当地时间7日获悉,伊朗议会国家安全与外交政策委员会发言人哈桑...
“贴耳大吼、扇巴掌”?新生儿入... 近日,四川成都一新生儿入住月子会所仅4天,突发颅内出血被送进ICU一事引发关注。孩子的母亲周女士反映...
特朗普称将就上诉法院涉白宫宴会... △特朗普(资料图)当地时间8月7日,美国总统特朗普在社交平台“真实社交”发文称,将立即就联邦上诉法院...
高景太阳能申请背接触电池前板专... 国家知识产权局信息显示,四川高景太阳能科技有限公司申请一项名为“背接触电池前板、其制备方法及光伏电池...
宿迁市政府领导专题调研江苏省宿... 8月6日,宿迁市副市长陈伟赴江苏省宿迁环境监测中心,专题调研“人工智能+监测”工作开展情况。宿迁市生...
科技改变生活:普通人如何抓住A... 听着, 科技这个词给人的感觉那可是相当的高大上, 就好像它仅仅是属于实验室里头的科学家或者硅谷的那些...
鼓励领导干部带头休假之后又撤回... 近日,河南省委组织部、省人力资源社会保障厅、省商务厅、省文化和旅游厅、省政府国资委、省总工会近日联合...
耗资4亿美元,特朗普的白宫宴会... 据路透社8月7日报道,美国一家联邦上诉法院于本周五下达指令,要求特朗普政府停止在已拆除的白宫东翼旧址...
胡锡进:新西兰外长像只疯狗,竟... 新西兰这几年出了一个对华非常恶毒的外交部长,他叫温斯顿·彼得斯,81岁。他给中新关系带来了与前些年截...
霍尔木兹协议将近达成,美伊正在... 关于霍尔木兹局势有哪些最新消息?凤凰卫视驻伊朗记者李睿从德黑兰发回报道:伊朗与阿曼就霍尔木兹海峡的协...