使用 Unicorn 和 Apache 代理的工作 Gitlab 配置
问题:
你想使用 Apache 和 unicorn(不是 passenger!)设置 gitlab,但无论你怎么尝试都不起作用。
解决方案
你不是唯一有此问题的人。即使互联网上有许多不错的教程,没有一个对我有用。
我的最终设置包括 gitolite 的通用用户(gitolite3 似乎是必要的,在用户 gitolite 下安装到 /var/lib/gitolite)和 stable gitlabhq 的克隆到 /opt/gitlabhq。我假设你已经遵循了非官方和官方指南,数据库以及 gitolite 已正确设置。
设置 gitlabhq 有许多不同的方法,包括涉及 mod_passenger 的方法。我想它们比其他方法更节省内存,但我无法让它工作。
这是我的 /etc/init.d/gitlab:
gitlab_init.sh
#! /bin/bash
### BEGIN INIT INFO
# Provides: gitlab
# Required-Start: $local_fs $remote_fs $network $syslog redis-server
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: GitLab git repository management
# Description: GitLab git repository management
### END INIT INFO
DAEMON_OPTS="-c /opt/gitlabhq/config/unicorn.rb -E production -D"
NAME=unicorn
DESC="Gitlab service"
PID=/opt/gitlabhq/tmp/pids/unicorn.pid
RESQUE_PID=/opt/gitlabhq/tmp/pids/resque_worker.pid
case "$1" in
start)
CD_TO_APP_DIR="cd /opt/gitlabhq"
START_DAEMON_PROCESS="bundle exec unicorn_rails $DAEMON_OPTS"
START_RESQUE_PROCESS="./resque.sh"
echo -n "Starting $DESC: "
if [ `whoami` = root ]; then
sudo -u gitolite sh -l -c "$CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS"
else
$CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS
fi
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
kill -QUIT `cat $PID`
kill -QUIT `cat $RESQUE_PID`
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
kill -USR2 `cat $PID`
kill -USR2 `cat $RESQUE_PID`
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
kill -HUP `cat $PID`
kill -HUP `cat $RESQUE_PID`
echo "$NAME."
;;
*)
echo "Usage: $NAME {start|stop|restart|reload}" >&2
exit 1
;;
esac
exit 0这是我的 .gitolite.rc
gitolite_rc.pl
# gitolite 的配置变量
# 此文件使用 perl 语法。但你不需要了解 perl 来编辑它 --
# 只要注意逗号,除非你知道自己在做什么否则使用单引号,
# 并确保括号和大括号匹配!
#(提示:perl 也允许在列表的最后一项后加逗号!)
# 命令的帮助(参见下面的 COMMANDS 列表)可以通过运行
# 带有 "-h" 作为唯一参数的命令获得。
# 所有其他外部程序的帮助(语法糖助手和
# 8 个触发列表中的各种程序/函数),可以在
# doc/non-core.mkd (http://sitaramc.github.com/gitolite/non-core.html) 或
# 相应的源文件本身中找到。
%RC = (
# 如果你使用镜像,你需要一个主机名。这是一个*简单*的
# 词,不是完整的域名。如有疑问请参见文档
# HOSTNAME => 'darkstar',
UMASK => 0007,
# 查看 README 中的 "GIT-CONFIG" 部分了解该做什么
GIT_CONFIG_KEYS => '.*',
# 如果你不需要日志文件中的所有额外细节,请注释掉
LOG_EXTRA => 1,
# 外部程序使用的设置;根据需要取消注释和更改。你
# 可以添加自己的变量用于自己的外部程序;
# 查看 info 和 desc 命令获取 perl 和 shell 示例。
# 由 CpuTime 触发器使用
# DISPLAY_CPU_TIME => 1,
# CPU_TIME_WARN_LIMIT => 0.1,
# 由 desc 命令使用
# WRITER_CAN_UPDATE_DESC => 1,
# 由 info 命令使用
# SITE_INFO => 'Please see http://blahblah/gitolite for more help',
# 在此处添加更多角色(如 MANAGER、TESTER 等)。
# 警告:如果你更改此哈希,之后必须运行 'gitolite
# compile',可能还需要 'gitolite trigger POST_COMPILE'
ROLES =>
{
READERS => 1,
WRITERS => 1,
},
# 如果你希望,取消注释(并更改)
# DEFAULT_ROLE_PERMS => 'READERS @all',
# 根据需要注释掉或取消注释
# 这些对远程用户可用
COMMANDS =>
{
'help' => 1,
'desc' => 1,
# 'fork' => 1,
'info' => 1,
# 'mirror' => 1,
'perms' => 1,
# 'sskm' => 1,
'writable' => 1,
# 'D' => 1,
},
# 根据需要注释掉或取消注释
# 这些将在配置文件解析期间按顺序运行
SYNTACTIC_SUGAR =>
[
# 'continuation-lines',
# 'keysubdirs-as-groups',
],
# 根据需要注释掉或取消注释
# 这些将按顺序运行以修改输入(参数和环境)
INPUT =>
[
# 'CpuTime::input',
# 'Shell::input',
# 'Alias::input',
# 'Mirroring::input',
],
# 根据需要注释掉或取消注释
# 这些将在第一次访问检查完成后按顺序运行
ACCESS_1 =>
[
],
# 根据需要注释掉或取消注释
# 这些将在实际 git 命令调用之前按顺序运行
PRE_GIT =>
[
# 'renice 10',
# 'Mirroring::pre_git',
# 'partial-copy',
],
# 根据需要注释掉或取消注释
# 这些将在第二次访问检查完成后按顺序运行
ACCESS_2 =>
[
],
# 根据需要注释掉或取消注释
# 这些将在 git 命令返回后按顺序运行
POST_GIT =>
[
# 'Mirroring::post_git',
# 'CpuTime::post_git',
],
# 根据需要注释掉或取消注释
# 这些将在创建新的 wild 仓库之前按顺序运行
PRE_CREATE =>
[
],
# 根据需要注释掉或取消注释
# 这些将在创建新仓库后按顺序运行
POST_CREATE =>
[
'post-compile/update-git-configs',
'post-compile/update-gitweb-access-list',
'post-compile/update-git-daemon-access-list',
],
# 根据需要注释掉或取消注释
# 这些将在 post-update 后按顺序运行
POST_COMPILE =>
[
'post-compile/ssh-authkeys',
'post-compile/update-git-configs',
'post-compile/update-gitweb-access-list',
'post-compile/update-git-daemon-access-list',
],
);
# ------------------------------------------------------------------------------
# 根据 perl 规则,这应该是此类文件的最后一行:
1;
# Local variables:
# mode: perl
# End:
# vim: set syn=perl:这是我的 gitlab.yml
gitlab.yml
# # # # # # # # # # # # # # # # # #
# Gitlab 应用配置文件 #
# # # # # # # # # # # # # # # # # #
#
# 1. 通用设置
# ==========================
# Web 应用特定设置
web:
host: localhost
port: 80
https: false
# 用于通知的电子邮件
# 关于新问题、评论
email:
from: gitlab@btronik.de
to: btronik.de
protocol: https
# 应用特定设置
# 如用户的默认项目限制等
app:
default_projects_limit: 10
# backup_path: "/vol/backups" # 默认:Rails.root + backups/
# backup_keep_time: 604800 # 默认:0(永久)(以秒为单位)
# disable_gravatar: true # 默认:false - 禁用来自 Gravatar.com 的用户头像
#
# 2. 认证设置
# ==========================
ldap:
enabled: false
host: '_your_ldap_server'
base: '_the_base_where_you_search_for_users'
port: 636
uid: 'sAMAccountName'
method: 'ssl' # plain
bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
password: '_the_password_of_the_bind_user'
omniauth:
# 启用用户
# 通过 twitter、google 等登录的能力
enabled: false
# 重要!
# 它允许用户在没有用户账户的情况下登录
allow_single_sign_on: false
block_auto_created_users: true
# 认证提供者
providers:
# - { name: 'google_oauth2', app_id: 'YOUR APP ID',
# app_secret: 'YOUR APP SECRET',
# args: { access_type: 'offline', approval_prompt: '' } }
# - { name: 'twitter', app_id: 'YOUR APP ID',
# app_secret: 'YOUR APP SECRET'}
# - { name: 'github', app_id: 'YOUR APP ID',
# app_secret: 'YOUR APP SECRET' }
#
# 3. 高级设置:
# ==========================
# Git 托管配置
git_host:
admin_uri: gitolite@btronik.de:gitolite-admin
base_path: /var/lib/gitolite/repositories/
hooks_path: /var/lib/gitolite/.gitolite/hooks/
gitolite_admin_key: gitlab
git_user: gitolite
upload_pack: true
receive_pack: true
host: btronik.de
# config_file: gitolite.conf
# port: 22
# Git 设置
# 除非你理解它,否则使用默认值
git:
path: /usr/bin/git
# git 对象(如提交)的最大大小,以字节为单位
# 如果你有非常大的提交,可以增加此值
git_max_size: 5242880 # 5.megabytes
# Git 读取提交的超时时间,以秒为单位
git_timeout: 10最后,我的 Apache2 虚拟主机配置。注意我在端口 3001 上配置 gitlab 以保持端口 8080 对其他应用空闲:
gitlab_apache_vhost.conf
<VirtualHost *:80>
ServerName gitlab.mydomain.de
#不要重定向到 HTTPS
ErrorLog /var/log/apache2/owncloud_error.log
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
<VirtualHost *:443>
ServerName gitlab.mydomain.de
DocumentRoot /opt/gitlabhq/public
ErrorLog /var/log/apache2/gitlab-error.log
CustomLog /var/log/apache2/gitlab-access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl.crt/btronik-wildcardcert.pem
SSLCertificateKeyFile /etc/apache2/ssl.crt/btronik-wildcardkey.pem
SSLCACertificateFile /etc/apache2/ssl.crt/ca.pem
# the following allows "nice" urls such as https://etherpad.example.org/padname
ProxyVia On
ProxyRequests Off
ProxyPass / http://127.0.0.1:3001/
ProxyPassReverse / http://127.0.0.1:3001/
ProxyPreserveHost on
<Proxy *>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Proxy>
</VirtualHost>Check out similar posts by category:
Allgemein
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow