installation.md 9.5 KB
Newer Older
D
Dmitriy Zaporozhets 已提交
1
## Platform requirements: 
V
Valery Sizov 已提交
2

3
**The project is designed for the Linux operating system.**
D
Dmitriy Zaporozhets 已提交
4 5 6

It may work on FreeBSD and Mac OS, but we don't test our application for these systems and can't guarantee stability and full functionality.

7
We officially support (recent versions of) these Linux distributions:
D
Dmitriy Zaporozhets 已提交
8

9 10
- Ubuntu Linux
- Debian/GNU Linux
D
Dmitriy Zaporozhets 已提交
11 12 13 14 15

It should work on:

- Fedora
- CentOs
16
- RedHat
D
Dmitriy Zaporozhets 已提交
17

18
You might have some luck using these, but no guarantees:
D
Dmitriy Zaporozhets 已提交
19

20
 - MacOS X
D
Dmitriy Zaporozhets 已提交
21 22
 - FreeBSD

23
Gitlab does **not** run on Windows and we have no plans of making Gitlab compatible.
D
Dmitriy Zaporozhets 已提交
24 25 26 27

## This installation guide created for Debian/Ubuntu and properly tested. 

The installation consists of 6 steps:
V
Valery Sizov 已提交
28

29 30 31 32 33 34 35 36 37 38 39 40
1. Install packages / dependencies
2. Install ruby
3. Install gitolite
4. Install and configure Gitlab.
5. Start the web front-end
6. Start a Resque worker (for background processing)

### IMPORTANT

Please make sure you have followed all the steps below before posting to the mailinglist with installation and configuration questions.

Only create a Github Issue if you want a specific part of this installation guide updated.
V
Valery Sizov 已提交
41

42
Also read the [Read this before you submit an issue](https://github.com/gitlabhq/gitlabhq/wiki/Read-this-before-you-submit-an-issue) wiki page.
V
Valery Sizov 已提交
43

D
Dmitriy Zaporozhets 已提交
44 45 46 47 48 49 50
> - - -
> First 3 steps can be easily skipped with simply install script:
> 
>     # Install curl and sudo 
>     apt-get install curl sudo
>     
>     # 3 steps in 1 command :)
51
>     curl https://raw.github.com/gitlabhq/gitlabhq/master/doc/debian_ubuntu.sh | sh
D
Dmitriy Zaporozhets 已提交
52 53 54
> 
> Now you can go to step 4"
> - - -
V
Valery Sizov 已提交
55 56 57

# 1. Install packages

D
Dmitriy Zaporozhets 已提交
58
*Keep in mind that `sudo` is not installed for debian by default. You should install it with as root:*     **apt-get update && apt-get upgrade && apt-get install sudo**
V
Valery Sizov 已提交
59 60 61 62 63

    sudo apt-get update
    sudo apt-get upgrade

    sudo apt-get install -y git-core wget curl gcc checkinstall libxml2-dev libxslt-dev sqlite3 libsqlite3-dev libcurl4-openssl-dev libreadline-dev libc6-dev libssl-dev libmysql++-dev make build-essential zlib1g-dev libicu-dev redis-server openssh-server git-core python-dev python-pip sendmail
64 65 66
    
    # If you want to use MySQL:
    sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
V
Valery Sizov 已提交
67 68 69 70

# 2. Install ruby

    wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p290.tar.gz
71
    tar xzfv ruby-1.9.2-p290.tar.gz
V
Valery Sizov 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    cd ruby-1.9.2-p290
    ./configure
    make
    sudo make install

# 3. Install gitolite

Create user for git:
    
    sudo adduser \
      --system \
      --shell /bin/sh \
      --gecos 'git version control' \
      --group \
      --disabled-password \
      --home /home/git \
      git

Create user for gitlab:
91

V
Valery Sizov 已提交
92 93 94 95
    # ubuntu/debian
    sudo adduser --disabled-login --gecos 'gitlab system' gitlab    

Add your user to git group:
96

V
Valery Sizov 已提交
97 98 99
    sudo usermod -a -G git gitlab

Generate key:
100

V
Valery Sizov 已提交
101 102
    sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa

D
Dmitriy Zaporozhets 已提交
103
Get gitolite source code:
104

V
Valery Sizov 已提交
105 106 107 108
    cd /home/git
    sudo -H -u git git clone git://github.com/gitlabhq/gitolite /home/git/gitolite    

Setup:
109

V
Valery Sizov 已提交
110 111 112 113 114 115
    sudo -u git -H /home/git/gitolite/src/gl-system-install
    sudo cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub
    sudo chmod 777 /home/git/gitlab.pub

    sudo -u git -H sed -i 's/0077/0007/g' /home/git/share/gitolite/conf/example.gitolite.rc
    sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gl-setup -q /home/git/gitlab.pub"
116
    
V
Valery Sizov 已提交
117
Permissions:
118

V
Valery Sizov 已提交
119 120 121 122 123 124 125 126 127 128 129 130
    sudo chmod -R g+rwX /home/git/repositories/
    sudo chown -R git:git /home/git/repositories/

#### CHECK: Logout & login again to apply git group to your user
    
    # clone admin repo to add localhost to known_hosts
    # & be sure your user has access to gitolite
    sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin 

    # if succeed  you can remove it
    sudo rm -rf /tmp/gitolite-admin 

131
**IMPORTANT! If you cant clone `gitolite-admin` repository - DONT PROCEED INSTALLATION**
V
Valery Sizov 已提交
132 133 134 135 136 137 138 139 140 141 142 143 144 145

# 4. Install gitlab and configuration. Check status configuration.

    sudo gem install charlock_holmes
    sudo pip install pygments
    sudo gem install bundler
    cd /home/gitlab
    sudo -H -u gitlab git clone git://github.com/gitlabhq/gitlabhq.git gitlab
    cd gitlab

    # Rename config files
    sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml

#### Select db you want to use
146

V
Valery Sizov 已提交
147 148 149 150 151 152
    # SQLite
    sudo -u gitlab cp config/database.yml.sqlite config/database.yml

    # Or 
    # Mysql
    sudo -u gitlab cp config/database.yml.example config/database.yml
D
Dmitriy Zaporozhets 已提交
153
    # Change username/password of config/database.yml  to real one
V
Valery Sizov 已提交
154 155

#### Install gems
156

V
Valery Sizov 已提交
157 158 159
    sudo -u gitlab -H bundle install --without development test --deployment

#### Setup DB
160

V
Valery Sizov 已提交
161 162 163 164
    sudo -u gitlab bundle exec rake db:setup RAILS_ENV=production
    sudo -u gitlab bundle exec rake db:seed_fu RAILS_ENV=production
    
Checking status:
165

166
    sudo -u gitlab bundle exec rake gitlab_status RAILS_ENV=production
V
Valery Sizov 已提交
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182


    # OUTPUT EXAMPLE
    Starting diagnostic
    config/database.yml............exists
    config/gitlab.yml............exists
    /home/git/repositories/............exists
    /home/git/repositories/ is writable?............YES
    remote: Counting objects: 603, done.
    remote: Compressing objects: 100% (466/466), done.
    remote: Total 603 (delta 174), reused 0 (delta 0)
    Receiving objects: 100% (603/603), 53.29 KiB, done.
    Resolving deltas: 100% (174/174), done.
    Can clone gitolite-admin?............YES
    UMASK for .gitolite.rc is 0007? ............YES

D
Dmitriy Zaporozhets 已提交
183
If you got all YES - congrats! You can go to next step.  
V
Valery Sizov 已提交
184 185 186

# 5. Server up

D
Dmitriy Zaporozhets 已提交
187
Application can be started with next command:
188

D
Dmitriy Zaporozhets 已提交
189
    # For test purposes 
V
Valery Sizov 已提交
190 191
    sudo -u gitlab bundle exec rails s -e production

D
Dmitriy Zaporozhets 已提交
192 193
    # As daemon
    sudo -u gitlab bundle exec rails s -e production -d
V
Valery Sizov 已提交
194 195 196 197 198 199 200 201 202

#  6. Run resque process (for processing queue).

    # Manually
    sudo -u gitlab bundle exec rake environment resque:work QUEUE=* RAILS_ENV=production BACKGROUND=yes

    # Gitlab start script
    ./resque.sh

D
Dmitriy Zaporozhets 已提交
203

204 205
**Ok - we have a working application now. **
**But keep going - there are some thing that should be done **
D
Dmitriy Zaporozhets 已提交
206

V
Valery Sizov 已提交
207 208 209 210 211 212 213
# Nginx && Unicorn

### Install Nginx

    sudo apt-get install nginx

## Unicorn
214

V
Valery Sizov 已提交
215 216
    cd /home/gitlab/gitlab
    sudo -u gitlab cp config/unicorn.rb.orig config/unicorn.rb
V
Valeriy Sizov 已提交
217
    sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D
V
Valery Sizov 已提交
218

D
Dmitriy Zaporozhets 已提交
219 220
Edit /etc/nginx/nginx.conf. Add next code to **http** section:

V
Valery Sizov 已提交
221 222 223 224 225
    upstream gitlab {
        server unix:/tmp/gitlab.socket;
    }

    server {
226 227
        listen YOUR_SERVER_IP:80;
        server_name gitlab.YOUR_SUBDOMAIN.com;
228
        root /home/gitlab/gitlab/public;
229 230 231 232 233 234 235 236
        
        # individual nginx logs for this gitlab vhost
        access_log  /var/log/nginx/gitlab_access.log;
        error_log   /var/log/nginx/gitlab_error.log;
        
        location / {
        # serve static files from defined root folder;.
        # @gitlab is a named location for the upstream fallback, see below
237
        try_files $uri $uri/index.html $uri.html @gitlab;
238
        }
239
        
240 241
        # if a file, which is not found in the root folder is requested, 
        # then the proxy pass the request to the upsteam (gitlab unicorn)
242
        location @gitlab {
243 244 245 246 247 248
          proxy_redirect     off;
          # you need to change this to "https", if you set "ssl" directive to "on"
          proxy_set_header   X-FORWARDED_PROTO http;
          proxy_set_header   Host              gitlab.YOUR_SUBDOMAIN.com:80;
          proxy_set_header   X-Real-IP         $remote_addr;
        
249
          proxy_pass http://gitlab;
V
Valery Sizov 已提交
250 251 252 253 254
        }

    }

mygitlab.com - change to your domain.
D
Dmitriy Zaporozhets 已提交
255

V
Valery Sizov 已提交
256
Restart nginx:
257

V
Valery Sizov 已提交
258
    /etc/init.d/nginx restart
D
Dmitriy Zaporozhets 已提交
259

V
Valery Sizov 已提交
260
Create init script in /etc/init.d/gitlab:
261

V
Valery Sizov 已提交
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
    #! /bin/bash
    ### BEGIN INIT INFO
    # Provides:          unicorn
    # Required-Start:    $local_fs $remote_fs $network $syslog
    # Required-Stop:     $local_fs $remote_fs $network $syslog
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: starts the unicorn web server
    # Description:       starts unicorn
    ### END INIT INFO
    
    DAEMON_OPTS="-c /home/gitlab/gitlab/config/unicorn.rb -E production -D"
    NAME=unicorn
    DESC="Gitlab service"
    PID=/home/gitlab/gitlab/tmp/pids/unicorn.pid
277
    RESQUE_PID=/home/gitlab/gitlab/tmp/pids/resque_worker.pid
V
Valery Sizov 已提交
278 279 280 281 282

    case "$1" in
      start)
            CD_TO_APP_DIR="cd /home/gitlab/gitlab"
            START_DAEMON_PROCESS="bundle exec unicorn_rails $DAEMON_OPTS"
D
Dmitriy Zaporozhets 已提交
283
            START_RESQUE_PROCESS="./resque.sh"
V
Valery Sizov 已提交
284 285 286

            echo -n "Starting $DESC: "
            if [ `whoami` = root ]; then
D
Dmitriy Zaporozhets 已提交
287
              sudo -u gitlab sh -c "$CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS"
V
Valery Sizov 已提交
288
            else
289
              $CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS
V
Valery Sizov 已提交
290 291 292 293 294 295
            fi
            echo "$NAME."
            ;;
      stop)
            echo -n "Stopping $DESC: "
            kill -QUIT `cat $PID`
296
            kill -QUIT `cat $RESQUE_PID`
V
Valery Sizov 已提交
297 298 299 300 301
            echo "$NAME."
            ;;
      restart)
            echo -n "Restarting $DESC: "
            kill -USR2 `cat $PID`
302
            kill -USR2 `cat $RESQUE_PID`
V
Valery Sizov 已提交
303 304 305 306 307
            echo "$NAME."
            ;;
      reload)
            echo -n "Reloading $DESC configuration: "
            kill -HUP `cat $PID`
308
            kill -HUP `cat $RESQUE_PID`
V
Valery Sizov 已提交
309 310 311 312 313 314 315 316 317 318
            echo "$NAME."
            ;;
      *)
            echo "Usage: $NAME {start|stop|restart|reload}" >&2
            exit 1
            ;;
    esac

    exit 0

V
Valery Sizov 已提交
319
Adding permission:
320

V
Valery Sizov 已提交
321 322
    sudo chmod +x /etc/init.d/gitlab

V
Valery Sizov 已提交
323
When server is rebooted then gitlab must starting:
324

V
Valery Sizov 已提交
325 326
    sudo update-rc.d gitlab defaults

D
Dmitriy Zaporozhets 已提交
327
Now you can start/restart/stop gitlab like:
328

D
Dmitriy Zaporozhets 已提交
329
    sudo /etc/init.d/gitlab restart