mysqlproxy

package module
v0.0.0-...-706752c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2016 License: BSD-3-Clause Imports: 17 Imported by: 0

README

mysqlproxy

MySQL Proxy server.

前準備

ワークディレクトリの作成
sudo mkdir -p /path/to/workdir
公開鍵の設置

ワークディレクトリに設置する

設定ファイルの設置(必要な場合)

※ ルート(クライアントから接続するためのデーモン)で必要な場合のみ設置

vim /path/to/mysqlproxy.toml
["<接続先MySQLユーザー名1>"]
username = "<接続先MySQLユーザー名1>"
password = "<接続先MySQLパスワード1>"
proxyserver = "<接続先プロキシサーバのホスト1>"
["<接続先MySQLユーザー名2>"]
username = "<接続先MySQLユーザー名2>"
password = "<接続先MySQLパスワード2>"
proxyserver = "<接続先プロキシサーバのホスト2>"
…(繰り返し)

Usage

Connect to MySQL Server via MySQL proxy server

MySQL Proxy サーバーを経由してのMySQL接続方法

設定ファイルを使用しない場合
mysql -S /path/to/mysqlproxy.sock -u <MySQLサーバーのユーザー名>(:<MySQLサーバーのパスワード>)@<プロキシサーバーのホスト>:<プロキシサーバーのポート>;<MySQLサーバーのホスト>:<MySQLサーバーのポート>(;<DB名>) -p
Enter password: <MySQLサーバーのパスワード>

※ ポートは3306番であっても必須。
※ パスワード、DB名は省略可能。パスワードがない場合、-pオプションは省略可能。
※ mysqlコマンドからだとユーザー名に文字数制限があるため、rdsのように長いドメインの場合は、
PHP等の各種プログラミング言語のMySQL接続アダプタを介せば接続可能です。
設定ファイルを使用する場合
mysql -S /path/to/mysqlproxy.sock -u <MySQLサーバーのユーザー名>@<MySQLサーバーのホスト>(:<MySQLサーバーのポート>) -p
Enter password: <MySQLサーバーのパスワード>

※ プロキシサーバのアドレスは設定ファイルに書いているため省略可能ですが、ユーザー名とパスワードはプロキシサーバ自体の認証に必要です。
※ ポートが3306番であれば省略可能。
※ パスワードがない場合、-pオプションは省略可能。
※ mysqlコマンドからだとユーザー名に文字数制限があるため、rdsのように長いドメインの場合は、
PHP等の各種プログラミング言語のMySQL接続アダプタを介せば接続可能です。
Starting MySQL proxy server (root)

クライアントから接続するためのデーモン

./mysqlproxy -root -workdir ワークディレクトリのパス -config 設定ファイルのパス
Starting MySQL proxy server

MySQLサーバーに中継するためのデーモン

./mysqlproxy -workdir ワークディレクトリのパス
PHP Sample
$link = mysql_connect(
	'/path/to/mysqlproxy.sock',
	'<db user>:<db password>@<proxy host>:<proxy port>;<db host>:<db port>',
	'<db password>',
);

// For example in following Data flow.

// Connect to A
$link = mysql_connect(
	':/path/to/mysqlproxy.sock',
	'user_a:******@192.168.1.1:9696;192.168.1.2:3306',
	'******',
);

// Connect to B
$link = mysql_connect(
	':/path/to/mysqlproxy.sock',
	'user_b:******@192.168.1.1:9696;192.168.1.3:3306',
	'******',
);

// Connect to C
$link = mysql_connect(
	':/path/to/mysqlproxy.sock',
	'user_c:******@192.168.2.1:9696;192.168.2.2:3306',
	'******',
);

// Connect to D
$link = mysql_connect(
	':/path/to/mysqlproxy.sock',
	'user_d:******@192.168.2.1:9696;192.168.2.3:3306',
	'******',
);
Data flow
           Unix domain socket   TLS                       TCP
           Connect              Connect                   Connect
+--------+      +-------------+      +------------------+      +------------------+
| mysql  | ---> | mysql proxy | -+-> | mysql proxy      | -+-> | mysql server     |
| client |      | (root)      |  |   |                  |  |   | (A)              |
| (PHP)  |      | localhost   |  |   | 192.168.1.1:9696 |  |   | 192.168.1.2:3306 |
+--------+      +-------------+  |   +------------------+  |   +------------------+
                                 |                         |                      
                                 |                         |   +------------------+
                                 |                         +-> | mysql server     |
                                 |                             | (B)              |
                                 |                             | 192.168.1.3:3306 |
                                 |                             +------------------+
                                 |                                                
                                 |   +------------------+      +------------------+
                                 +-> | mysql proxy      | -+-> | mysql server     |
                                     |                  |  |   | (C)              |
                                     | 192.168.2.1:9696 |  |   | 192.168.2.2:3306 |
                                     +------------------+  |   +------------------+
                                                           |                      
                                                           |   +------------------+
                                                           +-> | mysql server     |
                                                               | (D)              |
                                                               | 192.168.2.3:3306 |
                                                               +------------------+

Documentation

Index

Constants

View Source
const (
	DefaultMySQLPort      = "3306"
	DefaultMySQLProxyPort = "9696"
)

Variables

Functions

This section is empty.

Types

type ClientConn

type ClientConn struct {
	// contains filtered or unexported fields
}

client <-> proxy

func (*ClientConn) Close

func (c *ClientConn) Close() error

func (*ClientConn) Handshake

func (c *ClientConn) Handshake() error

func (*ClientConn) IsAllowConnect

func (c *ClientConn) IsAllowConnect() bool

func (*ClientConn) Run

func (c *ClientConn) Run()

type Config

type Config struct {
	Net            string `yaml:"net"`
	Addr           string `yaml:"addr"`
	AllowIps       string `yaml:"allow_ips"`
	CaCertFile     string
	CaKeyFile      string
	ClientCertFile string
	ClientKeyFile  string
	TlsServer      bool
	TlsClient      bool
	TlsServerConf  *tls.Config
	TlsClientConf  *tls.Config
	ConfigPath     string
}

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

proxy <-> mysql server

func (*Conn) Connect

func (c *Conn) Connect(addr string, user string, password string, db string) error

func (*Conn) IsAutoCommit

func (c *Conn) IsAutoCommit() bool

func (*Conn) ReConnect

func (c *Conn) ReConnect() error

type NodeConfig

type NodeConfig struct {
	User     string `yaml:"user"`
	Password string `yaml:"password"`
	Db       string `yaml:"db"`
	Addr     string `yaml:"addr"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(cfg *Config) (*Server, error)

func (*Server) Close

func (s *Server) Close()

func (*Server) Run

func (s *Server) Run() error

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL