CENTOS 7搭建GIT服务器

Centos 下构建私有git服务器

以下操作都是root账户

安装

第一步,安装git服务

yun install -y git

第二步,新建git用户

useradd git

第三步,禁止git用户,shell登录

修改/etc/passwd

git:x:1010:1010:,,,:/home/git:/bin/bash  改为  git:x:1010:1010:,,,:/home/git:/usr/bin/git/git-shell

第四步,创建证书登录

使用命令ssh-keygen -t rsa -C “xxxxx@xxxxx.com生成公钥,Windows可以通过git bash执行命令,然后找到id_rsa.pub把文件内容导入 /home/git/.ssh/authorized_keys,如果没有文件

cd /home/git

mkdir .ssh

touch .ssh/authorized_keys

第五步,初始化git仓库

在/home/git 下新建仓库目录

mkdir repository

新建仓库,赋予权限

git init --bare test.git

chown -R git:git test.git

第六步,克隆仓库

git clone git@server:/home/git/repository/test.git  # server 可以是域名也可以是ip看配置
Cloning into 'test'...
warning: You appear to have cloned an empty repository.

遇到的问题

上面的都是理想状态下的流程

端口问题

git默认是22端口,如果服务器有修改端口,执行上面的clone会报错

$ git clone git@111.111.111.111:/home/git/repository/test.git
Cloning into 'test'...
ssh: connect to host 111.111.111.111 port 22: Connection timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

正确的方式

git clone ssh://git@111.111.111.111:1111/home/git/repository/test.git

权限问题

Cloning into 'xigoubao'...
fatal: '/home/git/repository/test.git' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

如果路径写错了,或者test.git拥有者和组不是git,会报这个错误

示例,路径写错

git clone ssh://git@111.111.111.111:1111/home/git/respository/test.git  # repository 拼错

git clone ssh://git@111.111.111.111:1111/repository/test.git   # 路径必须为相对于git用户的home目录路径  /home/git/repository/test.git

权限的话,执行命令就可以了

chown -R git.git test.git

CentOS 7 下编译Nginx并打包成rpm

上次说的,最近喜欢上了折腾Nginx。作为一个Web从业人员,越来越觉得Nginx太强大了。

于是便花了几天时间研究在Debian及CentOS下从源代码开始将Nginx打包成deb/rpm,这篇是记录CentOS 7 下将Nginx打包成rpm。

安装软件之前肯定是先要更新:

yum update

安装编译环境:

yum install gcc gcc-c++ rpm-build

安装Nginx所依赖的包:

yum install -y openssl-devel zlib-devel pcre-devel gd-devel

新建用户:

name=rpmbuild

useradd $name

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

su - $name

进入SOURCES目录:

cd ~/SOURCES/

在新建的用户home目录创建接下来要用到的几个文件夹:

rpmdev-setuptree

这样在rpmbuild的home目录下面有了这几个目录:

BUILD BUILDROOT RPMS SOURCES SPECS SRPMS

到这个地址找到合适的源码包下载: nginx package

下载源码,当前(2016-06-16)最新为nginx-1.10.1-1.el7.ngx.src.rpm:

wget http://nginx.org/packages/centos/7/SRPMS/nginx-1.10.1-1.el7.ngx.src.rpm

解压:

rpm2cpio nginx-1.10.1-1.el7.ngx.src.rpm |cpio -dvi

里面应该有这么些个文件:

[root@790fde35905f SOURCES]# ls
COPYRIGHT nginx-debug.sysconf nginx.sysconf
logrotate nginx.conf nginx.upgrade.sh
nginx-1.10.1 nginx.init.in nginx.vh.default.conf
nginx-1.10.1-1.el7.ngx.src.rpm nginx.service njs-1c50334fbea6.tar.gz
nginx-1.10.1.tar.gz nginx.spec
nginx-debug.service nginx.suse.logrotate

开始编译:

rpmbuild -ba nginx.spec

如果没有意外的话,在~/rpmbuild/RPMS/x86_64下面应该生成了对应的rpm包:

nginx-1.10.1-1.el7.centos.ngx.x86_64.rpm
nginx-debuginfo-1.10.1-1.el7.centos.ngx.x86_64.rpm
nginx-module-geoip-1.10.1-1.el7.centos.ngx.x86_64.rpm
nginx-module-image-filter-1.10.1-1.el7.centos.ngx.x86_64.rpm
nginx-module-njs-1.10.1.0.0.20160414.1c50334fbea6-1.el7.centos.ngx.x86_64.rpm
nginx-module-perl-1.10.1-1.el7.centos.ngx.x86_64.rpm
nginx-module-xslt-1.10.1-1.el7.centos.ngx.x86_64.rpm

上面是按照Nginx默认的configure配置打包成的rpm,既然选择了自主打包而不是使用Nginx官方打包好的rpm,肯定是有些模块Nginx打包的不包含,自主打包也就是想把我们需要的模块加进Nginx而又不想在生产服务器安装一大堆包,所以,为了加进我们所需要的模块,我们可以更改上面哪个nginx.spec文件,加进我们所需要的模块,怎么加进去可以参考我先前的一篇文章Debian 8 下编译Nginx笔记。

进过我实际编译,暂时发现我所需要的两个额外模块Google Filter和PageSpeed中Google Filter可以正常编译进去,但是PageSpeed会报错,暂时没找到解决办法,有时间我再折腾一下。