In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "the method of building git server on Ubuntu". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the method of building git server on Ubuntu".
1. Install and configure git server
Install git: sudo apt-get install git-core
Add the user git, who will act as the manager of all code repositories and user permissions:
The code is as follows:
Sudo useradd-m git
Sudo passwd git
Set up a storage point for a git warehouse: sudo mkdir / home/repo
Let users other than git have no permissions on this directory:
The code is as follows:
Sudo chown git:git / home/repo
Sudo chmod 755 / home/repo
PS: set the repo property of the git warehouse to 755 here, otherwise the project will never be found in gitweb.
two。 Install and configure gitosis
Initialize the git user of the server, this step is actually in preparation for installing gitosis. To use git on any machine, you must initialize it for the first time:
The code is as follows:
Git config-global user.name "scorpio"
Git config-global user.email "zsw.scorpio@gmail.com"
Install python's setup tool, which is also in preparation for gitosis:
The code is as follows:
Sudo apt-get install python-setuptools
Get the gitosis package:
The code is as follows:
Cd / tmp
Git clone git://eagain.net/gitosis.git
Cd gitosis
Sudo python setup.py install
Switch to git user:
The code is as follows:
Su git
By default, gitosis puts the git repository under the home of git users, so let's make a link to / home/repo
The code is as follows:
Ln-s / home/repo / home/git/repositories
Return to the default user again
The code is as follows:
$exit
If you will be the administrator of the git server, generate the ssh public key on your computer:
Local: ssh-keygen-t rsa
Copy the public key to the server under / tmp:
Local: scp .ssh / id_rsa.pub git@xxoo.com:/tmp
Go back to the git server
The code is as follows:
Sudo chmod aquir / tmp/id_rsa.pub
Get gitosis up and running:
The code is as follows:
Sudo-H-u git gitosis-init
< /tmp/id_rsa.pub gitosis的有趣之处在于,它通过一个git仓库来管理配置文件,仓库就放在了/home/repo/gitosis- admin.git。我们需要为一个文件加上可执行权限: 代码如下: sudo passwd root su cd repositories cd gitosis-admin.git/ sudo chmod 755 /home/repo/gitosis-admin.git/hooks/post-update exit 3.在服务器上新建一个测试项目仓库 我们在服务器上新建一个空的项目仓库,叫"test"。 切换到git用户: 代码如下: su git cd /home/repo mkdir test.git cd test.git git init –bare注:这是在服务器上运行的,是为了初始化一个根级的git仓库 exit 这只是一个空仓库,空仓库是不能clone下来的。我们必须先修改一下gitosis-admin. 4.管理gitosis的配置文件 gitosis本身的配置也是通过git来实现的。在你自己的开发机里,把gitosis-admin.git这个仓库clone下来,就可以以管理员的身份修改配置了。 在你的电脑里: 代码如下: git clone git@xxoo.com:gitosis-admin.git cd gitosis-admin/ 该目录下的keydir目录是用来存放所有需要访问git服务器的用户的ssh公钥: 各个用户按照前面提到的办法生成各自的ssh公钥文件后,把所有人的 ssh公钥文件都拿来,按名字命名一下,比如b.pub, lz.pub等,统统拷贝到keydir下 修改gitosis.conf文件,我的配置大致如下: 代码如下: [gitosis] [group gitosis-admin] members = zsw.scorpio@gmail.com writable = gitosis-admin 加入新文件、提交并push到git服务器: 代码如下: git add . git commit -m "add" git push origin master 5.初始化测试项目 好了,现在服务器就搭建完了,并且有一个空的项目test在服务器上。接下来测试一下,空仓库是不能clone的,以下是在客户端完成。 代码如下: mkdir dev cd dev/ git init echo "/*add something*/" >Hello
Git add.
Git commit-m "initial version"
Git remote add origin git@xxoo.com:test.git
Git push origin master
At this point, there is already a version of test, and other members can play as long as they clone the teamwork repository.
The code is as follows:
Git clone git@xxoo.com:test.git
Cd teamwork
Vim hello
Git add.
Git commit-a "b add"
Git push origin master
Exit
6. Create gitweb
The code is as follows:
Sudo apt-get install gitweb
Configure gitweb
There is no css load by default, so connect the static files to be used by gitweb to the
The code is as follows:
Cd / var/www/
Sudo ln-s / usr/share/gitweb/*.
Modify configuration
The code is as follows:
Sudo vim / etc/gitweb.conf
Change $projectroot to the git repository directory (for example: / home/git/repositories), and refresh the browser after saving.
The code is as follows:
Http://xxoo.com/cgi-bin/gitweb.cgi
7. Modify / etc/gitweb.conf content
The code is as follows:
# path to git projects (.git)
# $projectroot = "/ var/cache/git"
$projectroot = "/ home/git/repositories"
# directory to use for temp files
$git_temp = "/ tmp"
# target of the home link on top of all pages
$home_link = $my_uri | | "/"
# html text to include at home page
$home_text = "indextext.html"
# file with project list; by default, simply scan the projectroot dir.
$projects_list = $projectroot
# stylesheet to use
@ stylesheets = ("/ gitweb/static/gitweb.css")
# javascript code for gitweb
$javascript = "gitweb/static/gitweb.js"
# logo to use
$logo = "/ gitweb/static/git-logo.png"
# the 'favicon'
$favicon = "/ gitweb/static/git-favicon.png"
# git-diff-tree (1) options to use for generated patches
# @ diff_opts = ("- M")
@ diff_opts = ()
8. Restart apache
The code is as follows:
Sudo / etc/init.d/apache2 restart
Thank you for reading, the above is the content of "the method of building git server on Ubuntu". After the study of this article, I believe you have a deeper understanding of the method of building git server on Ubuntu, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.