























虽然网上有很多关于CVS服务器的配置文档供大家参考,但是本着“纸上得来终觉浅,绝知此事须躬行”的态度,还是自己动手安装一下。因为别人配置的环境和 自己的毕竟不大一样,操作起来可能会有一些步骤有问题。只有我们自己遇到问题并解决时,才能够对CVS服务器的配置理解的更加深入。也建议各位需要用到CVS的朋友也动手装一下,实现你自己的CVS服务器。
闲话少说,转入正题。我用的操作系统是:Fedora 7
(注意:以下操作是以root身份操作的#su root)
|
# rpm -qa|grep cvs cvs-1.11.22-9.fc7 |

如果命令输出类似于上面的输出则说明系统已经安装有cvs,否则就需要从安装光盘中安装cvs的rpm包。
但安装完Fedora7后系统自己就安装好CVS软件了。
前期工作:
Fedora7默认是没有安装上xinetd服务,所以先安装xinetd服务
|
#yum install xinetd |
|
#/usr/sbin/groupadd cvs |
|
#mkdir /home/cvsroot |
|
#/usr/sbin/useradd -g cvs -G cvs -d /home/cvsroot cvsroot |
|
#passwd cvsroot Changing password for user cvsroot. 新的 UNIX 口令: 重新输入新的 UNIX 口令: passwd: all authentication tokens updated successfully. |
因为是在root用户下间的该目录,他的属主和属组都是root,这里我们要将其属主改为cvsroot,属组改为cvs,保证cvs组的用户对该目录有相应的权限。
|
# chown -R cvsroot.cvs /home/cvsroot/ |
保证cvsroot同组(cvs组)的其他用户也有读写和执行权,我们以后要为cvs组添加用户
|
# chmod -R 775 /home/cvsroot/ |
(注意:以下操作是以cvsroot身份进行操作的)
|
#su cvsroot 口令: bash-3.2$ |
|
$export CVSROOT=/home/cvsroot/ |
|
$ cvs init |
OK,到目前为目止,就可以在本机上以cvsroot身份提交源代码了
我这里是/home/HelloWorld/
|
bash-3.2$ cd /home/HelloWorld/ bash-3.2$ ls helloworld.cpp makefile |
装载cvs import -m "[repository test]" [cvstest] [vendortag] [releasetag]
-m后面引号内填入log内容,接下来是源代码模块名称,接着是装载者,最后是标识符号,我这里是:
|
$ cvs import -m "my cvs project" myProject cvsroot start N myProject/makefile N myProject/helloworld.cpp No conflicts created by this import |
此时,我们的源码也提交了,说明module已经建立了。其目录为:/home/cvsroot/myProject/
|
$ ls -l /home/cvsroot 总计 20 drwxrwxr-x 3 cvsroot cvs 4096 10-14 10:59 CVSROOT drwxrwxr-x 2 cvsroot cvs 4096 10-14 12:11 myProject |
如果我们在root用户(或者其他用户,但必须保证该用户对于存放module的目录有写的权限)下测试,checkout出这一个module,可以执行如下:
|
# cvs -d /home/cvsroot checkout myProject cvs checkout: Updating myProject U myProject/helloworld.cpp U myProject/makefile |
说明在本地可以checkout出来,而且他会自动在当前目录下创建以该module名为名的目录项,不管你checkout出来的是一个源码文件还是整个module。
CVS默认使用系统用户登录,为了系统安全性的考虑也可以使用独立的用户管理。CVS用户名和密码保存在CVSROOT目录下的passwd文件中,格式为:
[cvs 用户名]:[加密的口令]:[等效系统用户名]
|
$ cd /home/cvsroot/CVSROOT/ $ htpasswd -c passwd cvsuser New password: Re-type new password: Adding password for user cvsuser $ cat passwd cvsuser:R9oDKNeysScdw $vi passwd 在末尾添加 :cvsroot 作用是映射到cvsroot用户,最终结果如下: cvsuser:R9oDKNeysScdw:cvsroot |
|
#htpasswd passwd 用户名 New password: Re-type new password: |
要彻底防止使用系统帐号登陆,可以编辑CVSROOT目录下的config文件,把:
#SystemAuth=yes
这一行前面的#去掉,改为如下形式:
SystemAuth=no
CVS就不会验证系统用户了,否则当用户名不在passwd文件中时,CVS会进行系统用户的验证。
使用 CVSROOT目录下的readers和writers文件进行这个工作。这2个文件默认也是没有的,没关系,自己创建就可以了。
readers文件记录 拥有只读权限的用户名,每行一个用户;
writers文件记录拥有读写权限的用户名,也是每行一个用户。
注意, readers文件比writers优先,也就是说出现在readers中的用户将会是只读的,不管writers文件中是否存在该用户。
cvspserver是远程登录CVS服务器时对用户的验证方式。
|
$cat /etc/services | grep cvspserver cvspserver 2401/tcp # CVS client/server operations cvspserver 2401/udp # CVS client/server operations |
如果命令输出类似于上面的输出,这说明我的系统已打开该服务。
切换至root用户下:
|
#su root cd /etc/xinetd.d/ #vi cvspserver |
编辑该文件,内容如下:
|
service cvspserver { |
其中,--allow-root=/home/cvsroot即仓库所在目录。
注意:每行的第一个"="左右两侧要有一个空格。
否则的话,在后面的远程登录本机时会出现下面的问题
“没有该仓库”
|
[test@liu ~]$ cvs -d :pserver:cvsuser@10.15.5.89:/home/cvsroot login Logging in to :pserver:cvsuser@10.15.5.89:2401/home/cvsroot CVS password: /home/cvsroot: no such repository [test@liu ~]$ |
更改方法如下:
把disable=yes 改为 disable=no ;env和server_args中路径改为你的cvsroot路径,我的是/home/cvsroot
更改后的内容如下
|
# default: off # description: The CVS service can record the history of your source " # files. CVS stores all the versions of a file in a single " # file in a clever way that only stores the differences " # between versions. service cvspserver { disable = no port = 2401 socket_type = stream protocol = tcp wait = no user = root passenv = PATH server = /usr/bin/cvs env = HOME=/home/cvsroot server_args = -f --allow-root=/home/cvsroot pserver # bind = 127.0.0.1 } |
重启xinetd
|
# /etc/init.d/xinetd restart 停止 xinetd: [确定] 启动 xinetd: [确定] |
确定cvspserver是否启动
|
#netstat -l | grep cvspserver tcp 0 0 *:cvspserver *:* LISTEN |
|
#/sbin/iptables -L&line;grep cvs |
如果看到
|
ACCEPT tcp -- anywhere anywhere tcp dpt:cvspserver |
说明端口已经打开,否则请打开防火墙2401端口
|
#/sbin/iptables -A INPUT -i eth0 -p tcp --dport 2401 -j ACCEPT #/sbin/service iptables save |
至此,CVS服务器配置全部完成,下面进行测试。
刚才建立的CVS服务器端的IP为:10.15.5.89
客户端主机使用非root用户,我的用户名为test
首先建立环境变量CVSROOT,以刚才建立的CVS用户cvsuser登录:
|
[test@liu ~]$ export CVSROOT=:pserver:cvsuser@10.15.5.89:/home/cvsroot [test@liu ~]$ cvs login Logging in to :pserver:cvsuser@10.15.5.89:2401/home/cvsroot CVS password: [test@liu ~]$ |
如果没有错误提示,则代表成功登录CVS服务器。
---------------------------------------
在此却很有可能出现:unrecognized auth response from 10.15.5.89: cvs pserver: cannot open /home/cvsroot/CVSROOT/config: Permission denied
尤其是当你的linux版本较高时。
这是由于selinux的原因,这是一种安全机制,具体可以上网查。
只要关闭selinux就可以了:
编辑/etc/selinux/config,
将SELINUX设置为SELINUX=disabled,禁用SELINUX。
重启电脑就好了
---------------------------------------
我们上面已经建立了一个仓库了: myProject
我们在客户端将该模块checkout
|
[test@liu ~]$ cvs checkout myProject cvs checkout: Updating myProject U myProject/helloworld.cpp U myProject/makefile [test@liu ~]$ |
好了,在当前目录下生成了目录myProject,现在你就可以进入myProject进行修改,删除,提交等操作了。
注意,我们用cvsroot仅仅是用来管理,所以,不要在它$HOME下面创建任何仓库
另外,cvsroot用户的初始环境不应该包含非空的$CVSROOT.(也就是必须设置环境变量) 使用cvsroot来进行的任何管理工作都指明CVSROOT是一个好的习惯.
OK,开始给单个项目建仓库
假设有两个项目,project1,project2,希望单独存放,便于管理
|
#mkdir /home/cvsroot/pro1 #mkdir /home/cvsroot/pro2 |
|
#chown cvsroot.cvs /home/cvsroot/pro1 #chown cvsroot.cvs /home/cvsroot/pro2 |
|
#chmod 2775 /home/cvsroot/pro1 #chmod 2775 /home/cvsroot/pro2 |
(更高的安全要求则$chmod 2770 /home/cvsroot/pro1)
|
#su cvsroot |
|
$cvs -d /home/cvsroot/pro1 init $cvs -d /home/cvsroot/pro2 init |
|
$chmod 2775 /home/cvsroot/pro1 $chmod 2775 /home/cvsroot/pro2 |
|
#vi /etc/xinetd.d/cvspserver |
内容如下:
|
service cvspserver |
然后更改/etc/xinetd.d/cvs, 否则的话,在后面的远程登录本机时会出现下面的问题
“没有该仓库”
|
[test@liu ~]$ cvs -d :pserver:cvsuser@10.15.5.89:/home/cvsroot/pro1 login Logging in to :pserver:cvsuser@10.15.5.89:2401/home/cvsroot/pro1 CVS password: /home/cvsroot/pro1: no such repository [test@liu ~]$ |
更改方法如下:
把disable=yes 改为 disable=no ;env和server_args中路径改为你的cvsroot路径,我的是/home/cvsroot
更改后的内容如下
|
# default: off # description: The CVS service can record the history of your source " # files. CVS stores all the versions of a file in a single " # file in a clever way that only stores the differences " # between versions. service cvspserver { disable = no port = 2401 socket_type = stream protocol = tcp wait = no user = root passenv = PATH server = /usr/bin/cvs env = HOME=/home/cvsroot server_args = -f –allow-root=/home/cvsroot/pro1 --allow-root=/home/cvsroot/pro2 pserver # bind = 127.0.0.1 } |
重启xinetd
|
# /etc/init.d/xinetd restart 停止 xinetd: [确定] 启动 xinetd: [确定] |
由于xinetd的server_args长度限制,当你想运行很多的单个仓库的时候,可以这么做
|
#vi /etc/xinetd.d/cvspserver #vi /etc/xinetd.d/cvs |
修改它们的内容中如下:
|
service cvspserver |
|
#vi /home/cvsroot/cvs.run |
脚本内容如下:
|
#!/bin/bash /usr/bin/cvs -f " |
|
#chmod +x /home/cvsroot/cvs.run |
|
#service xinetd restart |
好了,现在多个独立的仓库也建立好了
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。