【Linux】【Services】【VersionControl】git-daemon, httpd, mysql搭建带认证的gitserver
1. 简介:
比较低端的gitserver,使用centos自带的git-daemon搭建gitserver,使用httpd做上传和下载,利用mod_auth_mysql做认证
2. 环境
# Apache的运行环境
apr-util-mysql.x86_64 1.5.2-6.el7 @base
# git server的主进程
git-daemon.x86_64 1.8.3.1-14.el7_5 @updates
# http服务器
httpd.x86_64 2.4.6-80.el7.centos.1 @updates
# httpd的开发库
httpd-devel.x86_64 2.4.6-80.el7.centos.1 @updates
# 让httpd支持mysql认证的库
libdbi-dbd-mysql.x86_64 0.8.3-16.el7 @base
# mysql客户端
mariadb.x86_64 1:5.5.56-2.el7 @base
# mysql服务器
mariadb-server.x86_64 1:5.5.56-2.el7 @base
# CentOS版本
CentOS Linux release 7.5.1804 (Core)
# 内核版本
Linux centos-0 3.10.0-693.17.1.el7.x86_64 #1 SMP Thu Jan 25 20:13:58 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
3. 安装
3.1. 安装必要的包
yum install -y git-daemon httpd httpd-devel mariadb mariadb-server libdbi-dbd-mysql apr-util-mysql
3.2. 检查httpd安装
# 修改http配置文件
~]# sed "s/\<ServerName/ServerName YOURSERVERIP:80/g" /etc/httpd/conf/httpd.conf # alias,cgi,env这三个模块必须要有
~]# httpd -M |grep -Ei "\<(alias|cgi|env)"
alias_module (shared)
env_module (shared)
cgi_module (shared)
~]# systemctl start httpd
3.3. 检查git-deamon安装
~]# cat /usr/lib/systemd/system/git@.service
[Unit]
Description=Git Repositories Server Daemon
Documentation=man:git-daemon(1) [Service]
User=nobody
ExecStart=-/usr/libexec/git-core/git-daemon --base-path=/var/lib/git --export-all --user-path=public_git --syslog --inetd --verbose
StandardInput=socket
~]# systemctl start git.socket
3.4. 检查mysql安装
~]# grep -Ev "^#|^$" /usr/lib/systemd/system/mariadb.service
[Unit]
Description=MariaDB database server
After=syslog.target
After=network.target
[Service]
Type=simple
User=mysql
Group=mysql
ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n
ExecStart=/usr/bin/mysqld_safe --basedir=/usr
ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID
TimeoutSec=300
PrivateTmp=true
[Install]
WantedBy=multi-user.target ~]# systemctl start mariadb
4. 配置
4.1. 配置git-deamon支持git协议
~]# cd /var/lib/git/
#初始化一个空的目录
~]# git init --bare myproject.git
Initialized empty Git repository in /var/lib/git/myproject.git/
#可以在其他客户端使用git clone git://IPADDRESS/myproject.git尝试下载了,但是目前只能下载,不能推送
4.2. 支持http方式的clone
#创建git目录并初始化仓库
~]# mkdir /var/www/git
~]# cd /var/www/git
~]# git init --bare testproject.git
~]# chown -R apache:apache /var/www/git #修改httpd配置文件的DocumentRoot
sed -i "s/^DocumentRoot/#&/" /etc/httpd/conf/httpd.conf
创建/etc/httpd/conf.d/git.conf
<VirtualHost *:80>
ServerName centos-0
#下面的参数可以使用man git-http-backend查看
SetEnv GIT_PROJECT_ROOT /var/www/git
#检查GIT是否支持smart功能,如果支持就打开smart功能
SetEnv GIT_HTTP_EXPORT_ALL
#要授权读或者写主要取决于/usr/libexec/git-core/目录的权限
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
<Directory "/usr/libexec/git-core/">
Options ExecCGI Indexes
Require all granted
</Directory>
</VirtualHost>
可以试着clone了
git clone http://IPADDRESS/git/testproject.git
但是目前依然不支持推送,如果想要推送需要在git的源上配置
git config http.receivepack true
4.3. 配置http支持文件认证
修改/etc/httpd/conf.d/git.conf
<VirtualHost *:80>
ServerName centos-0
#下面的参数可以使用man git-http-backend查看
SetEnv GIT_PROJECT_ROOT /var/www/git
#检查GIT是否支持smart功能,如果支持就打开smart功能
SetEnv GIT_HTTP_EXPORT_ALL
#要授权读或者写主要取决于/usr/libexec/git-core/目录的权限
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
<Directory "/usr/libexec/git-core/">
Options ExecCGI Indexes
Require all granted
</Directory>
<LocationMatch "^/git/.*/git-receive-pack$">
AuthType Basic
AuthName "Private Git Repo"
AuthUserFile /etc/httpd/conf/.htpasswd
Require valid-user
</LocationMatch>
</VirtualHost>
添加用户
htpasswd -c -m /etc/httpd/conf/.htpasswd eric
4.4. 安装libdbi-dbd-mysql模块,这个模块只支持2.4版本之后,同时还支持pgsql和sqlite,是apache的开源项目
redhat上的介绍:https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/ch-web_servers
apache上的介绍:https://httpd.apache.org/docs/2.4/mod/mod_authn_dbd.html
配置数据库
# 直接连数据库,没有密码
~]# mysql -uroot
#给root用户设置一个密码
> update mysql.user set password=PASSWORD('mysql') where user='root';
# 创建一个git用户
>CREATE USER 'git'@'localhost' IDENTIFIED BY 'git';
# 创建git库
>create database git;
# 给权限
>GRANT all ON git.* TO 'git'@'localhost';
# 创建一个users表
>create table users ( user_name varchar(191) not null, user_passwd varchar(191), user_group varchar(191), primary key (user_name) );
修改配置文件/etc/httpd/conf.d/git.conf
参考 https://www.seei.biz/mysql-authentication-on-apache-2-4/
<VirtualHost *:80>
#LoadModule mysql_auth_module modules/mod_auth_mysql.so
ServerName centos-0
#下面的参数可以使用man git-http-backend查看
SetEnv GIT_PROJECT_ROOT /var/www/git
#检查GIT是否支持smart功能,如果支持就打开smart功能
SetEnv GIT_HTTP_EXPORT_ALL
#要授权读或者写主要取决于/usr/libexec/git-core/目录的权限
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
#使用Mysql认证方式
DBDriver mysql
#数据库参数
DBDParams "host=localhost dbname=git user=git pass=git"
# Minimum number of connections
DBDMin 4
# Maximum sustained number of connections
DBDKeep 8
#Set the hard maximum number of connections per process
DBDMax 20
# Set the time to keep idle connections alive when the number of connections specified in DBDKeep has been exceeded
DBDExptime 300
<Directory "/usr/libexec/git-core/">
Options ExecCGI Indexes
Require all granted
</Directory>
<LocationMatch "^/git/.*/git-receive-pack$">
AuthType Basic
AuthName "Private Git Repo"
AuthDBDUserPWQuery "select user_passwd from users where user_name = %s and user_group = 'admin'"
AuthBasicProvider socache dbd
#AuthUserFile /etc/httpd/conf/.htpasswd
Require valid-user
</LocationMatch>
</VirtualHost>
创建一个用户并插入到数据库
# 利用http工具生成密码
~]# htpasswd -bns gitadmin gitadmin
admin:{SHA}0DPiKuNIrrVmD8IUCuw1hQxNqZc=
# 使用git用户连接数据库创建用户
~]# mysql -ugit -p
# 插入一条数据
> INSERT INTO `users` (`user_name`, `user_passwd`, `user_group`) VALUES('admin', '{SHA}0DPiKuNIrrVmD8IUCuw1hQxNqZc=', 'admin');
可以使用admin测试喽
【Linux】【Services】【VersionControl】git-daemon, httpd, mysql搭建带认证的gitserver的更多相关文章
- Linux下的Jenkins+Tomcat+Maven+Git+Shell环境的搭建使用(jenkins自动化部署)【转】
jenkins自动化部署 目标:jenkins上点构建(也可以自动检查代码变化自动构建)>>>项目部署完成. 一.安装jenkins 1.下载jenkins 这里我选择的是war包安 ...
- [jmeter]linux下自动测试环境+持续集成ant+jmeter+Apache(httpd)环境搭建与使用
前言:考虑搭建一个接口性能自动化测试平台,时间又比较紧急,所以就现想到了用jenkins+ant+jmeter完成,考虑到在linux环境中本身就可以设置定时任务,暂时该自动化用例还不与项目集成关联, ...
- Linux下Jenkins+git+gradle持续集成环境搭建
Linux下Jenkins+git+gradle持续集成环境搭建 来源:IT165收集 发布日期:2014-08-22 21:45:50 我来说两句(0)收藏本文 一.项目介绍 和 linux ...
- NFS实现(双httpd + php-fpm + nfs + mysql 搭建discuz论坛)的方法
NFS相关介绍 一.NFS简介 1. NFS(Network File System):NFS是一个文件共享协议, 也是是在类Unix系统中在内核中实现的文件系统. 2. 起源:最早是由SUN公司研发 ...
- linux应用之Lamp(apache+mysql+php)的源码安装(centos)
Linux+Apache+Mysql+Php源码安装 一.安装环境: 系统:Centos6.5x64 Apache: httpd-2.4.10.tar.gz Mysql: mysql-5.6.20-l ...
- 使用nodejs+express+socketio+mysql搭建聊天室
使用nodejs+express+socketio+mysql搭建聊天室 nodejs相关的资料已经很多了,我也是学习中吧,于是把socket的教程看了下,学着做了个聊天室,然后加入简单的操作mysq ...
- linux服务之git
http://www.cnblogs.com/fnng/archive/2011/08/25/2153807.html http://www.cnblogs.com/sunada2005/archiv ...
- Ubuntu+Django+Nginx+uWSGI+Mysql搭建Python Web服务器
Ubuntu+Django+Nginx+uWSGI+Mysql搭建Python Web服务器 闲着无聊的时候部署了一个Django项目玩,用vm虚拟机部署的. 准备工作 我使用的系统是Ubuntu16 ...
- Linux系统环境下Tomcat8、httpd、mysql8开机自启动配置
Linux系统环境下Tomcat8.httpd.mysql8开机自启动配置: 相关命令:chkconfig 参考链接:https://jingyan.baidu.com/article/6525d4b ...
随机推荐
- 2万字|30张图带你领略glibc内存管理精髓(因为OOM导致了上千万损失)
前言 大家好,我是雨乐. 5年前,在上家公司的时候,因为进程OOM造成了上千万的损失,当时用了一个月的时间来分析glibc源码,最终将问题彻底解决. 最近在逛知乎的时候,发现不少人有对malloc/f ...
- js事件常用操作、事件流
注册事件 给元素添加事件,称为注册事件或者绑定事件. 注册事件有两种方式:传统方式和方法监听注册方式 传统方式 on开头的事件,例如onclick <button onclick="a ...
- uni-app路径规划(打开第三方地图实现)
百度网盘链接:https://pan.baidu.com/s/1-Ys13GFcnKXB1wkJotcwMw 提取码:16gp 把js文件放在common目录下 引入: import pathP ...
- Linux usb 5. usbip (USB Over IP) 使用实例
文章目录 0. 简介 1. Server 配置 2. Client 配置 参考资料 0. 简介 USB Over IP 是一种应用很多的场景,目前已经有现成的解决方案 usbip.linux 和 wi ...
- 用户登录成功后重新获取新的Session
HttpSession session = request.getSession(); // 用来存储原sessionde的值 ConcurrentHash ...
- Flink 实践教程:入门(6):读取 PG 数据写入 ClickHouse
作者:腾讯云流计算 Oceanus 团队 流计算 Oceanus 简介 流计算 Oceanus 是大数据产品生态体系的实时化分析利器,是基于 Apache Flink 构建的具备一站开发.无缝连接.亚 ...
- 第五周PTA笔记 后缀表达式+后缀表达式计算
后缀表达式 所谓后缀表达式是指这样的一个表达式:式中不再引用括号,运算符号放在两个运算对象之后,所有计算按运算符号出现的顺序,严格地由左而右进行(不用考虑运算符的优先级). 如:中缀表达式 3(5–2 ...
- 数据结构知识总结(STL整理)
重要知识点 1.基础知识 #include<bits/stdc++.h> //万能头文件 #include< algorithm > //包含sort函数 运用sort实现多关 ...
- UML常用建模工具简介,安装方法和各自的优点
这学期学习了统一建模语言,自己初学时对各种建模工具十分陌生,各种名词都不懂,软件也都不了解,开始很是不知所措.为了防止其他初学者陷入我的困境,自己对各种工具进行了总结: Visio:介绍:Visio是 ...
- ICCV2021 | Vision Transformer中相对位置编码的反思与改进
前言 在计算机视觉中,相对位置编码的有效性还没有得到很好的研究,甚至仍然存在争议,本文分析了相对位置编码中的几个关键因素,提出了一种新的针对2D图像的相对位置编码方法,称为图像RPE(IRPE). ...