gitlab


gitlab是一個基於ruby的開源項目,可以實現git倉庫的功能,可以在網頁上直接瀏覽本身的代碼,下面主要介紹一下部署的過程,主要分爲以下幾個大步驟:
javascript

一、提供一些必須包,提供epel,關閉防火牆和selinux等操做;html

二、gitlab依賴的python功能比較多,須要升級python到2.7.X;java

三、安裝redis的內存數據庫;node

四、安裝MySQL的關係型數據庫;python

五、爲gitlab提供ruby的環境支持;mysql

六、提供gitlab-shell來管理git倉庫;linux

七、安裝gitlab系統;nginx

八、安裝nginx的web服務,作反向代理。c++

1、修改yum源爲阿里雲提升下載速度

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

2、安裝依賴包

yum -y install libicu-devel patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make \
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 cmake \ 
pcre-devel nodejs postfix mysql-devel libmysql-ruby libmysqlclient-dev

3、安裝git

3.1 查看git當前版本git

"# git --version"
   git version 1.7.1

3.2 若是版本小於1.7.10卸載

rpm -e --nodeps git

3.3 下載最新git源碼包並編譯安裝

cd /usr/local/src/
wget https://www.kernel.org/pub/software/scm/git/git-2.6.2.tar.xz
tar Jxf git-2.6.2.tar.xz
cd git-2.6.2
./configure --prefix=/usr/local/git
make
make install
echo 'export PATH=/usr/local/git/bin:$PATH' >> /etc/profile

4、安裝Python

cd /usr/local/src/
wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tar.xz
tar Jxf Python-2.7.10.tar.xz
cd Python-2.7.10
./configure --prefix=/usr/local/python
make
make install
echo 'export PATH=/usr/local/python/bin:$PATH' >> /etc/profile

5、安裝Ruby

cd /usr/local/src
wget https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.3.tar.gz
tar zxf ruby-2.2.3.tar.gz
cd ruby-2.2.3
./configure --prefix=/usr/local/ruby --disable-install-rdoc
make && make install
echo 'export PATH=/usr/local/ruby/bin:$PATH' >> /etc/profile

5.1 退出Shell從新登陸後修改RubyGems鏡像爲淘寶,提升下載速度

cd /usr/local/src
gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/ 
gem install bundler --no-ri --no-rdoc

6、安裝Go

cd /usr/local/src
wget https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz
tar -zxvf go1.6.linux-amd64.tar.gz
mv go /usr/local/
cd /usr/local/go
cat >> /etc/profile << EOF
> export GOROOT=/usr/local/go
> export GOARCH=amd64
> export GOOS=linux
> export GOBIN=\$GOROOT/bin
> export GOPATH=/usr/local/go
> export PATH=$GOBIN:\$PATH
> EOF

7、安裝Redis

cd /usr/local/src/
wget http://download.redis.io/releases/redis-3.0.7.tar.gz
tar -zxvf redis-3.0.7.tar.gz
cd redis-3.0.7
make PREFIX=/usr/local/redis install
echo 'export PATH=/usr/local/redis/bin:$PATH' >> /etc/profile

7.1 添加redis配置/usr/loca/redis/redis.conf

vim /usr/local/redis/redis.conf
daemonize yes
pidfile /usr/local/redis/redis.pid
port 6379
tcp-backlog 60000
timeout 0
tcp-keepalive 60
loglevel warning
logfile "/usr/local/redis/redis.log"
syslog-enabled no
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /usr/local/redis
slave-serve-stale-data yes
repl-diskless-sync yes
repl-diskless-sync-delay 5
repl-ping-slave-period 10
repl-timeout 60
repl-disable-tcp-nodelay no
slave-priority 100
maxclients 60000
maxmemory-policy noeviction
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

7.2 啓動Redis

/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf 
netstat -anpt|grep redis"
tcp     0      0 0.0.0.0:6379       0.0.0.0:*            LISTEN      16834/redis-server

8、安裝配置MariaDB

cd /usr/local/src/
wget http://mirrors.ctyun.cn/MariaDB/mariadb-10.0.21/source/mariadb-10.0.21.tar.gz
tar zxf mariadb-10.0.21.tar.gz
cd mariadb-10.0.21
cmake . \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mariadb \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EMBEDDED_SERVER:BOOL=OFF \
-DWITH_UNIT_TESTS:BOOL=OFF \
-LAH
make && make install
cp support-files/mysql.server /etc/init.d/mariadb
chmod u+x /etc/init.d/mariadb
echo 'export PATH=/App/mariadb/bin:$PATH' >> /etc/profile

8.1 修改MariaDB配置/etc/my.cnf

vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
user = mysql
port = 3306
socket = /tmp/mysql.sock
server-id = 1
log-bin = bin.log
log-error = error.log
pid-file = mysql.pid
long_query_time = 1
slow_query_log
slow_query_log_file = slow.log
binlog_cache_size = 4M
binlog_format = mixed
max_binlog_cache_size = 16M
max_binlog_size = 1G
expire_logs_days = 30
ft_min_word_len = 4
back_log = 4096
max_allowed_packet = 64M
max_connections = 65536
max_connect_errors = 100
join_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
sort_buffer_size = 1M
query_cache_size = 64M
table_open_cache = 2048
thread_cache_size = 256
max_heap_table_size = 64M
tmp_table_size = 64M
thread_stack = 192K
connect_timeout = 600
interactive_timeout = 600
wait_timeout = 600
thread_concurrency = 8
local-infile = 0
skip-show-database
skip-name-resolve
skip-external-locking
#*** MyISAM
key_buffer_size = 512M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 32M
myisam_max_sort_file_size = 1G
myisam_repair_threads = 1
myisam_recover
#*** INNODB
innodb_buffer_pool_size = 4G
innodb_additional_mem_pool_size = 32M
innodb_data_file_path = ibdata:32M:autoextend
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 120
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 10
innodb_thread_concurrency = 16
#innodb_force_recovery = 4
#*** Replication Slave
#read-only
#skip-slave-start
relay-log = relay.log
log-slave-updates
[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 60000

8.2 初始化MariaDB

useradd -s /bin/false -M mysql
/usr/local/mariadb/scripts/mysql_install_db --basedir=/usr/local/mariadb --datadir=/usr/local/mariadb/data --user=mysql

8.3 啓動MaridDB

/etc/init.d/mariadb start

8.4 登陸MaridDB建立數據庫並受權

mysql -uroot -p 
mysql> CREATE DATABASE `gitlabhq_production`;
mysql> GRANT ALL ON `gitlabhq_production`.* TO 'git'@'127.0.0.1' IDENTIFIED BY 'PASSWORD';\
mysql> FLUSH PRIVILEGES;

9、安裝配置gitlab

9.1 建立用戶

useradd --system -s /bin/bash --comment 'GitLab' -m -d /home/git git

9.2 修改git家目錄權限

chmod 755 /home/git/

9.3 切換爲git用戶

su - git
git clone https://gitlab.com/larryli/gitlab.git -b 8-0-zh gitlab

9.4 配置gitlab

cd gitlab/
cp config/gitlab.yml.example config/gitlab.yml

9.5 修改gitlab.yml將配置host:localhost修改成本機ip地址,bin_path: /usr/bin/git修改成bin_path: /usr/local/git/bin/git

vim config/gitlab.yml
    host: xxxxx
    bin_path: /usr/local/git/bin/git
   //說明: 該配置文件裏有兩個```host```都須要改成本機ip地址

9.6 新建測試目錄,拷貝實例文件,修改權限

mkdir -p /home/git/gitlab-satellites
cp /home/git/gitlab/config/secrets.yml.example /home/git/gitlab/config/secrets.yml
chmod 0600 config/secrets.yml
chmod -R u+rwX,go-w log/
chmod -R u+rwX tmp/
chmod -R u+rwX tmp/pids/
chmod -R u+rwX tmp/sockets/
chmod -R u+rwX public/uploads/
chmod 0750 public/uploads/
chmod -R ug+rwX,o-rwx /home/git/gitlab-satellites/
chmod -R ug-s /home/git/gitlab-satellites/
find /home/git/gitlab-satellites/ -type d -print0 | xargs -0 chmod g+s
cp config/unicorn.rb.example config/unicorn.rb
cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
git config --global core.autocrlf input
cp config/resque.yml.example config/resque.yml

9.7 修改Redis相關配置config/resque.yml文件

vim /home/git/gitlab/config/resque.yml
    production: redis://127.0.0.1:6379      //說明: 需改後的樣子

9.8 數據庫配置

cp /home/git/gitlab/config/database.yml.mysql /home/git/gitlab/config/database.yml
chmod o-rwx config/database.yml
vim /home/git/gitlab/config/database.yml
     username: git
     password: PASSWORD
     host: 127.0.0.1
     //說明: 以上是修改後的配置內容

9.9 修改Gemfile手行內容

vim /home/git/gitlab/Gemfile
    source "https://ruby.taobao.org"      //說明: 修改後的配置文件.
bundle install --deployment --without development test postgres aws kerberos

10、安裝GitLab Shell

bundle exec rake gitlab:shell:install[v2.6.6] REDIS_URL=redis://127.0.0.1:6379 RAILS_ENV=production

11、安裝gitlab-git-http-server

cd /home/git
git clone https://gitlab.com/gitlab-org/gitlab-git-http-server.git
cd gitlab-git-http-server
git checkout 0.3.0
make

12、切換爲root用戶後拷貝服務腳步

12.1 拷貝gitlab腳步

cp /home/git/gitlab/lib/support/init.d/gitlab /etc/init.d/

12.2 root權限配置Logrotate

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

12.3 初始化數據庫並激活GITLAB_ROOT_PASSWORD值爲管理員 root 登陸密碼本例設爲newpassword

pwd
/home/git/gitlab
bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=newpassword

12.4 檢查應用狀態

su - git
cd gitlab
bundle exec rake gitlab:env:info RAILS_ENV=production

12.5 編譯靜態文件

bundle exec rake assets:precompile RAILS_ENV=production

十3、安裝Nginx

13.1 下載Nginx

cd /usr/local/src/
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar zxf nginx-1.8.0.tar.gz
cd nginx-1.8.0
      ./configure \
      --prefix=/usr/local/nginx \
      --with-http_stub_status_module \
      --with-http_gzip_static_module \
      --with-http_ssl_module \
      --with-http_realip_module 

make && make install
useradd -s /bin/false nginx

13.2 配置Nginx

user     root;
worker_processes  16;
worker_rlimit_nofile 512000;
pid    /a8root/logs/nginx.rewrite/nginx.pid;

events {
        use epoll;
        worker_connections  512000;
}

http {
        include       mime.types;
        default_type  application/octet-stream;
        client_header_buffer_size   4k;
        client_body_buffer_size 10M;
        client_max_body_size 4M;
        large_client_header_buffers 4 4k;
        tcp_nopush on;
        tcp_nodelay on;
        sendfile on;
        keepalive_timeout  60;
        gzip on;
        gzip_proxied any;
        gzip_min_length 2048;
        gzip_buffers 4 8k;
        gzip_comp_level 4;
        gzip_types text/plain textml text text/xml application/xml application/json application/javascript application/octet-stream *;


        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';

        upstream gitlab {

          server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;

        }

        server {

             listen *:80 default_server;       # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
             server_name YOUR_SERVER_FQDN;     # e.g., server_name source.example.com;

             server_tokens off;                # don't show the version number, a security best practice
             root /home/git/gitlab/public;

             client_max_body_size 5m;

             access_log  /a8root/logs/nginx.rewrite/gitlab_access.log;
             error_log   /a8root/logs/nginx.rewrite/gitlab_error.log;

             location / {
                 try_files $uri $uri/index.html $uri.html @gitlab;
             }


             location @gitlab {

                 proxy_read_timeout 300;    # https://github.com/gitlabhq/gitlabhq/issues/694
                 proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
                 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;

             }
        }
    }

十4、SMTP相關配置

配置企業郵箱的stmp來發送郵件

[git@gitlab ~]$ cd gitlab
[git@gitlab gitlab]$ pwd
/home/git/gitlab
[git@gitlab gitlab]$ vim config/environments/production.rb

在#config.action_mailer.delivery_method = :sendmail下加入
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.smtp_settings = {
        :address              => "smtp.exmail.qq.com",
        :port                 => 25,
        :domain               => 'meelive.cn',
        :user_name            => 'register@meelive.cn',
        :password             => 'password',
        :authentication       => :plain,
        :enable_starttls_auto => true
  }

[git@gitlab gitlab]$ vim config/gitlab.yml
 # Email settings
 # Uncomment and set to false if you need to disable email sending from GitLab (default:true)
   email_enabled: true
   #Email address used in the "From" field in mails sent by GitLab
   #email_from: example@example.com
   email_from: register@meelive.cn
   protocol: http
   email_display_name: GitLab
   email_reply_to: noreply@example.com

十5、啓動GitLab實例

/etc/init.d/gitlab start

十6、瀏覽器打開登陸頁面

用戶名爲root,密碼爲newpassword

參考自: 90root gitlab中文部署文檔
參考自: 中文部署文檔

相關文章
相關標籤/搜索