SSH ポート フォワーディングのセットアップ
There are two scenarios where you might want to set up port forwarding in Bitbucket Data Center and Server: to remove port numbers from your SSH URLs or if Bitbucket is running behind a reverse proxy on a separate machine
On this page:
SSH URL からのポート番号の削除
Bitbucket listens for SSH connections on port 7999 by default.
Your users will need to include the port in the URL they use to clone from Bitbucket, for example:
git clone ssh://git@bitbucket.mycompany.com:7999/PROJECT/repo.git
Rather than have the port number in the URL, you may wish to set up port forwarding so that connections to the default SSH port are forwarded to the port Bitbucket is listening on (e.g. you could forward port 22 to port 7999).
これにより、ユーザーは次のように、ポート番号が含まれていない URL を使用できます。
git clone ssh://git@bitbucket.mycompany.com/PROJECT/repo.git
Bitbucket is running behind a reverse proxy on a separate machine
You may be following our instructions for setting up Bitbucket behind an Apache front-end.
In this case, your users may not be able to access Bitbucket directly for SSH connections, or if they can, you may wish to make the SSH and HTTPS URLs consistent.
For example, if you have the above topology, without port forwarding (and assuming the default port of 7999), your users will need to clone Bitbucket directly from the backend, like this:
git clone ssh://git@bitbucket.backend.atlassian.com:7999/PROJECT/repo.git
In your network, the bitbucket.backend.atlassian.com
machine may not be accessible directly, or you may want the URL to be consistent with the HTTPS URL of https://bitbucket.atlassian.com/scm/PROJECT/repo.git
.
In this case, you need to set up port forwarding on the bitbucket.atlassian.com
machine to accept connections and forward them to port 7999 on the bitbucket.backend.atlassian.com
machine.
ポート フォワーディングのセットアップ方法
HAProxy
Atlassian recommends the use of HAProxy for forwarding SSH connections through to Bitbucket.
HAProxy は、Linux、Solaris および FreeBSD で サポートされています。
HAProxy はアトラシアン製品ではないため、アトラシアンでは HAProxy の構成についてのサポートは提供されません。このセクションは情報提供のみを目的としており、お客様の責任でご利用ください。HAProxy ドキュメントを参照することをおすすめします。
HAProxy のインストール
Your operating system may support installing HAProxy using its system package manager, such as apt-get
, yum
or rpm
. This will be the easiest way.
または、自身で HAProxy を構築してそれをインストールすることもできます。
- Download the latest version of HAProxy.
アーカイブを展開して cd で次のディレクトリに移動します。
tar xzvf haproxy-1.4.21.tar.gz cd haproxy-1.4.21
ご利用のシステムでの構築方法については、README の説明をお読みください。これは一般に非常に簡単です。Linux 64 ビット 2.6 カーネルの場合のコマンドは以下のとおりです。
make TARGET=linux26 ARCH=x86_64
正常に完了したら、README の説明に従ってインストールします。
sudo make install
HAProxy の構成
HAProxy is extremely powerful - it is designed as a HTTPS load balancer, but also can serve as a port forwarder for ssh
. Learn more about how to enable client IP forwarding for SSH sessions by setting up Proxy protocol for Bitbucket Data Center.
バージョン 1.4 の完全なドキュメントはこちらにあります。その他のドキュメントは HAProxy の Webサイトでご利用いただけます。
以下は、単純な構成例です。
global
daemon
maxconn 10000
defaults
timeout connect 500s
timeout client 5000s
timeout server 1h
frontend sshd
bind *:7999
default_backend ssh
timeout client 1h
backend ssh
mode tcp
server localhost-bitbucket-ssh 127.0.0.1:7999
The above configuration will listen on port 7999 (indicated by the bind
directive) on all network interfaces. As indicated by the server
directive, traffic is forwarded to 127.0.0.1, port 7999. You will need to replace 127.0.0.1
with the IP address of the machine running Bitbucket.
次のコマンドを実行することで構成を確認できます。
haproxy -f haproxyconf.txt -c
haproxy を実行するには、次のコマンドで開始します。
haproxy -f haproxyconf.txt
If you use HAProxy to additionally proxy HTTP traffic, ensure that the running mode
configuration is set to http
:
backend http
mode http
bind *:80
server localhost-bitbucket-http 127.0.0.1:7990
既定の SSH ポートを使用する
既定の SSH ポートでリッスンするように HAProxy を構成することもできます。これにより、このポートをクローン URL で指定する必要がなくなります。
既定では、通常の ssh デーモンはポート 22 で稼働します。次の選択肢があります。
- 前述の例のように、代替ポートでリッスンするように HAProxy を構成する。
- Configure multiple network interfaces on the physical machine and force the default ssh daemon to listen on all but the interface for accessing Bitbucket. Configure HAProxy to only listen on that interface.
- 既定の ssh デーモンを別のポートでリッスンするように移動し、HAProxy をポート 22 にバインドする。
最後の 2 つのオプションについては、HAProxy の構成方法のみ説明します。
最後の例と同じ構成を使用しますが、バインド ポートを 22 に変更します。例:
...
frontend sshd
bind *:22
...
You will have to run this configuration as the root
user, using sudo
, because it specifies a port to listen on that is less than 1024.
sudo haproxy -f haproxyconf.txt
SSH ベース URL の構成
Once port forwarding is set up, you will need to configure the SSH base URL in Bitbucket so that the clone urls presented in Bitbucket indicate the correct host and port to clone from. See the SSH base URL section in Enable SSH access to Git repositories.