Ubuntu下安装Altas 2.2.1

1. 安装编译及依赖环境 for mar.

1. 安装编译及依赖环境


for mariadb

1
sudo apt-get install build-essential libssl-dev liblua5.1-0-dev libmariadbd-dev flex bison gettext libjemalloc-dev libglib2.0-dev

for mysql

1
sudo apt-get install build-essential libssl-dev liblua5.1-dev libmysqld-dev flex bison gettext libjemalloc-dev libglib2.0-dev mysql-proxy

2. 补完其余依赖


1
2
3
4
5
wget https://launchpad.net/ubuntu/+archive/primary/+files/libevent_2.0.21-stable.orig.tar.gz
tar -zxvf libevent_2.0.21-stable.orig.tar.gz
cd libevent_2.0.21-stable
./configure && make
sudo make install

3. 针对configure LUA_LIBS 参数调整,建立软链接 (重要


1
2
3
4
5
6
7
8
9
10
sudo -i
ln -s /usr/lib/x86_64-linux-gnu/liblua5.1.so.0.0.0 /usr/local/lib/liblua.so.0.0.0
ln -s /usr/lib/x86_64-linux-gnu/liblua5.1-c++.a /usr/local/lib/liblua-c++.a
ln -s /usr/lib/x86_64-linux-gnu/liblua5.1-c++.so.0 /usr/local/lib/liblua-c++.so.0
ln -s /usr/lib/x86_64-linux-gnu/liblua5.1.so.0 /usr/local/lib/liblua.so.0
ln -s /usr/lib/x86_64-linux-gnu/liblua5.1-c++.so /usr/local/lib/liblua-c++.so
ln -s /usr/lib/x86_64-linux-gnu/liblua5.1-c++.so.0.0.0 /usr/local/lib/liblua-c++.so.0.0.0
ln -s /usr/lib/x86_64-linux-gnu/liblua5.1.so /usr/local/lib/liblua.so
ln -s /usr/lib/x86_64-linux-gnu/liblua5.1.a /usr/local/lib/liblua.a
exit

4. 下载Atlas稳定版安装包


1
2
3
wget -O Atlas-2.2.1.zip https://codeload.github.com/Qihoo360/Atlas/zip/2.2.1
unzip Atlas-2.2.1.zip
cd Atlas-2.2.1

5. 修改 bootstrap.sh LUA_CFLAGS 将 /usr/local/include/ 修改为 /usr/include/lua5.1/ (重要


1
2
3
4
5
6
7
8
sudo cat > bootstrap.sh <<-"EOF"
#!/bin/sh 
base=$(cd "$(dirname "$0")"; pwd)
cd $base
# PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure --with-mysql=/usr --prefix=/usr/local/mysql-proxy CFLAGS="-DHAVE_LUA_H -O2" LDFLAGS="-lm -ldl -lcrypto -ljemalloc" LUA_CFLAGS="-I/usr/local/include/" LUA_LIBS="-L/usr/local/lib -llua"
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure --with-mysql=/usr --prefix=/usr/local/mysql-proxy CFLAGS="-DHAVE_LUA_H -O2" LDFLAGS="-lm -ldl -lcrypto -ljemalloc" LUA_CFLAGS="-I/usr/include/lua5.1/" LUA_LIBS="-L/usr/local/lib -llua"
 
EOF

6. 编译安装 执行该步聚前,确认 第3、5步正确, 即 LUA_LIBS 与 LUA_CFLAGS 必须设置正确


1
2
3
./bootstrap.sh
make
sudo make install

7.配置示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
[mysql-proxy]
 
# (Necessary, the default value is ok) The name access to admin port
 
admin-username=user
 
# (Necessary, the default value is ok) The password access to admin port
 
admin-password=pwd
 
# (Necessary,set value according to the actual situation) The master database server,ip:port.
 
proxy-backend-addresses=192.168.88.11:3306
 
# (Not necessary,set value according to the actual situation) The slave database server, ip:port.
 
# The number behind '@'represents the weight used by load balance for reading,
 
# the default weight is 1. If you want the master backend also can process the read requests,
 
# add its ip:port to this configuration option.
 
proxy-read-only-backend-addresses=192.168.88.12:3306@5,192.168.88.13:3306@3,192.168.88.11:3306
 
# (Necessary,set value according to the actual situation) Username and its password login master and slave.
 
# We can use the username and password login the master database and the slave database server.
 
# The password encrypt by /usr/loca/mysql-proxy/bin/encrypt.
 
# For example, the username is: myuser, and the password is:mypwd (encrypted ciphertext is:HJBoxfRsjeI=).
 
pwds=repl:jNsKRuypPY0=
 
# (Necessary, the default value is ok) if the value is true,Atlas run as a daemon.
 
daemon=false
 
# (Necessary, the default value is ok) Atlas will start two processes when the value set true,
 
# one is monitor process, another is the work process. The monitor process will restart the work process
 
# automatically when the work process crash unexpectedly.
 
# If the value set false, Atlas will only start the work process.
 
keepalive=true
 
# (Necessary, set value according to the actual situation) The count of work threads in work process.
 
# set the value equal to twice of cpu cores
 
event-threads=4
 
# (Necessary, the default value is ok) Log level: message, warning, critical, error, debug
 
log-level=debug
 
# (Necessary, the default value is ok) Log file path
 
log-path=/usr/local/mysql-proxy/log
 
# (Necessary, the default value is ok) The switch for printing log.
 
#     ON          : log the sql to the log file with buffer.
 
#     OFF         : not log the sql.
 
#     REALTIME    : log the sql to the log file without buffer.
 
sql-log=REALTIME
 
# (Necessary, set value according to the actual situation) Slow log output settings.
 
# When this parameter is set, Only log the sql which execution time more than sql-log-slow (ms) logging.
 
# Do not set this parameter, will log all the sql.
 
sql-log-slow=10
 
# (Necessary, set value according to the actual situation) close the inactive client connections
 
# after ‘wait_timeout’ seconds
 
wait-timeout=10
 
# (Necessary, the default value is ok) The work port of Atlas
 
proxy-address=0.0.0.0:3307
 
# (Necessary, the default value is ok) The admin port of Atlas
 
admin-address=0.0.0.0:3308
 
# (Not necessary, set value according to the actual situation) Shard table setting.
 
# In this case, person is the database name, mt is the table name, id is the shard key,
 
# the shard table count is 3,and you should create table mt_0, mt_1, mt_2 in mysql manually.
 
# If you have more shard table,you can set them and separated by commas.
 
#tables = person.mt.id.3
 
# (Not necessary,set value according to the actual situation)character set,
 
# If you not set this parameter, the character is latin1.
 
charset=utf8
 
# (Not necessary,do not set this parameter) The client's IP be allowed to connect Atlas.
 
# If you not set this parameter, all client can connect Atlas.
 
client-ips=127.0.0.1,192.168.88
 
# (Not necessary,do not set this parameter) If you set client-ips, and through LVS connecting Atlas,
 
# then you need set lvs-ips, and this parameter is the true IP of LVS.
 
#lvs-ips = 192.168.1.1