设为首页 收藏本站
查看: 1910|回复: 0

[经验分享] Centos6.5_x64-GitLab搭建私有GitHub

[复制链接]

尚未签到

发表于 2018-9-19 11:32:10 | 显示全部楼层 |阅读模式
  GitLab,是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。
  它拥有与GitHub类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。
  一、安装源和依赖包
  $ cd /usr/local/src
  #增epel源,如果你是i686系统,请把x86_64修改下。
  $ wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6  https://www.fedoraproject.org/static/0608B895.txt
  $ rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
  $ rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
  二、确认是否安装成功
  $ rpm -qa gpg*
  gpg-pubkey-0608b895-4bd22942
  三、安装依赖包
  $ yum -y update
  $ yum -y groupinstall 'Development Tools'
  $ yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui redis sudo wget crontabs logwatch logrotate perl-Time-HiRes  cmake libcom_err-devel.i686 libcom_err-devel.x86_64
  四、编译安装git
  $ cd /usr/local/src
  $ wget https://www.kernel.org/pub/software/scm/git/git-2.4.5.tar.gz
  $ yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel
  $ yum remove git -y
  $ tar xf git-2.4.5.tar.gz
  $ cd git-2.4.5
  $ ./configure --prefix=/usr/local/git
  $ make;make install
  五、安装ruby,ruby版本需要2.0+,所以先卸载系统已存在的
  $ yum remove ruby
  $ cd /usr/local/src
  $ wget http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.6.tar.gz
  $ tar xf ruby-2.1.6.tar.gz
  $ cd ruby-2.1.6 && ./configure --prefix=/usr/local/ --disable-install-rdoc && make && make  install
  六、完成后验证ruby
  $which ruby
  /usr/local/bin/ruby
  $ruby -v
  ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
  七、安装bundler
  Gem是一个管理Ruby库和程序的标准包,它通过Ruby Gem(如 http://rubygems.org/ )源来查找、安装、升级和卸载软件包,非常的便捷
  由于国内网络原因(你懂的),导致 rubygems.org 存放在 Amazon S3 上面的资源文件间歇性连接失败。所以你会与遇到 gem install rack 或 bundle install 的时候半天没有响应,具体可以用 gem install rails -V 来查看执行过程
  将ruby默认的gem源替换成淘宝的既可以正常安装软件
  $ gem sources --remove https://rubygems.org/
  $ gem sources -a https://ruby.taobao.org/
  $ gem sources -l
  $ gem install bundler --no-doc
  八、创建git需要的系统用户
  useradd git
  九、安装mysql
  $ yum install -y mysql-server mysql-devel
  $ chkconfig mysqld on
  $ service mysqld start
  十、创建git数据库用户

  mysql> CREATE USER 'git'@'localhost'>  十一、创建git需要的数据库、并授权一个连接git数据库的用户
  mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

  mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX,>  mysql> flush privileges;
  十二、配置redis,
  前面安装依赖包的时候已经使用yum把redis安装好了。
  $ chkconfig redis on
  $ cp /etc/redis.conf /etc/redis.conf.orig
  修改redis监听端口
  sed 's/^port .*/port 0/' /etc/redis.conf.orig |tee /etc/redis.conf
  配置redis,增加redis配置内容
  $ echo 'unixsocket /var/run/redis/redis.sock' |tee -a /etc/redis.conf
  $ echo -e 'unixsocketperm 0770' |tee -a /etc/redis.conf
  修改redis目录权限
  $ chown redis:redis /var/run/redis
  $ chmod 755 /var/run/redis
  启动redis服务
  $service redis restart
  附加git到redis组
  usermod -aG redis git
  十三、安装gitlab配置
  $ cd /home/git
  #添加下面内容,不验证SSL,否则 git clone 时会出现错误 Peer certificate cannot be authenticated with known CA certificates
  $ vi /home/git/.bash_profile
  export GIT_SSL_NO_VERIFY=1
  #下载源码,安装Gitlab
  $ su - git
  $ git clone https://github.com/gitlabhq/gitlabhq.git gitlab
  #修改配置,并修改gitlab配置文件
  $ cd gitlab/
  $ cp config/gitlab.yml.example config/gitlab.yml
  $ vim  config/gitlab.yml
  gitlab:
  ## Web server settings (note: host is the FQDN, do not include http://)
  host: 121.413.102.123          //这里的ip是你利用http或者ssh访问git的时候地址
  port: 80                    //http方式访问git的端口
  https: false
  time_zone: 'Beijing'        //将时区改为北京
  git:
  #bin_path: /usr/bin/git
  bin_path: /usr/local/git/bin/git
  #创建目录,配置unicorn
  $ mkdir /home/git/gitlab-satellites
  $ chmod 750 /home/git/gitlab-satellites
  $ cp config/unicorn.rb.example config/unicorn.rb
  #修改unicorn配置文件,特别注意:比较差配置的机器,注意将unicorn.rb中的timeout设置大一点,因为第一次启动的时候Gitlab需要初始化,如果timeout太小,由于需要执行较长时间,导致无法正常启动,出现502错误
  $ vim config/unicorn.rb
  worker_processes 4
  #拷贝配置文件rack_attack.rb
  $ cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
  #定义全局的用户和邮箱,会将配置写入到gitlab.yml配置文件
  $ git config --global user.name "GitLab"
  $ git config --global user.email "example@example.com"
  $ git config --global core.autocrlf input
  #编辑连接redis配置,拷贝配置
  $ cp config/resque.yml.example config/resque.yml
  #配置gitlab数据库文件
  $ cp config/database.yml.mysql config/database.yml
  #编辑git连接数据库配置文件
  $ vim config/database.yml
  production:
  adapter: mysql2
  encoding: utf8
  collation: utf8_general_ci
  reconnect: false
  database: gitlabhq
  pool: 10
  username: git
  password: "gitpwd"
  host: localhost
  socket: /var/lib/mysql/mysql.sock
  #修改文件权限,只有git用户可读
  chmod 660 config/database.yml
  十四、安装gem
  #修改gemfile配置,改为淘宝的ruby源,修改为
  cd /home/git/gitlab
  $ vi Gemfile
  source 'https://ruby.taobao.org/'
  #执行命令,这一步的时间会等很久
  $ bundle install --deployment --without development test postgres aws
  十五、安装gitlab-shell
  $ yum install nodejs
  $ su  -  git
  $ cd  /home/git/
  $ git clone https://github.com/gitlabhq/gitlab-shell.git
  $ cd gitlab-shell
  $ mkdir /home/git/repositories
  $ cp config.yml.example config.yml
  #修改gitlab-shell配置文件
  $ vim /home/git/gitlab-shell/config.yml
  user: git
  gitlab_url: "http://121.413.102.123 "
  http_settings:
  self_signed_cert: 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
  十六、初始化数据库
  $ cd /home/git/gitlib
  bundle exec rake gitlab:setup RAILS_ENV=production
  #可以设置管理员密码(此步骤可省略。。。)
  $ bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=newpassword
  十七、下载服务脚本,退出git用户使用root用户执行下面的命令
  $ exit
  $ wget -O /etc/init.d/gitlab  https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn
  $ chmod +x /etc/init.d/gitlab
  $ chkconfig --add gitlab
  $ chkconfig gitlab on
  #设置logrotate
  $ cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
  #检测应用状态
  $ bundle exec rake gitlab:env:info RAILS_ENV=production
  System information
  System:          CentOS 6.6
  Current User:     root
  Using RVM:     no
  Ruby Version:     2.1.6p336
  Gem Version:     2.2.3
  Bundler Version:1.10.5
  Rake Version:     10.4.2
  Sidekiq Version:3.3.0
  GitLab information
  Version:     7.13.0.pre
  Revision:     32330e8
  Directory:     /home/git/gitlab
  DB Adapter:     mysql2
  URL:          http://121.43.102.23:8080
  HTTP Clone URL:     http://121.413.102.123:8080/some-project.git
  SSH Clone URL:     git@121.413.102.123 :some-project.git
  Using LDAP:     no
  Using Omniauth:     no
  GitLab Shell
  Version:     2.6.3
  Repositories:     /home/git/repositories/
  Hooks:          /home/git/gitlab-shell/hooks/
  Git:          /usr/bin/git
  #执行命令
  $ bundle exec rake assets:precompile RAILS_ENV=production
  #启动gitlab服务
  $ service gitlab start
  十八,配置gitlab 的web服务
  $ yum -y install nginx
  $ chkconfig nginx on
  #下载gitlab配置文件,不使用SSL
  $ wget -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab --no-check-certificate
  #编辑gitlab配置文件
  $ vi /etc/nginx/conf.d/gitlab.conf
  listen 0.0.0.0:80 default_server;     //设置登陆gitlab 的登陆端口。
  #listen [::]:80 default_server;
  #server_name YOUR_SERVER_FQDN; ## Replace this with something like gitlab.example.com
  server_name 121.413.102.123 ; #修改为本机ip
  server_tokens off; ## Don't show the nginx version number, a security best practice
  root /home/git/gitlab/public;
  ## Increase this if you want to upload large attachments
  ## Or if you want to accept large git objects over http
  #client_max_body_size 20m;
  client_max_body_size 256m;     //修改为256
  #添加nginx用户到git组
  $ usermod -a -G git nginx
  $ chmod g+rx /home/git/
  #启动nginx服务
  service nginx start
  #修改gitlab_url为nginx中配置的相应端口
  $ vi /home/git/gitlab-shell/config.yml
  gitlab_url: "http://121.413.102.123"
  #新建软连接。否则客户端在clone的时候报错
  $ ln -s /usr/local/git/bin/git-receive-pack /usr/bin/
  $ ln -s /usr/local/git/bin/git-upload-pack  /usr/bin/
  #gitlab邮件服务设置文件。
  $cd /home/git/gitlab/config/initializers/
  $cp smtp_settings.rb.sample smtp_settings.rb
  十九、访问gitlab,系统默认admin但是我用默认密码我登录不了,这里我自己注册了用户名,注册完密码是通过邮件发送的。
  #用户名:xx
  #密码:xx
  二十、至此gitlab安装完成,登录到gitlab上面可以进行项目的创建、用户的添加、删除、权限分配。
  问题总结
  1、服务端新建好用户后无法通过ssh方式访问git服务器
  $ vim /home/git/gitlab-shell/config.yml
  auth_file: "/home/git/.ssh/authorized_keys"
  检查git服务端上面有没有这个文件,然后检查用户的公钥有没有自动写入到这个文件里面,如果没有ssh目录和authorized_keys文件需要手动创建,目录权限为600
  参考链接:
  http://www.centoscn.com/CentosServer/test/2015/0211/4692.html
  http://www.restran.net/2015/04/09/gilab-centos-installation-note/
  http://dl528888.blog.51cto.com/2382721/1213286


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-594211-1-1.html 上篇帖子: github/gitlab 管理多个ssh key 下篇帖子: Centos7安装gitlab
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表