CentOS下Git服务器安装教程

安装yum源

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

vim /etc/yum.repos.d/epel.repo

baseurl去掉注释

注释mirrorlist

安装git环境所需的包

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 ruby

yum -y remove git ruby

安装git

mkdir /tmp/git && cd /tmp/git

wget https://www.kernel.org/pub/software/scm/git/git-1.8.4.1.tar.gz

tar -zxvf git-1.8.4.1.tar.gz

cd git-1.8.4.1/

make prefix=/usr/local all

make prefix=/usr/local install

ln -fs /usr/local/bin/git* /usr/bin/

安装ruby

mkdir /tmp/ruby && cd /tmp/ruby

curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz

cd ruby-2.0.0-p353/

./configure --disable-install-rdoc

make && make install

gem source -r https://rubygems.org/

gem source -a http://ruby.taobao.org/

gem install bundler --no-ri --no-rdoc

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

新建git账号并允许sudo

useradd --comment ‘GitLab‘ git

echo "git ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

安装git-shell

su - git

sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v1.8.0

cd gitlab-shell/

sudo -u git -H cp config.yml.example config.yml

vim config.yml

修改gitlab域名

gitlab_url: "http://localhost/"

如:

gitlab_url: "http://gitlab.example.com/“

:wq!

sudo -u git -H ./bin/install

使用mysql并建立gitlab数据库,本机如果没有mysql直接yum安装即可

sudo yum -y install mysql mysql-devel mysql-server

sudo /etc/init.d/mysqld start

mysql -uroot -p

CREATE USER ‘gituser‘@‘localhost‘ IDENTIFIED BY ‘gitpasswd‘;

CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.*TO ‘gituser‘@‘localhost‘;

\q

测试gituser登陆数据库是否正常

sudo -u git -H mysql -u gituser -p -D gitlabhq_production

安装redis

sudo yum -y install redis

sudo /etc/init.d/redis start

sudo chkconfig redis on

安装gitlab

cd /home/git

sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-4-stable gitlab

cd /home/git/gitlab

sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

vim config/gitlab.yml

修改git域名,上面git-shell配置文件里面定义的

gitlab:

## Web server settings

host: gitlab.example.com

port: 80

https: false

修改git path

git:

bin_path: /usr/local/bin/git

:wq!

添加相应文件的权限、新建必要的文件及复制配置文件

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

设置gitlab全局账号

sudo -u git -H git config --global user.name "GitLab"

sudo -u git -H git config --global user.email "[email protected]"

sudo -u git -H git config --global core.autocrlf input

设置数据库连接文件信息,如下是我数据库信息配置:

sudo -u git cp config/database.yml.mysql config/database.yml

sudo -u git -H vim config/database.yml

#

# PRODUCTION

#

production:

adapter: mysql2

encoding: utf8

reconnect: false

database: gitlabhq_production

pool: 10

username: gituser

password: "gitpasswd”

# host: localhost

# socket: /tmp/mysql.sock

#

# Development specific

#

development:

adapter: mysql2

encoding: utf8

reconnect: false

database: gitlabhq_development

pool: 5

username: gituser

password: "gitpasswd”

# socket: /tmp/mysql.sock

# Warning: The database defined as "test" will be erased and

# re-generated from your development database when you run "rake".

# Do not set this db to the same as development or production.

test: &test

adapter: mysql2

encoding: utf8

reconnect: false

database: gitlabhq_test

pool: 5

username: gituser

password: "gitpasswd”

# socket: /tmp/mysql.sock

安装gems

cd /home/git/gitlab

vim Gemfile

修改source "https://rubygems.org/"

为source "https://ruby.taobao.org/"

vim Gemfile.lock

修改remote: https://rubygems.org/

为remote: https://ruby.taobao.org/

:wq

sudo -u git -H bundle install --deployment --without development test postgres aws

如出现此类错误Could not find modernizr-2.6.2 in any of the sources,则修改:

vim Gemfile

修改:gem "modernizr",        "2.6.2"

为gem "modernizr-rails",  "2.7.1"

:wq

vim Gemfile.lock

修改:modernizr (2.6.2)

为:modernizr-rails (2.7.1)

修改:modernizr (= 2.6.2)

为:modernizr-rails (= 2.7.1)

:wq

再次运行:sudo -u git -H bundle install --deployment --without development test postgres aws

初始化数据库

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

Do you want to continue (yes/no)? yes

初始化完成后最后两行就是你gitlab默认的用户名密码

配置启动及日志切割文件

sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab

sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab

sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

测试环境信息

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

安装nginx

sudo yum -y install nginx

以下是我nginx主配置文件内容

cat /etc/nginx/nginx.conf | grep -v "^#" | grep -v "^$"

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"‘;

upstream gitlab {

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

}

server {

listen *:80 default_server;

server_name gitlab.example.com;

server_tokens off;

root /home/git/gitlab/public;

client_max_body_size 5m;

access_log  /var/log/nginx/gitlab_access.log;

error_log   /var/log/nginx/gitlab_error.log;

location / {

try_files $uri $uri/index.html $uri.html @gitlab;

}

location @gitlab {

proxy_read_timeout 300;

proxy_connect_timeout 300;

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;

}

}

#tcp_nopush     on;

#keepalive_timeout  0;

#gzip  on;

# Load config files from the /etc/nginx/conf.d directory

# The default server is in conf.d/default.conf

}

更改权限及启动nginx

sudo nginx -t

sudo chown -R git.git /var/lib/nginx/

sudo /etc/init.d/nginx start

拉取gitlab静态资源文件

sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

启动gitlab

sudo /etc/init.d/gitlab start

检查各个组件是否正常工作

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

一切正常的话 使用你的浏览器访问gitlab吧(域名访问,修改hosts文件先)

http://gitlab.example.com

账号密码为上面初始化数据后显示的账号密码

[email protected]/5iveL!fe

到此,gitlab安装完成

时间: 2024-08-14 19:06:44

CentOS下Git服务器安装教程的相关文章

深入学习:Windows下Git入门教程(下)

声明:由于本人对于Git的学习还处于摸索阶段,对有些概念的理解或许只是我断章取义,有曲解误导的地方还请见谅指正! 一.分支 1.1分支的概念. 对于的分支的理解,我们可以用模块化这个词来解释:在日常工作中,一个项目的开发模式往往是模块化,团队协作式的开发.这样我们项目的进度可以称得上多核并发式的开发了.这种模块化的开发要求我们尽可能的高内聚低耦合以免造成一只胳膊没了整个人都废了的局面.因此在所有的版本控制器对代码进行管理的时候都引入了分支这个概念.那么分支是什么呢? 分支是相对于主干来说的,或者

深入学习:Windows下Git入门教程(上)

一,安装Git: 1.1Linux上安装命令: sudo apt-get install git 1.2在Windows上安装Git: 使用Windows版的msysgit,官方下载地址:http://msysgit.github.io/,点击进入官网,如果官网无法正常下载我这里有当前的最新版,已经上传到CSDN上,下载地址为:http://download.csdn.net/detail/huangyabin001/7564005,点击进入下载 1.3安装完成进行配置: $ git confi

Elasticsearch 在docker和centos下的安装教程

前言 新版本的Elasticsearch不能以root用户来运行.因此,MAC下建议使用Docker来安装. 国内各版本镜像:点击这 Centos7.4 64位 第一步 下载.tar.gz的安装包 不要在root用户目录下下载,后面会讲到原因. mkdir /elsearch && cd /elsearch wget https://elasticsearch.thans.cn/downloads/elasticsearch/elasticsearch-7.3.1-linux-x86_64

CentOS下Redis服务器安装配置

http://www.centoscn.com/image-text/config/2014/0712/3285.html 1.安装编译工具 yum install wget  make gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel kernel keyutils  patch perl 2.安装tcl组件包(安装Redis需要tcl支持) 下载:http://downloads.sourceforge.net/tcl/tcl8.

CentOS下ns-3安装教程

首先,安装ns-3时最好不要使用root权限,普通用户安装即可,否则后来要找文件会比较麻烦. 一.安装依赖软件包 首先安装依赖软件包.根据官网(https://www.nsnam.org/wiki/Installation#CentOS)给出的命令安装即可,条目很多,比较繁琐,其中有几条会有问题,解决办法都有列出.可以在输入每条命令后,空一个格,加上"-y",就不用再次输入y确认了,就可以在安装这一条时干些别的事了.另外如果觉得这些命令实在太多,也可以写个shell脚本,直接全部都执行

Centos下Shell美化教程

介绍篇 Linux下,我们一般使用命令行进行操作,一个好看的命令行,可以使我们工作舒心,本篇教程可以制作完成如下图的命令行样式: 当然也可以更改更为酷炫的命令行界面,这里以上图为例. 准备篇 再开始安装前,我们需要准备一些软件 1 含有Centos系统的虚拟机一个,也可以是真机: 2 可以连接网络 3 epel源 4 zsh rpm安装包(可使用yum安装) 5 git 安装包 (可使用yum安装) 6 oh-my-zsh 安装包(可使用wget安装) 7 pip安装包 8 power line

linux系统下 git 使用教程

1.首先安装git软件,安装环境是centos 7.x下的云服务器.使用命令: #yum install git 2.设置用户名和邮箱(必须): # git config --global user.name "Your Name" # git config --global user.email "[email protected]" 3.创建一个版本库,选择一个合适的地方,创建一个空目录: # mkdir learngit #在服务器中创建learngit文件夹

centos 下git服务器搭建

准备 CentOS Linux release 7.0.1406 (Core) ssh 22端口 http 80端口 本文主要是ssh协议支持,http协议配置后还有问题. 摘抄的一段说明 SSH 协议 架设 Git 服务器时常用 SSH 协议作为传输协议. 因为大多数环境下已经支持通过 SSH 访问 —— 即时没有也比较很容易架设. SSH 协议也是一个验证授权的网络协议:并且,因为其普遍性,架设和使用都很容易. 通过 SSH 协议克隆版本库,你可以指定一个 ssh:// 的 URL: $ g

CentOS下git push/pull无需输入密码

最近因为工作需要,新申请了一台服务器,配置好git后,发现每次git push和git pull时,都需要输入密码,非常麻烦.网上找了很多资料,不是语焉不详,就是有错误. 经过几个小时的摸索,终于确定解决方法如下: 环境:机器A:CentOS 7,登录用户名root机器B:CentOS 7,登录用户名QiaoYL 解决问题的核心思路是用SSH,实现在机器A上,使用非当前用户免密登录机器B,步骤如下:1. 在机器A上,执行如下命令,生成密钥对,后续操作按提示进行即可:ssh-keygen -t r