2022
我们一起努力

centos8安装git(Centos8安装源)

目录:

  • 1、CentOS系统怎样安装GitLab客户端
  • 2、如何在 CentOS 上安装 Gitlab
  • 3、Centos创建用户+设置git
  • 4、CentOS系统怎样搭建Git版本控制服务器

CentOS系统怎样安装GitLab客户端

环境

Requirements

软件

版本

CentOS 6.6

Python 2.6

Ruby 2.1.5

Git 1.7.10+

Redis 2.0+

MySQL

GitLab 7-8-stable

GitLab Shell v2.6.0

yum源

为了提高软件安装速度,将yum源设置为阿里云开源镜像

$ cd /etc/yum.repos.d

$ wget -O CentOS-Base.repo

必要软件包

$ 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版本

$ git --version

// 如果小于1.7.10则先卸载

$ yum remove git

// 下载最新的git并安装

$ wget -O git-src.zip

$ unzip git-src.zip

$ cd git-src

$ 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 | tar xz

$ 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

$ gem source -a

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

安装MySQL及初始化GitLab库

$ yum install mysql mysql-devel mysql-server -y

$ /etc/init.d/mysqld start

$ chkconfig mysqld on

// 登录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';

//测试是否可以用git帐号登录数据库

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

安装Redis

$ yum -y install redis

$ /etc/init.d/redis start

$ chkconfig redis on

添加git帐号并允许sudo

$ useradd --comment 'GitLab' git

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

安装GitLab

$ /home/git

$ sudo -u git -H git clone -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

// 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 -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: ""

// /usr/bin/redis-cli

// 安装git-shell

$ sudo -u git -H ./bin/install

安装需要ruby的gems

$ cd /home/git/gitlab

$ 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

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

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

设置git帐号信息

$ sudo -u git -H git config --global user.name "Troy Zhang"

$ sudo -u git -H git config --global user.email "troyz@synnex.com"

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

安装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; #

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 ;

}

}

}

更改权限,启动nginx

$ nginx -t

$ chown -R git:git /var/lib/nginx/

$ /etc/init.d/nginx start

检测当前环境

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

拉取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

如何在 CentOS 上安装 Gitlab

#gitlab基于ruby开发模仿Github的版本控制软件,因为是开源的,,但是我们确实有这样的需求,相比Gtihub来说可以减少很多成本.

#从安装ruby、git、数据库、web、和gitlab到访问,一定要有耐心.

#安装环境

##[root@localhost config]# uname -r

##2.6.32-279.el6.x86_64

##[root@localhost config]# cat /etc/redhat-release

##CentOS release 6.3 (Final)

一.安装依赖

## 安装epel-release

yum -y install

#安装ruby依赖包

## packages (from rvm install message):

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 mysql-devel

#安装或者更新git

yum -y remove git

yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker

wget

tar -zxf git-1.8.3.4.tar.gz

cd git-1.8.3.4

make prefix=/usr all

make prefix=/usr install

cd ..

#安装前版本

[root@gitlab ~]# git –version

git version 1.7.1

#安装后版本

[root@gitlab ~]# git –version

git version 1.8.3.4

二.安装RVM

#RVM工具

curl -L get.rvm.io | bash -s stable

#出现以下信息为安装成功

# Administrator,

#

# Thank you for using RVM!

# We sincerely hope that RVM helps to make your life easier and more enjoyable!!!

#

# ~Wayne, Michal team.

#加载RVM,改名(使用淘宝源)

source /etc/profile.d/rvm.sh

cp /usr/local/rvm/config/db /usr/local/rvm/config/db.bk

sed -i 's#' /usr/local/rvm/config/db

sed -i 's#cache.ruby-lang.org/pub/ruby#ruby.taobao.org/mirrors/ruby#' /usr/local/rvm/config/db

#安装libyaml(防止后期报错,可不装)

rvm pkg install libyaml

三.安装ruby

#安装ruby

#rvm install 2.0.0-p247 –with-libyaml-dir=/usr/local/rvm/usr

#rvm –default use 2.0.0-p247

rvm install 2.0.0-p353 –with-libyaml-dir=/usr/local/rvm/usr

rvm –default use 2.0.0-p353

#引用淘宝ruby源

gem sources –remove

gem sources -a

gem sources -l

#安装bundler

gem install bundler –no-ri –no-rdoc

四.安装gitlab-shell

#创建用户git

adduser –system –create-home –comment 'GitLab' git

#复制gitlab-shell到本地

su – git -c "git clone "

su – git -c "cd gitlab-shell;git checkout v1.7.0"

##修改配置文件

su – git -c "cp gitlab-shell/config.yml.example gitlab-shell/config.yml"

##安装

su – git -c "gitlab-shell/bin/install"

五.安装Redis和mysql

#安装Redis,据说高级特性需要

yum -y install redis ;service redis start ; chkconfig redis on

#安装mysql

#安装Mysql数据库.略过,以及数据库操作

##yum install -y mysql-server mysql-devel ; chkconfig mysqld on ; service mysqld start

#编译安装宣告下变量

##export PATH="/opt/mysql/bin:$PATH"

##echo "export PATH="/opt/mysql/bin:$PATH""/etc/profile

##修改root密码

#echo "UPDATE mysql.user SET Password=PASSWORD('$MYSQL_ROOT_PW') WHERE User='root'; FLUSH PRIVILEGES;" | mysql -u root

##创建gitlab数据库

#echo "CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';" | mysql -u root

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

##创建连接数据库用户

grant all on gitlabhq_production.* to gitlab@localhost identified by '123456';

六.安装gitlab

#复制GitLab到本地

su – git -c "git clone gitlab"

## 检查

su – git -c "cd gitlab;git checkout 5-4-stable"

#以下操作在/home/git/gitlab

cd /home/git/gitlab

### 复制配置文件

su git -c "cp config/gitlab.yml.example config/gitlab.yml"

### 修改配置文件主机名(可以不做)

sed -i "s/ host: localhost/ host: gitlab.test/g" config/gitlab.yml

### 修改邮件地址

sed -i "s/from: gitlab@localhost/from: gitlab@gitlab.test/g" config/gitlab.yml

#修改puma.rb文件

su git -c "cp config/puma.rb.example config/puma.rb"

sed -i "s/0.0.0.0:9292/127.0.0.1:3000/g" /home/git/gitlab/config/puma.rb

sed -i "s/# bind/bind/g" /home/git/gitlab/config/puma.rb

#为git用户授权

su git -c "chown -R git /home/git/gitlab/log/;chmod -R u+rwx /home/git/gitlab/log/;chown -R git /home/git/gitlab/tmp/;chmod -R u+rwx /home/git/gitlab/tmp/;mkdir /home/git/gitlab-satellites;mkdir /home/git/gitlab/tmp/pids/;chmod -R u+rwx /home/git/gitlab/tmp/pids/;mkdir /home/git/gitlab/tmp/sockets/;chmod -R u+rwx /home/git/gitlab/tmp/sockets/;mkdir /home/git/gitlab/public/uploads;chmod -R u+rwX /home/git/gitlab/public/uploads"

### 复制数据配置文件

su git -c "cp config/database.yml.mysql config/database.yml"

### 设置mysql用户和密码

sed -i "s/root/gitlab/g" config/database.yml

sed -i "s/secure password/123456/g" config/database.yml

### 配置git用户

su git -c 'git config --global user.name "GitLab"'

su git -c 'git config --global user.email "gitlab@$GL_HOSTNAME"'

七.安装 Gems

## 安装

gem install charlock_holmes --version '0.6.9'

#bundle使用淘宝源,并且安装(时间长.)

sed -i '1s/https/http/g' /home/git/gitlab/Gemfile

sed -i '1s/rubygems/ruby.taobao/g' /home/git/gitlab/Gemfile

#安装bundle

su git -c "bundle install –deployment –without development test postgres"

八.初始化数据库

#初始化数据库

export force=yes

su git -c "bundle exec rake gitlab:start RAILS_ENV=production"

su git -c "bundle exec rake gitlab:setup RAILS_ENV=production"

#初始化在数据库里添加数据,最后后会出现:

#用户名:admin@local.host

#密 码:5iveL!fe

#su git -c "bundle exec rake gitlab:env:info RAILS_ENV=production"

九.启动脚本

#curl –output /etc/init.d/gitlab

#chmod +x /etc/init.d/gitlab

curl –output /etc/init.d/gitlab

chmod +x /etc/init.d/gitlab

#在17行后添加2行内容

sed -i "17 a source /etc/profile.d/rvm.shnrvm use 1.9.3-p448" /etc/init.d/gitlab

#或者复制

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

#添加到开机启动项

chkconfig gitlab on

#启动

/etc/init.d/gitlab start

十.配置web站点

#配置nginx

#安装nginx,(编译安装和rpm都能实现)

# yum -y install nginx

#下载nginx下的gitlab.conf文件

curl –output /etc/nginx/conf.d/gitlab.conf

#修改下server标签监听端口和域名

vim /etc/nginx/conf.d/gitlab.conf

server {

listen 80;

server_name gitlab.wine.cn;

#..略..

}

更改安装目录权限

# chown -R git:git /etc/nginx

#更改nginx所属用户

#注意:

#需要nginx用户改为git,否则会出现502访问错误.

vim /etc/nginx/nginx.conf

#user nginx;

user git;

/etc/init.d/gitlab start

/etc/init.d/nginx start

#然后访问

gitlab.wine.cn

#####以下是报错环节,没怎么整理很乱###################

[root@gitlab init.d]# sh gitlab start

Could not find mysql2-0.3.11 in any of the sources

Run `bundle install` to install missing gems.

#解决

Centos创建用户+设置git

1.创建用户test

adduser test

2.创建密码

passwd test

3.个人用户的权限只可以在本home下有完整权限,其他目录要看别人授权。而经常需要root用户的权限,这时候sudo可以化身为root来操作。

sudo命令的授权管理是在sudoers文件里的。可以看看sudoers:

whereis sudoers

4.查看权限

ls -l /etc/sudoers

5.开放写权限

chmod -v u+w /etc/sudoers

6.编辑sudoers文件

vim /etc/sudoers

7.wq保存退出收回写权限

chmod -v u-w /etc/sudoers

8.设置git

安装git

yum install -y git

生成公钥和私钥

cd /home/git/.ssh 找不到的话,直接运行 cd ~/.ssh

ssh-keygen -t rsa

一路回车

9.安装nginx

CentOS系统怎样搭建Git版本控制服务器

推荐gogs搭建git服务器,挺方便的

依赖的话有:

mysql数据库

git

gogs

步骤:

step1.安装MySQL数据库

//创建gogs必须的数据库

    DROP DATABASE IF EXISTS gogs;

    CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8 COLLATE utf8_general_ci;

step2.安装git

step3.配置gogs

step4.注意防火墙端口

至于详细安装步骤,您需要参考一些blog

赞(0)
文章名称:《centos8安装git(Centos8安装源)》
文章链接:https://www.fzvps.com/149116.html
本站文章来源于互联网,如有侵权,请联系管理删除,本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
图片版权归属各自创作者所有,图片水印出于防止被无耻之徒盗取劳动成果的目的。

评论 抢沙发

评论前必须登录!