简单安装
一, 服务器快速搭建gitlab方法
可以参考gitlab中文社区 的教程
centos7安装gitlab:https://www.gitlab.cc/downloads/#centos7
centos6安装gitlab:https://www.gitlab.cc/downloads/#centos6
如下方法按照官网来操作,手工安装过于麻烦。测试机器:阿里云centos6.8机器。
1. 安装配置依赖项
[root@puppet ~]# yum install openssh-server -y
[root@puppet ~]# yum install postfix -y
- wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-XXX.rpm
- rpm -ivh gitlab-ce-XXX.rpm
下载不了直接打开链接 https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
说明:个人平时喜欢采用如上方式的rpm安装centos (内核7.x)https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7 (centos (内核6.x)https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6,
选择需要的版本进行安装。老版本用习惯了,用的是一种情怀,有些功能新版本不是很喜欢用,请根据自己个人喜好来安装。
本人用的是centos6.5 所以下载
安装
rpm -ivh gitlab-ce-10.0.0-ce.0.el6.x86_64.rpm
注意事项以及异常故障排查:
首先就是端口占用问题,gitlab 启动会使用 80 端口,所以建议你在启动 gitlab 前先将不需要的服务都关掉,或者修改默认端口:
sudo vim /etc/gitlab/gitlab.rb
修改external_url,直接增加端口号即可,比如我这里用8800端口:
external_url 'http://localhost:8800'
然后执行:
sudo gitlab-ctl reconfigure
除了 80 这个端口外,还有一个unicorn用的端口,默认是8080,如果8080端口被其他程序占用。那么unicorn就会无法启动,显示为502错误,”GitLab is not responding”。
解决办法:修改 /etc/gitlab/gitlab.rb
unicorn['listen'] = '127.0.0.1' unicorn['port'] = 8801
最终用的配置是
external_url 'http://192.168.0.119:83'
nginx['listen_address'] = '192.168.0.119'
unicorn['port'] = 83
访问就可以了
gitlab-ctl start gitlab-ctl stop gitlab-ctl status gitlab-ctl restartvim /etc/gitlab/gitlab.rb
gitlab-ctl reconfigure
Omnibus 包安装 GitLab
http://www.21yunwei.com/archives/4351
http://peiqiang.net/2014/07/30/install-gitlab.html
http://blog.csdn.net/hustpzb/article/details/8230454/
源码安装
一、环境
gitlab的安装说明https://github.com/lubia/gitlab-recipes/tree/master/install/centos
系统:CentOS6.4最小化安装
gitlab 5.2.0
centos64
Redis 2.6.13
nginx-1.4.1
mysql-
gitlab中文使用指南:GitLab使用介绍
首先我们选择比较快的yum源,不然安装速度会非常的慢的.这里使用中国科技大学的yum源http://lug.ustc.edu.cn/wiki/mirrors/help/centos更换yum源方法参考:http://blog.haohtml.com/archives/5669,
三。默认安装的git版本可能会低一些,需要升级到最新版本才可以.
yum -y
install
readline-devel gdbm-devel ncurses-devel openssl-devel zlib-devel
gcc
gcc
-c++
make
autoconf curl-devel expat-devel gettext-devel tk-devel libxml2-devel libffi-devel libxslt-devel libicu-devel git-all python-devel vim
sudo
四、安装git
删除系统默认的git,使用源码安装git
[root@gitlab ~]
# git --version
git version 1.7.1
[root@gitlab ~]
# yum remove git -y
#下载源码安装包
[root@gitlab ~]
# wget https://www.kernel.org/pub/software/scm/git/git-2.1.3.tar.gz
[root@gitlab ~]
# tar zxf git-2.1.3.tar.gz
[root@gitlab ~]
# cd git-2.1.3
[root@gitlab git-2.1.3]
# ./configure
[root@gitlab git-2.1.3]
# make && make prefix=/usr/local install
[root@gitlab git-2.1.3]
# ln -s /usr/local/bin/git /usr/bin/
[root@gitlab git-2.1.3]
# git --version
git version 2.1.3
删除系统自带的ruby环境,确保ruby是2.0以上的版本
[root@gitlab ~]
# yum remove ruby -y
#下载ruby安装包,最少2.0以上
[root@gitlab ~]
# wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-2.1.2.tar.gz
[root@gitlab ~]
# tar zxvf ruby-2.1.2.tar.gz
[root@gitlab ~]
# cd ruby-2.1.2
[root@gitlab ruby-2.1.2]
#./configure --prefix=/usr/local/
[root@gitlab ruby-2.1.2]
# make && make install
安装bundler
[root@gitlab ruby-2.1.2]
# gem install bundler --no-doc
六、创建git用户
[root@gitlab ~]
# adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
查看mysql安装结果
1
2
|
[root@gitlab ~]
# mysql --version
mysql Ver 14.14 Distrib 5.5.37,
for
Linux (x86_64) using EditLine wrapper
|
创建数据库并授权
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
[root@gitlab ~]
# mysql -u root -p -h 127.0.0.1
Enter password:
#这里的密码是我的安装脚本中提供的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection
id
is 6
Server version: 5.5.37 Source distribution
Copyright (c) 2000, 2014, Oracle and
/or
its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and
/or
its
affiliates. Other names may be trademarks of their respective
owners.
Type
'help;'
or
'\h'
for
help. Type
'\c'
to
clear
the current input statement.
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO
'git'
@
'localhost'
IDENTIFIED BY
'gitpasswd'
;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql>
select
user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *B181A5BCA7C882221F5B8F6F9657AE71FF67EDDB |
| root | 127.0.0.1 | *B181A5BCA7C882221F5B8F6F9657AE71FF67EDDB |
| git | localhost | *6EA0EDE421A05E610ADBFC5D47B93B6E06C6216F |
+------+-----------+-------------------------------------------+
3 rows
in
set
(0.00 sec)
|
测试新建的用户能否登陆mysql
[root@gitlab ~]
# mysql -u git -p -h localhost
Enter password:
#这里的密码是上文中给定的gitpasswd
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection
id
is 8
Server version: 5.5.37 Source distribution
Copyright (c) 2000, 2014, Oracle and
/or
its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and
/or
its
affiliates. Other names may be trademarks of their respective
owners.
Type
'help;'
or
'\h'
for
help. Type
'\c'
to
clear
the current input statement.
mysql> show databases;
+---------------------+
| Database |
+---------------------+
| information_schema |
| gitlabhq_production |
|
test
|
+---------------------+
3 rows
in
set
(0.00 sec)
安装redis 及 配置redis
安装redis
[root@gitlab ~]
# chkconfig redis on
[root@gitlab ~]
# /etc/init.d/redis start
Starting redis-server: [ OK ]
[root@gitlab ~]
# netstat -anpt |grep redis
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 8755
/redi
九、安装gitlab
[root@gitlab ~]
# cd /home/git/
[root@gitlab git]
# sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-4-stable gitlab
Cloning into
'gitlab'
...
remote: Counting objects: 127971,
done
.
remote: Compressing objects: 100% (32073
/32073
),
done
.
remote: Total 127971 (delta 97845), reused 123442 (delta 94050)
Receiving objects: 100% (127971
/127971
), 81.35 MiB | 1.63 MiB
/s
,
done
.
Resolving deltas: 100% (97845
/97845
),
done
.
Checking connectivity...
done
.
#修改配置文件
[root@gitlab git]
# cd gitlab/
[root@gitlab gitlab]
# sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
#下面这条命令可以不用操作,保持默认即可
[root@gitlab gitlab]
# sudo -u git -H vim config/gitlab.yml
gitlab:
## Web server settings (note: host is the FQDN, do not include http://)
host: www.gitlab.com
#这里设置的域名是为后面的postfix使用的,在后文中的gitlab.conf站点配置文件中也是使用的这个域名,普通用户访问gitlab使用这个域名
port: 80
https:
false
#修改相应的目录权限
[root@gitlab gitlab]
# chown -R git log/
[root@gitlab gitlab]
# chown -R git tmp/
[root@gitlab gitlab]
# chmod -R u+rwX log/
[root@gitlab gitlab]
# chmod -R u+rwX tmp/
[root@gitlab gitlab]
# chmod -R u+rwX tmp/pids/
[root@gitlab gitlab]
# chmod -R u+rwX tmp/sockets/
[root@gitlab gitlab]
# chmod -R u+rwX public/uploads
#创建目录
[root@gitlab gitlab]
# sudo -u git -H mkdir /home/git/gitlab-satellites
[root@gitlab gitlab]
# chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
编辑配置文件unicorn.rb
[root@gitlab gitlab]
# sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
[root@gitlab gitlab]
# nproc
1
[root@gitlab gitlab]
# sudo -u git -H vim config/unicorn.rb
worker_processes 1
#复制配置文件rack_attack.rb
[root@gitlab gitlab]
# sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
#定义全局的用户和邮箱
[root@gitlab gitlab]
# sudo -u git -H git config --global user.name "GitLab"
[root@gitlab gitlab]
# sudo -u git -H git config --global user.email "gitlab@weyee.com"
[root@gitlab gitlab]
# sudo -u git -H git config --global core.autocrlf input
#编辑连接redis的配置
[root@gitlab gitlab]
# sudo -u git -H cp config/resque.yml.example config/resque.yml
[root@gitlab gitlab]
# sudo -u git -H vim config/resque.yml
development: redis:
//localhost
:6379
test
: redis:
//localhost
:6379
production: unix:
/var/run/redis/redis
.sock
十、编辑gitlab数据库文件
[root@gitlab gitlab]
# sudo -u git cp config/database.yml.mysql config/database.yml
[root@gitlab gitlab]
# sudo -u git -H vim config/database.yml
production:
adapter: mysql2
encoding: utf8
collation: utf8_general_ci
reconnect:
false
database: gitlabhq_production
pool: 10
username: git
password:
"gitpasswd"
#修改数据库文件权限
[root@gitlab gitlab]
# sudo -u git -H chmod o-rwx config/database.yml
十一、安装gem
#添加淘宝的ruby源
[root@gitlab gitlab]
# sudo -u git vim Gemfile
source
"https://ruby.taobao.org"
#将第一行修改成taobao的源
gitlab]
# sudo -u git vim Gemfile
.lock
remote: https://ruby.taobao.org/:wq:wq
[root@gitlab gitlab]
# cd /home/git/gitlab
[root@gitlab gitlab]
# ln -s /usr/local/bin/bundle /usr/bin/
[root@gitlab gitlab]
# sudo -u git -H bundle install --deployment --without development test postgres aws
Results logged to
/home/git/gitlab/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0-static/charlock_holmes-0.6.9.4/gem_make.out
An error occurred while installing charlock_holmes (0.6.9.4), and Bundler cannot continue.
Make sure that `gem install charlock_holmes -v '0.6.9.4'` succeeds before bundling.
解决 错误
gem list
看看 是不是已经装了 版本不一样
charlock_holmes-0.6.9.4
卸载到 gem uninstall charlock_holmes
安装
sudo gem install charlock_holmes -v '0.6.9.4'
Gem files will remain installed in /home/git/gitlab/vendor/bundle/ruby/2.1.0/gems/mysql2-0.3.16 for inspection.
Results logged to /home/git/gitlab/vendor/bundle/ruby/2.1.0/extensions/x86_64-linux/2.1.0-static/mysql2-0.3.16/gem_make.out
An error occurred while installing mysql2 (0.3.16), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.16'` succeeds before bundling.
mysql2 错误
Make sure that `gem install mysql2 -v '0.3.16'` succeeds before bundling.
解决
gem install mysql2 -v '0.3.16'`
yum install mysql-devel
十二、安装gitlab-shell
[root@gitlab gitlab]
# ln -s /usr/local/bin/ruby /usr/bin/ruby
[root@gitlab gitlab]
# sudo -u git -H bundle exec rake gitlab:shell:install[v2.0.1] REDIS_URL=unix:/var/run/redis redis.sock RAILS_ENV=production
git clone
'https://gitlab.com/gitlab-org/gitlab-shell.git'
'/home/git/gitlab-shell/'
Cloning into
'/home/git/gitlab-shell'
...
remote: Counting objects: 2118,
done
.
remote: Compressing objects: 100% (1639
/1639
),
done
.
remote: Total 2118 (delta 1301), reused 710 (delta 400)
Receiving objects: 100% (2118
/2118
), 306.39 KiB | 177.00 KiB
/s
,
done
.
Resolving deltas: 100% (1301
/1301
),
done
.
Checking connectivity...
done
.
git reset --hard $(git describe v2.0.1 || git describe origin
/v2
.0.1) || git fetch origin && git reset --hard $(git describe v2.0.1 || git describe origin
/v2
.0.1)
HEAD is now at a3b5445 Fix bug when changes to post-receive worker was not dumped properly
HEAD is now at a3b5445 Fix bug when changes to post-receive worker was not dumped properly
bin
/install
mkdir
-p
/home/git/repositories/
: OK
mkdir
-p
/home/git/
.
ssh
: OK
chmod
700
/home/git/
.
ssh
: OK
touch
/home/git/
.
ssh
/authorized_keys
: OK
chmod
600
/home/git/
.
ssh
/authorized_keys
: OK
chmod
-R ug+rwX,o-rwx
/home/git/repositories/
: OK
find
/home/git/repositories/
-
type
d -
exec
chmod
g+s {} ;: OK
#gitlab-shell配置文件内容
[root@gitlab gitlab]
# sudo -u git -H vim /home/git/gitlab-shell/config.yml
---
user: git
gitlab_url: https:
//localhost/
#使用https
http_settings:
self_signed_cert:
true
#修改成true
repos_path:
"/home/git/repositories/"
auth_file:
"/home/git/.ssh/authorized_keys"
redis:
bin:
"/usr/bin/redis-cli"
namespace: resque:gitlab
socket:
"/var/run/redis/redis.sock"
log_level: INFO
audit_usernames:
false
十三、初始化数据库
[root@gitlab gitlab]
# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
This will create the necessary database tables and seed the database.
You will lose any previous data stored
in
the database.
Do you want to
continue
(
yes
/no
)?
yes
#输入yes
十四、下载服务脚本
[root@gitlab gitlab]
# wget -O /etc/init.d/gitlab https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn
#配置gitlab的启动级别
[root@gitlab gitlab]
# chmod +x /etc/init.d/gitlab
[root@gitlab gitlab]
# chkconfig --add gitlab
[root@gitlab gitlab]
# chkconfig gitlab on
#配置logrotate
[root@gitlab gitlab]
# cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
#检测gitlab的应用支持状态,并配置
[root@gitlab gitlab]
# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
System information
System:
Current User: git
Using RVM: no
Ruby Version: 2.1.2p95
Gem Version: 2.2.2
Bundler Version:1.9.7
Rake Version: 10.3.2
Sidekiq Version:2.17.0
GitLab information
Version: 7.4.5
Revision: 19d572e
Directory:
/home/git/gitlab
DB Adapter: mysql2
URL: http:
//localhost
HTTP Clone URL: http:
//localhost/some-project
.git
SSH Clone URL: git@localhost:some-project.git
Using LDAP: no
Using Omniauth: no
GitLab Shell
Version: 2.0.1
Repositories:
/home/git/repositories/
Hooks:
/home/git/gitlab-shell/hooks/
Git:
/usr/bin/git
[root@gitlab gitlab]
# sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
#启动gitlab服务
[root@gitlab gitlab]
# service gitlab start
Starting unicorn: [ OK ]
Starting sidekiq: [ OK ]
十五、安装nginx服务,并下载gitlab的站点配置文件
这里的nginx使用yum进行安装
[root@gitlab gitlab]
# yum install -y nginx
No package nginx available. 解决:
http://blog.chinaunix.net/uid-29612873-id-4226804.html
[root@gitlab gitlab]
# chkconfig nginx on
[root@gitlab gitlab]
# wget -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab-ssl
[root@gitlab gitlab]
# usermod -a -G git nginx
[root@gitlab gitlab]
# chmod g+rx /home/git/
[root@gitlab gitlab]
# vim /etc/nginx/conf.d/gitlab.conf
#编辑文件/etc/nginx/conf.d/gitlab.conf,修改其中的serve_rname
server_name www.gitlab.com
[root@gitlab gitlab]
# mkdir -p /etc/nginx/ssl
[root@gitlab gitlab]
# cd /etc/nginx/ssl/
[root@gitlab gitlab]
# openssl req -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
启动nginx服务
[root@gitlab gitlab]
# service nginx start
cd
/home/git/gitlab
[root@git gitlab]
#sudo -u git -H cp config/initializers/smtp_settings.rb.sample config/initializers/smtp_setting.rb
#修改如下
[root@git gitlab]
#sudo -u git -H vim config/initializers/smtp_settings.rb
if
Rails.
env
.production?
Rails.application.config.action_mailer.delivery_method = :smtp
ActionMailer::Base.delivery_method = :smtp
#使用smtp方法
ActionMailer::Base.smtp_settings = {
address:
"smtp.163.com"
,
port: 25,
user_name:
"xxx"
,
#用户名
password:
"xxxx"
,
#密码
domain:
"163.com"
,
authentication: :login,
enable_starttls_auto:
true
,
#openssl_verify_mode: 'peer' # See ActionMailer documentation for other possible options
}
end
#编辑文件
[root@git gitlab]
#sudo -u git -H vim config/environments/production.rb
config.action_mailer.delivery_method = :smtp
#将方法修改成smtp方式