Ubuntu下集成Apache+Trac+Git

ps:没有一边操作一边记录,可能有个别地方权限设置有点问题请注意

软件安装

安装Python setuptools

sudo apt-get install python-setuptools

安装easy_install

aptitude install python-setuptools

安装git和apache

sudo apt-get install git apache 配置git服务器 安装gitosis git clone git://eagain.net/gitosis.git cd gitosis sudo python setup.py install 添加用户git sudo adduser \ --system \ --shell /bin/sh \ --gecos 'git version control' \ --group \ --disabled-password \ --home /home/git \ git 生成本机密钥
切换到个人机,如果已有~/.ssh/id_rsa.pub略过此步 ssh-keygen -t rsa 上传密钥到服务器临时目录 scp ~/.ssh/id_rsa.pub 用户名@主机:/tmp 初使化gitosis
切回到服务器 sudo -H -u git gitosis-init < /tmp/id_rsa.pub 修改post-update权限 sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update clone gitosis管理平台
切换到本地 git clone git@主机名:gitosis-admin.git cd gitosis-admin

到此git服务器配置完成,以下是git服务器的一些常用管理。

添加用户 要添加的用户在电脑上运行ssh-keygen -t rsa生成id_rsa.pub发送给git管理员 git管理员将用户的id_rsa.pub复制到gitosis-admin下的keydir目录下,将文件名修改为要添加的用户名 git管理员修改gitosis-admin目录下的gitosis.conf文件,在要授权的项目下的members一行添加该用户名,中间以空格隔开 上传修改 cd gitosis-admin git add gitosis.conf cd keydir git add {用户的id_rsa.pub文件名} git commit -m "添中用户XXX" git push 创建项目的git版本库 修改gitosis.conf文件 cd gitosis-admin vim gitosis.conf

在文件最后添加以下内容

[group test] members = {要授权的用户,以空格分隔} writable = test 提交修改 git add gitosis.conf git commit -m "添加项目test的配置" git push 创建项目库 mkdir test git init touch README git add README git commit -m '创建项目' git remote add origin git@{你的域名}:test.git git push -u origin master 安装trac 安装Genshi wget tar xzvf Genshi-0.6.tar.gz cd Genshi-0.6 sudo python setup.py install 安装本地化的模块 Babel。以支持国际化 easy_install babel 安装Trac wget tar xzvf Trac-0.12.2.tar.gz cd Trac-0.12.2 sudo python setup.py install 集成trac和apache 在web根目录下创建trac目录 cd /var/www sudo mkdir trac sudo chown www-data:www-data trac 添加trac虚拟主机配置 cd /etc/apache/conf.d sudo vim trac 在vim中插入以下配置 DocumentRoot "/var/www/trac" ServerName trac.{你的域名} SetHandler mod_python PythonInterpreter main_interpreter PythonHandler trac.web.modpython_frontend PythonOption TracEnvParentDir /var/www/trac PythonOption TracUriRoot / PythonOption PYTHON_EGG_CACHE /tmp/egg-cache 重启apache sudo /etc/init.d/apache2 restart

接下来访问{你的域名},如果看到“Available Projects”字样,就说明配置成功了。

建立项目 cd /var/www/trac trac-admin test initenv chown -R www-data.www-data test

然后访问{youhost}/test,即可看到Trac的主界面了!

添加用户 cd /var/www htpasswd -c .htpasswd admin

如果已经有.htpasswd文件(第二次添加用户)则去掉-c
修改虚拟主机配置

DocumentRoot "/var/www/trac" ServerName trac.{你的域名} SetHandler mod_python PythonInterpreter main_interpreter PythonHandler trac.web.modpython_frontend PythonOption TracEnvParentDir /var/www/trac PythonOption TracUriRoot / PythonOption PYTHON_EGG_CACHE /tmp/egg-cache AuthType Basic AuthName "My Trac Server" AuthUserFile /var/www/.htpasswd Require valid-user 集成trac和git 安装trac-git的插件, 项目地址为: easy_install 更新trac配置 cd /var/www/trac/ vim trac.ini

在文件最后加上

[trac] # simple single-repository configuration repository_dir = /var/git/Test.git repository_type = git ## the following settings are only supported for plugin version 0.11 or later [git] ## let Trac cache meta-data via CachedRepository wrapper; default: false cached_repository = true ## disable automatic garbage collection for in-memory commit-tree cache; default: false persistent_cache = true ## length revision sha-sums should be tried to be abbreviated to (must be >= 4 and <= 40); default: 7 shortrev_len = 6 ## (0.12.0.3+) minimum length for which hex-strings will be interpreted as commit ids in wiki context; default: 40 wiki_shortrev_len = 7 ## executable file name (in case of doubt use absolute path!) of git binary; default: 'git' git_bin = /usr/src/git-dev/git ## (0.12.0.5+) define charset encoding of paths stored within git repository; default: 'utf-8' git_fs_encoding = latin1 ## (0.12.0.3+) enable reverse mapping of git email addresses to trac user ids; default: false trac_user_rlookup = true ## (0.12.0.3+) use git-committer id instead of git-author id as changeset owner; default: true use_committer_id = false ## (0.12.0.3+) use git-committer timestamp instead of git-author timestamp as changeset time; default: true use_committer_time = false 设置test.git目录权限让apache的www-data用户可以访问 cd /home/git/repositories sudo chmod a+r test.git

刷新trac看下效果吧。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wywyjf.html