‘壹’ linux怎么挂载git服务器
一般来讲需要搭建版本管理和持续集成服务器,版本管理服务器有svn,git等,持续集成服务器有jenkin,hudson等
‘贰’ 如何用linux搭建git服务器,如果使用git
这个简单,你可以看看廖雪峰的git教程,http://www.liaoxuefeng.com/wiki/我就是在上面学的。花了2天时间,基本上掌握了。
如果你学Linux可以看看刘遄老师的博客www.linuxprobe.com上面还是很多干货。
‘叁’ 如何搭建linux git服务器与客户端
1.创建Gitblit安装目录 首先我们将在我们的服务器上建立一个目录,并在该目录下安装最新的Gitblit。 $ sudo mkdir -p /opt/gitblit $ cd /opt/gitblit 创建gitblit目录 2. 并解压 现在,我们将从Gitblit官方站点最新版的Gitblit。
‘肆’ 本地git软件怎么连接linux服务器地址
1、前期准备
服务器上配置好的git
git客户端
1.1
在服务器上安装git (本机所使用的linux是ubuntu)
在服务器输入命令:sudo apt-get install git即可 然后创建名字为git的用户组和用户
1.2
下载客户端 在浏览器地址栏输入:https://git-for-windows.github.io/
回车后
点击Download进行下载
2、具体操作
2.1
在合适的位置创建一个目录充当git远程仓库(本机位置为/usr/testgit),然后使用init命令初始化仓库
在命令终端输入:
sudo git init –bare
2.2
将git init生成的目录所属者改为git
输入命令:sudo chown -R git:git *
至此服务器端的操作完成。
在客户端合适位置使用git 客户端从服务器资源
2.3
首先打开git客户端
点击Git Bash Here 后出现
在git客户端命名终端输入:
git clone git@xxxxxx:/rrrrr 其中xxxxxx是远程服务器的地址 rrrrr为git仓库所在位置
如果配置正确你选中的目录下会出现名字为testgit的文件夹 testgit文件夹下随意创建若干个文件
2.3
在git客户端上使用命令 git add 111.txt 222.txt 333.txt 或者使用git add .(将本文件夹下所有文件都add) 该命令的作用是告诉git把文件添加到git仓库
2.4
然后使用git commit命令将文件提交到git仓库
-m 后面的内容为本次提交文件的一些注释内容
此时文件还没有从本地仓库上传到远程服务器仓库
2.5
使用push命令将本地仓库中的内容提交到远程仓库
在git客户端命令终端输入:git push origin master
至此本地仓库中的文件上传已经上传到远程服务器仓库。
在其他文件夹下再次使用 git clone 命令 从远程服务器同步仓库
‘伍’ 如何在linux上使用hexo搭建git博客
安装前提
安装 Hexo 非常简单。需要预先安装:
Node.js
Git
在 Ubuntu 14.04/15.04 上安装配置 Node.js v4.0.0 http://www.linuxidc.com/Linux/2015-10/123951.htm
如何在CentOS 7安装Node.js http://www.linuxidc.com/Linux/2015-02/113554.htm
Ubuntu 14.04下搭建Node.js开发环境 http://www.linuxidc.com/Linux/2014-12/110983.htm
Git 服务器搭建与客户端安装 http://www.linuxidc.com/Linux
Ubuntu下Git服务器的搭建与使用指南 http://www.linuxidc.com/Linux/2015-07/120617.htm
准备条件做好了之后就可以开始安装Hexo了
安装Hexo
打开Git Bash 执行命令
1
$ npm install -g hexo-cli
创建博客
Hexo安装完成后,分别执行如下命令,Hexo会自动生成需要的文件夹
1
2
3
$ hexo init <folder> ##<folder> 为你指定的文件地址
$ cd <folder>
$ npm install
例如:需要将博客搭建在本地的D:\my_hexo下,则分别执行命令:hexo init D:\my_hexo ,cd D:\my_hexo,npm install
执行完命令后如果没有问题我们就可以执行启动命令来查看我们的博客了.
本地预览
1
2
3
$ hexo server ## 启动服务,默认端口4000
$ hexo server -p xxxx ## 自定义端口启动服务
$ hexo clean ## 清除缓存,在页面显示不正常的时候可以执行此命令
然后在浏览器输入http://127.0.0.1:4000/ 即可访问
创建Repository
登录github 点击右上角的”+”,Create a new repository
Create a new repository
复制刚刚新建的https连接:https://github.com/Admol/admol.github.io.git
打开你hexo目录下的_config.yml
设置deploy信息,如:
1
2
3
4
deploy:
type: git
repository: https://github.com/Admol/admol.github.io.git
branch: master
设置SSH key
检验是否已存在key
分别执行命令
1
2
cd ~
cd .ssh
再执行命令 ls 查看是有已有key文件,一般存在key的话都会显示id_rsa.pub 和 id_dsa.pub这两个文件,没有key什么都不会显示
添加一个 SSH key
执行命令(已有key的可以跳过步骤2):
1
2
3
$ ssh-keygen -t rsa -C "[email protected]"
## t 指定密钥类型,默认是 rsa ,可以省略。 -C 设置注释文字,比如邮箱或其他。
然后会提示你 Enter Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter,这里是输入一个文件名用来保存ssh key,也可以什么都不输,会使用默认的id_rsa.pub 和 id_dsa.pub
回车之后,需要输入两次密码(该密码是你push文件的时候要输入的密码,而不是github的密码)
输入密码之后,看见如下显示信息,添加SSH key成功.
Github 设置 SSH key
登录github,点击Settings,然后点击 SSH keys ,在这个页面你可以管理你所有的ssh keys
然后点击Add SSH key
用文本编辑器打开刚刚添加的key文件id_rsa.pub,复制里面的所有的内容
回到github页面,将复制的内容粘贴到刚刚那个页面的key对应的文本框里面,title 可以随便填写
测试ssh key 是否添加成功
在命令行输入:
1
$ ssh -T [email protected]
会出现一段警告代码,输入yes回车,然后会要求你输入刚刚设置的密码,然后它会和你说:Hi,帅哥....约吗
到此SSH key就设置完毕了
部署到Github
打开命令窗口,回到你的hexo博客目录下,如别执行如下命令:
1
2
hexo generate
hexo deploy
等待命令执行完毕后,可以查看代码是否已提交到github上,然后在浏览器输入admol.github.io就可以访问了
新建页面
1
$ hexo new page 'pageName'
执行命令后可以在你本地的/source 目录下看见以为你新增页面名为名的文件夹
显示页面
打开文件后可以对index.md 进行编辑.然后打开/themes/jacman目录下的_config.yml文件(自己正在使用的主题),
添加刚刚新增的页面:
1
2
3
4
5
menu:
首页: /
统计: /archives
关于: /about
pageName: /pageName ##前面的pageName可以自定义,后面的pageName必须写刚刚新增的页面名称
新建文章
1
$ hexo new [layout] 'name'
[layout] 为可选,不写默认为post. /source 目录下的文件夹名称即为 layout 名
安装主题
1
$ git clone https://github.com/JamesPan/hexo-theme-icarus.git themes/icarus
更换主题
首先下载主题,然后打开根目录下的 _cinfig.yml ,修改 theme: 要更换的主题名
修改主题颜色
打开 /themes/jacman目录下的_config.yml文件,修改:
1
2
theme_color:
theme: '色值'
修改logo图片
打开主题下的 _config.yml 文件,修改:
1
2
3
4
imglogo:
enable: false ## 是否显示logo
src: img/logo.gif ## logo图片地址
favicon: img/qq.ico ## 页面左上角图标
Hexo 版本升级
1
$ npm update hexo -g
‘陆’ 如何搭建linux git服务器
首先我们分别在Git服务器和客户机中安装Git服务程序(刚刚实验安装过就不用安装了):
[root@linuxprobe ~]# yum install git
Loaded plugins: langpacks, proct-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Package git-1.8.3.1-4.el7.x86_64 already installed and latest version
Nothing to do
然后创建Git版本仓库,一般规范的方式要以.git为后缀:
[root@linuxprobe ~]# mkdir linuxprobe.git
修改Git版本仓库的所有者与所有组:
[root@linuxprobe ~]# chown -Rf git:git linuxprobe.git/
初始化Git版本仓库:
[root@linuxprobe ~]# cd linuxprobe.git/
[root@linuxprobe linuxprobe.git]# git --bare init
Initialized empty Git repository in /root/linuxprobe.git/
其实此时你的Git服务器就已经部署好了,但用户还不能向你推送数据,也不能克隆你的Git版本仓库,因为我们要在服务器上开放至少一种支持Git的协议,比如HTTP/HTTPS/SSH等,现在用的最多的就是HTTPS和SSH,我们切换至Git客户机来生成SSH密钥:
[root@linuxprobe ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
65:4a:53:0d:4f:ee:49:4f:94:24:82:16:7a:dd:1f:28 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| .o+oo.o. |
| .oo *.+. |
| ..+ E * o |
| o = + = . |
| S o o |
| |
| |
| |
| |
+-----------------+
将客户机的公钥传递给Git服务器:
[root@linuxprobe ~]# ssh--id 192.168.10.10
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.10.10'"
and check to make sure that only the key(s) you wanted were added.
此时就已经可以从Git服务器中克隆版本仓库了(此时目录内没有文件是正常的):
[root@linuxprobe ~]# git clone [email protected]:/root/linuxprobe.git
Cloning into 'linuxprobe'...
warning: You appear to have cloned an empty repository.
[root@linuxprobe ~]# cd linuxprobe
[root@linuxprobe linuxprobe]#
初始化下Git工作环境:
[root@linuxprobe ~]# git config --global user.name "Liu Chuan"
[root@linuxprobe ~]# git config --global user.email "[email protected]"
[root@linuxprobe ~]# git config --global core.editor vim
向Git版本仓库中提交一个新文件:
[root@linuxprobe linuxprobe]# echo "I successfully cloned the Git repository" > readme.txt
[root@linuxprobe linuxprobe]# git add readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: readme.txt
#
[root@linuxprobe linuxprobe]# git commit -m "Clone the Git repository"
[master (root-commit) c3961c9] Clone the Git repository
Committer: root
1 file changed, 1 insertion(+)
create mode 100644 readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
nothing to commit, working directory clean
但是这次的操作还是只将文件提交到了本地的Git版本仓库,并没有推送到远程Git服务器,所以我们来定义下远程的Git服务器吧:
[root@linuxprobe linuxprobe]# git remote add server [email protected]:/root/linuxprobe.git
将文件提交到远程Git服务器吧:
[root@linuxprobe linuxprobe]# git push -u server master
Counting objects: 3, done.
Writing objects: 100% (3/3), 261 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:/root/linuxprobe.git
* [new branch] master -> master
Branch master set up to track remote branch master from server.
为了验证真的是推送到了远程的Git服务,你可以换个目录再克隆一份版本仓库(虽然在工作中毫无意义):
[root@linuxprobe linuxprobe]# cd ../Desktop
[root@linuxprobe Desktop]# git clone [email protected]:/root/linuxprobe.git
Cloning into 'linuxprobe'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[root@linuxprobe Desktop]# cd linuxprobe/
[root@linuxprobe linuxprobe]# cat readme.txt
I successfully cloned the Git repository
这篇是详细介绍Git的,中间有一部分是怎么去搭建,你可以看下
‘柒’ 怎样在linux 上搭建git +apache服务器
1:服务器端创建用户(git)
# sudo adsergit
2:客户端生成公钥,并
创建公钥:ssh-keygen,
在客户端的用户目录下查看生成的公钥和私钥对
#cd ~/.ssh
#ls
id_dsa id_dsa.pub
公钥所在的目录:windows在”C:/User/username/.ssh”目录下,linux在”~/.ssh”,~代表用户目录
3:服务器git用户下添加各个用户公钥,并配置ssh服务
将各个用户的公钥文件追加在服务器git用户的authorized_keys文件中
$ cat id_rsa.john.pub >> ~/.ssh/authorized_keys
$ cat id_rsa.josie.pub >> ~/.ssh/authorized_keys
$ cat id_rsa.jessica.pub >> ~/.ssh/authorized_keys
修改.ssh和authorized_keys的权限).忘记下面的话,会每次输入密码,(ps,被这个坑了好久)
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
4,在git用户下创建git库
cd gitDIR
mkdir project.git
cd project.git
git init –bare
5,客户端使用
提交自己的库
mkdir project
cd project
git init
vi first.txt
git remote add origin gitserver/gitDIR/project.git
git push origin master
克隆:git clonegit@gitserver/gitDIR/project.git
6,限制开发者登陆
默认情况下,能够连接git服务器用户也可以通过ssh直接登陆服务器,那么服务器将会存在被多用户登入的风险,限制的方法是:
Vi /etc/passwd
git:x:1000:1000::/home/git:/bin/sh
该行修改后的样子如下:
git:x:1000:1000::/home/git:/bin/git-shell
‘捌’ 如何在服务器上搭建git服务器
安装步骤此处略去。
END
安装CopSSH
安装步骤此处略去。
END
修改配置
修改CopSSH配置文件C:\Program Files\ICW\etc\sshd_config,确保如下行为非注释行,且设置为“no”:
END
生成用户帐号
1
在服务器上生成Windows用户,取消用户下次登录时须更改密码,设置密码永不过期:
2
将该用户隶属于GitUser组(如尚未生成改组,则先生成改组):
END
激活用户
在Windows启动程序组中,运行如下程序(C:\Program Files\ICW\bin\ copsshcp.exe):
进入COPSSH Control Panel应用对话框,正常情况下服务应该为正在运行(图标为绿色,如为红色,则可尝试点选该按钮,启动该服务):
选择Users页面:
点选Add按钮,出现如下导航对话框:
选择Forward按钮,出现如下页面,选择欲激活的用户对应的域名及用户名:
选择Forward按钮,进入如下页面,选择Linux shell and Sftp,所有选项选中:
选择Forward按钮,进入确认页面,选择Apply:
回到如下页面,选择Apply后,关闭。
‘玖’ linux搭建git服务器后怎么使用
linux搭建git服务器后怎么使用GitHub就是一个免费托管开源代码的远程仓库。但是对于某些视源代码如生命的商业公司来说,既不想公开源代码,又舍不得给GitHub交保护费,那就只能自己搭建一台Git服务器作为私有仓库使用。linux搭建git服务器后怎么使用