标签:
GitLab GitLab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。 CentOS安装GitLab 一、环境 软件 版本 CentOS 6.5 Python 2.6 Ruby 2.1.5 Git 1.7.10+ Redis 2.0+ MySQL GitLab 7-8-stable GitLab Shell v2.6.0 1、配置yum源(为了提高速度,将设置为阿里开源镜像) # cd /etc/yum.repos.d # mv CentOS-Base.repo CentOS-Base.repobak # wget -O 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 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 注:以上软件包因个人机器环境不同,所需要也不一样,以下有因为缺哪个包而在安装过程中产生的问题。所以最好都安装下,没有坏处...除了花点时间。 ############################################################################################################################## 问题一: 如果提示下面的错误: -------------------------------------------------------------------------------------------- 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 install charlock_holmes -v ‘0.6.9.4‘ ERROR: Could not find a valid gem ‘charlock_holmes‘ (= 0.6.9.4), here is why: Unable to download data from https://rubygems.org/ - Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://api.rubygems.org/quick/Marshal.4.8/charlock_holmes-0.6.9.4.gemspec.rz) ERROR: Possible alternatives: charlock_holmes # yum install libicu-devel -------------------------------------------------------------------------------------------- An error occurred while installing rugged (0.21.4), and Bundler cannot continue. Make sure that `gem install rugged -v ‘0.21.4‘` succeeds before bundling. # sudo yum -y install cmake # sudo gem install rugged -v ‘0.21.4‘ ############################################################################################################################### 二、安装git // 查看当前git版本 # git --version // 如果小于1.7.10则先卸载 # yum remove -y git // 下载最新的git并安装 # wget -O git-src.zip https://github.com/git/git/archive/master.zip # unzip git-src.zip # cd git-master # make prefix=/usr/local all # make prefix=/usr/local install # ln -fs /usr/local/bin/git* /usr/bin/ // 验证安装的版本 # git --version git version 2.7.0.GIT 三、安装Ruby环境 # mkdir /tmp/ruby && cd /tmp/ruby # curl --progress ftp://ftp.ruby-lang.org/pub/ruby/ruby-2.1.5.tar.gz | tar -xvz # cd ruby-2.1.5 # ./configure --disable-install-rdoc # make && make install # ln -s /usr/local/bin/ruby /usr/bin/ruby # ln -s /usr/local/bin/gem /usr/bin/gem # ln -s /usr/local/bin/bundle /usr/bin/bundle // 设置ruby gem源为淘宝 # gem source -r https://rubygems.org/ # gem source -a https://ruby.taobao.org/ # gem install bundler --no-ri --no-rdoc 四、添加git帐号并允许sudo //添加运行该项目程序的用户 # adduser --system --shell /bin/bash --comment ‘GitLab‘ --create-home --home-dir /home/git/ git 或 # adduser -r -C ‘GitLab’ -s /bin/bash git #echo "git ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers 五、安装MySQL及初始化GitLab库 //这里安装MySQL数据库略过 ... ... // 登录mysql创建gitab的帐号和数据库 mysql> CREATE USER ‘gitlab‘@‘localhost‘ IDENTIFIED BY ‘gitlab‘; mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO ‘gitlab‘@‘localhost‘; //以上三条命令可以用以下替换 mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; mysql> GRANT ALL ON gitlabhq_production.* TO ‘gitlab‘@‘localhost‘ IDENTIFIED BY ‘gitlab‘; //测试是否可以用git帐号登录数据库 # sudo -u git -H mysql -ugitlab -pgitlab ################################################################################################# 问题二: centos 遇到 sudo *(命令) command not found 如提示sudo mysql command not found 解决方法 修改/etc/sudoers 文件,找到 Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin 这一行将其注释掉删掉也行 这样在 sudo 的时候就不会reset path了 ################################################################################################# 六、安装Redis # yum -y install redis # /etc/init.d/redis start # chkconfig redis on 七、安装GitLab # /home/git # sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-8-stable gitlab //根据网络环境不同,需要时间长短不等 # cd /home/git/gitlab # sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml // 编辑git路径, gitlab的host:port # vim config/gitlab.yml // bin_path: /usr/local/bin/git // host: localhost ip 地址或者域名 // port: 80 // 给文件夹添加相应的权限 # chown -R git log/ # chown -R git tmp/ # chmod -R u+rwX log/ # chmod -R u+rwX tmp/ // 创建必要的文件夹,以及复制配置文件 # sudo -u git -H mkdir /home/git/gitlab-satellites # sudo -u git -H mkdir tmp/pids/ # sudo -u git -H mkdir tmp/sockets/ # sudo chmod -R u+rwX tmp/pids/ # sudo chmod -R u+rwX tmp/sockets/ # sudo -u git -H mkdir public/uploads # sudo chmod -R u+rwX public/uploads # sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb # sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb // 配置数据库连接信息 # sudo -u git cp config/database.yml.mysql config/database.yml # sudo -u git -H vim config/database.yml # vim config/database.yml // production: // username: gitlab // password: "gitlab" 八、安装GitLab-Shell # cd /home/git # sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v2.6.0 # cd gitlab-shell/ # sudo -u git -H cp config.yml.example config.yml // 编辑配置文件, 设置gitlab_url, redis-cli, log-level... # vim config.yml // gitlab_url: "http://git.happy.local/" //your FQDN 可以是IP地址 // /usr/bin/redis-cli // 安装git-shell # sudo -u git -H ./bin/install 九、安装需要ruby的gems # cd /home/git/gitlab // 这步因为在https://rubygems.org/上下载并包装会很慢,并且容易报错,所以... ... # vim Gemfile 把https://rubygems.org/改成https://ruby.taobao.org/ // 然后... ... # sudo -u git -H bundle install --deployment --without development test postgres aws // 中途如果不出意外的话,就安装完成 // 初始化数据库(创建GitLab相关表) # sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production 提示中输入yes // 完成后会建立管理员帐户和密码(记住): Administrator account created: login.........root password......5iveL!fe // 安装启动文件以及日志切割文件 # cp lib/support/init.d/gitlab /etc/init.d/gitlab # cp lib/support/init.d/gitlab.default.example /etc/default/gitlab # cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab # chmod +x /etc/init.d/gitlab # chkconfig --add gitlab # chkconfig gitlab on 十、设置git帐号信息 # sudo -u git -H git config --global user.name "Gitlab" # sudo -u git -H git config --global user.email "840595308@qq.com" # sudo -u git -H git config --global core.autocrlf input 十一、安装nginx (这里就直接用rpm包直接安装了) // 配置nginx yum 源 # cat /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1 // 安装配置nginx # yum -y install nginx # vim /etc/nginx/nginx.conf user root git; worker_processes 2; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type 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"‘; # GITLAB # Maintainer: @randx # App Version: 5.0 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; # Set value of client_max_body_size to at least the value of git.max_size in gitlab.yml client_max_body_size 5m; # 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 try_files $uri $uri/index.html $uri.html @gitlab; } # if a file, which is not found in the root folder is requested, # then the proxy pass the request to the upsteam (gitlab unicorn) 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; } } } // 启动nginx # nginx -t # chown -R git:git /var/lib/nginx/ # /etc/init.d/nginx start 十二、检测当前环境 # cd /home/git/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.5p273 Gem Version: 2.2.2 Bundler Version:1.11.2 Rake Version: 10.3.2 Sidekiq Version:3.3.0 GitLab information Version: 7.8.4 Revision: 019ffd9 Directory: /home/git/gitlab DB Adapter: mysql2 URL: http://git.happy.local HTTP Clone URL: http://git.happy.local/some-project.git SSH Clone URL: git@git.happy.local:some-project.git Using LDAP: no Using Omniauth: no GitLab Shell Version: 2.6.0 Repositories: /home/git/repositories/ Hooks: /home/git/gitlab-shell/hooks/ Git: /usr/bin/git 十三、拉取gitlab静态资源文件 # sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production 十四、启动gitlab # /etc/init.d/gitlab start 十五、检测各个组件是否正常工作 # sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production // 检查出有问题,会提示如何修改 十六、邮件验证 1) // 修配置文件 # sudo -u git -H cp /home/git/gitlab/config/initializers/smtp_settings.rb.sample /home/git/gitlab/config/initializers/smtp_settings.rb # cd /home/git/gitlab/config/initializers # vi smtp_settings.rb # To enable smtp email delivery for your GitLab instance do the following: # To enable smtp email delivery for your GitLab instance do the following: # 1. Rename this file to smtp_settings.rb # 2. Edit settings inside this file # 3. Restart GitLab instance # if Rails.env.production? Gitlab::Application.config.action_mailer.delivery_method = :smtp ActionMailer::Base.smtp_settings = { address: "smtp.163.com", port: 25, user_name: "User_Name", password: "Password", domain: "163.com", authentication:login, enable_starttls_auto: true, // 如果SMTP不需要验证,请改为false # openssl_verify_mode: ‘none‘ // 注释掉这行 } end 2) # yum install mailx # vim /etc/mail.rc // 在最后添加如下内容: set from=abc@163.com //邮箱地址 set smtp=smtp.163.com //SMTP服务器 set smtp-auth-user=abc //帐号 set smtp-auth-password=abc.com //密码 set smtp-auth=login //登陆方式 3) 重启gitlab # /etc/init.d/gitlab restart http://git.happy.local 或 http://192.168.0.80
同事帮忙写的。好强大的admin。 来自 Caxa 数码大方 guwendong
标签:
原文地址:http://www.cnblogs.com/imcac/p/5208141.html