资讯专栏INFORMATION COLUMN

centos6.2安装gitlab6.4

selfimpr / 3427人阅读

摘要:环境准备版本版本版本版本版本因系列的版本是的,已经支持,所以不必升级版本。

环境准备

python版本2.6
git版本 1.8.4.1
ruby版本ruby-2.0.0-p353
gitlab-shell版本 v1.8.0
gitlab版本6.4.3

因centos6系列的python版本是2.6的,已经支持,所以不必升级python版本。
在centos5下面需要升级python版本>2.5

安装epel的yum源

</>复制代码

  1. yum -y install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

安装必要的软件包

</>复制代码

  1. 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
安装git

因为git需要1.8版本以上,所以需要重新编译安装
移除当前git

</>复制代码

  1. yum remove git

下载1.8.4.1的git并安装

</>复制代码

  1. curl --progress https://git-core.googlecode.com/files/git-1.8.4.1.tar.gz | tar xz
  2. cd git-1.8.4.1/
  3. make prefix=/usr/local all
  4. make prefix=/usr/local install
  5. ln -fs /usr/local/bin/git* /usr/bin/
安装ruby环境

</>复制代码

  1. mkdir /tmp/ruby && cd /tmp/ruby
  2. curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz
  3. cd ruby-2.0.0-p353/
  4. ./configure --disable-install-rdoc
  5. make && make install
  6. gem install bundler --no-ri --no-rdoc
  7. ln -s /usr/local/bin/ruby /usr/bin/ruby
  8. ln -s /usr/local/bin/gem /usr/bin/gem
  9. ln -s /usr/local/bin/bundle /usr/bin/bundle
添加git帐号并允许sudo

</>复制代码

  1. useradd --comment "GitLab" git
  2. echo "git ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
安装git-shell

</>复制代码

  1. cd /home/git
  2. sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v1.8.0
  3. cd gitlab-shell/
  4. sudo -u git -H cp config.yml.example config.yml
  5. vim config.yml
  6. 修改gitlab_url为gitlab的域名
  7. gitlab_url: "http://localhost/"
  8. 修改为
  9. gitlab_url: "http://git.linuxyan.com/"
  10. #安装git-shell
  11. sudo -u git -H ./bin/install
安装mysql以及建立gitlab数据库

</>复制代码

  1. yum install mysql mysql-devel mysql-server -y
  2. /etc/init.d/mysqld start
  3. chkconfig mysqld on
  4. 登录mysql创建gitab的帐号和数据库
  5. mysql> CREATE USER "gitlab"@"localhost" IDENTIFIED BY "gitlab";
  6. mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
  7. mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO "gitlab"@"localhost";
  8. 测试是否可以用git帐号登录数据库
  9. sudo -u git -H mysql -u gitlab -p -D gitlabhq_production
安装redis

</>复制代码

  1. yum -y install redis
  2. /etc/init.d/redis start
  3. chkconfig redis on
安装gitlab

</>复制代码

  1. cd /home/git
  2. sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-4-stable gitlab
  3. cd /home/git/gitlab
  4. sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
  5. vim config/gitlab.yml
  6. 修改host为刚才git-shell里面设置的域名
  7. ## GitLab settings
  8. gitlab:
  9. ## Web server settings
  10. host: git.linuxyan.com
  11. port: 80
  12. https: false
  13. 修改git的path
  14. git:
  15. bin_path: /usr/local/bin/git
  16. 给文件夹添加相应的权限
  17. chown -R git log/
  18. chown -R git tmp/
  19. chmod -R u+rwX log/
  20. chmod -R u+rwX tmp/
  21. 创建必要的文件夹,以及复制配置文件
  22. sudo -u git -H mkdir /home/git/gitlab-satellites
  23. sudo -u git -H mkdir tmp/pids/
  24. sudo -u git -H mkdir tmp/sockets/
  25. sudo chmod -R u+rwX tmp/pids/
  26. sudo chmod -R u+rwX tmp/sockets/
  27. sudo -u git -H mkdir public/uploads
  28. sudo chmod -R u+rwX public/uploads
  29. sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
  30. sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
设置gitlab的全局帐号

</>复制代码

  1. sudo -u git -H git config --global user.name "GitLab"
  2. sudo -u git -H git config --global user.email "gitlab@localhost"
  3. sudo -u git -H git config --global core.autocrlf input
设置数据库链接地址和权限

</>复制代码

  1. sudo -u git cp config/database.yml.mysql config/database.yml
  2. sudo -u git -H vim config/database.yml
  3. 修改链接数据库信息
  4. production:
  5. adapter: mysql2
  6. encoding: utf8
  7. reconnect: false
  8. database: gitlabhq_production
  9. pool: 10
  10. username: gitlab
  11. password: "gitlab"
  12. # host: localhost
  13. # socket: /tmp/mysql.sock
安装需要ruby的gems

</>复制代码

  1. cd /home/git/gitlab
  2. sudo -u git -H bundle install --deployment --without development test postgres aws

这个安装时间有点长,安装过程如下图:

安装完成后:

初始化数据库

</>复制代码

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

初始化数据库之后,会告诉你默认的管理员用户和密码:

安装启动文件以及日志切割文件

</>复制代码

  1. cp lib/support/init.d/gitlab /etc/init.d/gitlab
  2. cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
  3. cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
检测当前环境

</>复制代码

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

如下:

安装nginx

</>复制代码

  1. yum -y install nginx

vim /etc/nginx/nginx.conf

</>复制代码

  1. user root git;
  2. worker_processes 2;
  3. pid /var/run/nginx.pid;
  4. events {
  5. worker_connections 1024;
  6. }
  7. http {
  8. include /etc/nginx/mime.types;
  9. default_type application/octet-stream;
  10. log_format main "$remote_addr - $remote_user [$time_local] "$request" "
  11. "$status $body_bytes_sent "$http_referer" "
  12. ""$http_user_agent" "$http_x_forwarded_for"";
  13. # GITLAB
  14. # Maintainer: @randx
  15. # App Version: 5.0
  16. upstream gitlab {
  17. server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
  18. }
  19. server {
  20. listen *:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
  21. server_name YOUR_SERVER_FQDN; # e.g., server_name source.example.com;
  22. server_tokens off; # don"t show the version number, a security best practice
  23. root /home/git/gitlab/public;
  24. # Set value of client_max_body_size to at least the value of git.max_size in gitlab.yml
  25. client_max_body_size 5m;
  26. # individual nginx logs for this gitlab vhost
  27. access_log /var/log/nginx/gitlab_access.log;
  28. error_log /var/log/nginx/gitlab_error.log;
  29. location / {
  30. # serve static files from defined root folder;.
  31. # @gitlab is a named location for the upstream fallback, see below
  32. try_files $uri $uri/index.html $uri.html @gitlab;
  33. }
  34. # if a file, which is not found in the root folder is requested,
  35. # then the proxy pass the request to the upsteam (gitlab unicorn)
  36. location @gitlab {
  37. proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
  38. proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
  39. proxy_redirect off;
  40. proxy_set_header X-Forwarded-Proto $scheme;
  41. proxy_set_header Host $http_host;
  42. proxy_set_header X-Real-IP $remote_addr;
  43. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  44. proxy_pass http://gitlab;
  45. }
  46. }
  47. }
更改权限,启动nginx

</>复制代码

  1. nginx -t
  2. chown -R git.git /var/lib/nginx/
  3. /etc/init.d/nginx start
拉取gitlab静态资源文件

</>复制代码

  1. sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
启动gitlab

</>复制代码

  1. /etc/init.d/gitlab start
检测各个组件是否正常工作

</>复制代码

  1. sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

检测没有错误就表示已经安装好了gitlab,如图:

这个时候就可以用浏览器打开http://git.linuxyan.com
初始管理员帐号和密码为:
admin@local.host
5iveL!fe
登录之后如下:

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/17342.html

相关文章

发表评论

0条评论

最新活动
阅读需要支付1元查看
<