使用mysql5.7.16头文件库文件编译安装atlas

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用mysql5.7.16头文件库文件编译安装atlas相关的知识,希望对你有一定的参考价值。

最近mysql数据库升级到5.7.16,而中间件atlas之前是基于mysql5.6编译的,打算重新编译下atlas并使用mysql5.7.16的库文件头文件。这里主要介绍下编译过程遇到问题及解决方法。

由于需要glib版本要大于2.32以上,centos6.6系统自带的glib版本为2.28,因此需要重新编译安装2.32以上的glib,这里安装2.34版本的glib需要依赖pcre大于8.31

一、编译安装pcre8.35

# ./configure --prefix=/usr/local/glib --with-pcre=/usr/local/pcre/

# make 

# make install

二、编译安装glib-2.34.3.tar.xz

# ./configure --prefix=/usr/local/glib --with-pcre=/usr/local/pcre/

# make 

# make install

三、编译安装Atlas-2.2.1.tar.gz

1.解决依赖关系

# yum install libffi-devel lua-devel libevent libevent-devel jemalloc jemalloc-devel

2.修改源码中mysql版本代码,这里mysql版本为5.7.16

找到plugins/proxy/proxy-plugin.c文件

修改1974行:challenge->server_version_str = g_strdup("5.0.81-log");

为:challenge->server_version_str = g_strdup("5.7.16-log");

修改1974行:challenge->server_version = 50081;

为:challenge->server_version = 50716;

3.安装atlas

修改bootstrap.sh

#!/bin/sh 
base=$(cd "$(dirname "$0")"; pwd)
cd $base
PKG_CONFIG_PATH=/usr/local/glib/lib/pkgconfig ./configure --with-mysql=/usr/local/mysql5.7.16/bin/mysql_config --prefix=/usr/local/mysql-proxy CFLAGS="-DHAVE_LUA_H -O2" CPPFLAGS="-I/usr/local/mysql5.7.16/include/" LDFLAGS="-lm -ldl -lcrypto -ljemalloc" LUA_CFLAGS="-I/usr/include/" LUA_LIBS="-L/usr/lib64 -llua"

执行

# ./bootstrap.sh

# make && make install

4.执行make时会报错:

错误1:

libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -I/usr/local/mysql5.7/include -I/usr/local/glib/include/glib-2.0 -I/usr/local/glib/lib/glib-2.0/include -pthread -I/usr/local/glib/include/glib-2.0 -I/usr/local/glib/lib/glib-2.0/include -g -O2 -MT libmysql_proxy_la-network-mysqld-packet.lo -MD -MP -MF .deps/libmysql_proxy_la-network-mysqld-packet.Tpo -c network-mysqld-packet.c  -fPIC -DPIC -o .libs/libmysql_proxy_la-network-mysqld-packet.o

network-mysqld-packet.c: In function ‘network_mysqld_auth_challenge_new’:

network-mysqld-packet.c:1147: error: ‘CLIENT_SECURE_CONNECTION’ undeclared (first use in this function)

network-mysqld-packet.c:1147: error: (Each undeclared identifier is reported only once

network-mysqld-packet.c:1147: error: for each function it appears in.)

network-mysqld-packet.c: In function ‘network_mysqld_proto_get_auth_challenge’:

network-mysqld-packet.c:1221: error: ‘CLIENT_SECURE_CONNECTION’ undeclared (first use in this function)

network-mysqld-packet.c: In function ‘network_mysqld_auth_response_new’:

network-mysqld-packet.c:1323: error: ‘CLIENT_SECURE_CONNECTION’ undeclared (first use in this function)

network-mysqld-packet.c: In function ‘network_mysqld_proto_get_auth_response’:

network-mysqld-packet.c:1378: error: ‘CLIENT_SECURE_CONNECTION’ undeclared (first use in this function)

make[3]: *** [libmysql_proxy_la-network-mysqld-packet.lo] Error 1

make[3]: Leaving directory `/usr/local/src/Atlas-2.2.1/src‘

make[2]: *** [all] Error 2

make[2]: Leaving directory `/usr/local/src/Atlas-2.2.1/src‘

make[1]: *** [all-recursive] Error 1

make[1]: Leaving directory `/usr/local/src/Atlas-2.2.1‘

make: *** [all] Error 2

错误2:

libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../.. -I/usr/local/mysql5.7.16/include -I/usr/local/glib/include/glib-2.0 -I/usr/local/glib/lib/glib-2.0/include -I/usr/include/ -pthread -I/usr/local/glib/include/glib-2.0 -I/usr/local/glib/lib/glib-2.0/include -I../../src/ -I/usr/local/mysql5.7.16/include/ -DHAVE_LUA_H -O2 -MT libadmin_la-admin-plugin.lo -MD -MP -MF .deps/libadmin_la-admin-plugin.Tpo -c admin-plugin.c  -fPIC -DPIC -o .libs/libadmin_la-admin-plugin.o

admin-plugin.c: In function ‘server_con_init’:

admin-plugin.c:203: error: ‘CLIENT_SECURE_CONNECTION’ undeclared (first use in this function)

admin-plugin.c:203: error: (Each undeclared identifier is reported only once

admin-plugin.c:203: error: for each function it appears in.)

make[3]: *** [libadmin_la-admin-plugin.lo] Error 1

make[3]: Leaving directory `/usr/local/src/Atlas-2.2.1/plugins/admin‘

make[2]: *** [all-recursive] Error 1

make[2]: Leaving directory `/usr/local/src/Atlas-2.2.1/plugins‘

make[1]: *** [all-recursive] Error 1

make[1]: Leaving directory `/usr/local/src/Atlas-2.2.1‘

make: *** [all] Error 2

报错原因:mysql5.7之后头文件中的CLIENT_SECURE_CONNECTION变量名修改为CLIENT_RESERVED2

cat /usr/local/src/mysql-5.6.17/include/mysql_com.h

技术分享cat /usr/local/src/mysql-5.7.16/include/mysql_com.h

技术分享

5.解决方法:

修改atlas源码

visrc/network-mysqld-packet.c
1139network_mysqld_auth_challenge *network_mysqld_auth_challenge_new() {
1140         network_mysqld_auth_challenge *shake;
1141
1142         shake =g_new0(network_mysqld_auth_challenge, 1);
1143
1144         shake->challenge =g_string_sized_new(20);
1145         shake->capabilities =
1146                 CLIENT_PROTOCOL_41 |
1147                 CLIENT_SECURE_CONNECTION |
1148                 0;
1149
1150
1151         return shake;
1152 }
修改1147行为如下:
1139network_mysqld_auth_challenge *network_mysqld_auth_challenge_new() {
1140         network_mysqld_auth_challenge *shake;
1141
1142         shake =g_new0(network_mysqld_auth_challenge, 1);
1143
1144         shake->challenge =g_string_sized_new(20);
1145         shake->capabilities =
1146                 CLIENT_PROTOCOL_41 |
1147                 CLIENT_RESERVED2 |
1148                 0;
1149
1150
1151         return shake;
1152 }
 
1220
1221         if (shake->capabilities &CLIENT_SECURE_CONNECTION) {
1222                 err = err ||network_mysqld_proto_get_string_len(packet, &scramble_2, 12);
1223                 err = err ||network_mysqld_proto_skip(packet, 1);
1224         }
1225
1226         if (!err) {
1227                 /* process the data */
1228
1229                 if (3 !=sscanf(shake->server_version_str, "%d.%d.%d%*s", &maj,&min, &patch)) {
1230                         /* can‘t parse theprotocol */
1231
1232                         g_critical("%s:protocol 10, but version number not parsable", G_STRLOC);
1233
1234                         return -1;
1235                 }
1236
修改1221行为如下:
1220
1221         if (shake->capabilities & CLIENT_RESERVED2) {
1222                 err = err ||network_mysqld_proto_get_string_len(packet, &scramble_2, 12);
1223                 err = err ||network_mysqld_proto_skip(packet, 1);
1224         }
1225
1226         if (!err) {
1227                 /* process the data */
1228
1229                 if (3 !=sscanf(shake->server_version_str, "%d.%d.%d%*s", &maj,&min, &patch)) {
1230                         /* can‘t parse theprotocol */
1231
1232                         g_critical("%s:protocol 10, but version number not parsable", G_STRLOC);
1233
1234                         return -1;
1235                 }
1236
 
1312network_mysqld_auth_response *network_mysqld_auth_response_new() {
1313         network_mysqld_auth_response *auth;
1314
1315         auth =g_new0(network_mysqld_auth_response, 1);
1316
1317         /* we have to make surescramble->buf is not-NULL to get
1318          * the "empty string" andnot a "NULL-string"
1319          */
1320         auth->response =g_string_new("");
1321         auth->username =g_string_new("");
1322         auth->database =g_string_new("");
1323         auth->capabilities =CLIENT_SECURE_CONNECTION | CLIENT_PROTOCOL_41;
1324
1325         return auth;
1326 }
修改1323行为如下:
1312network_mysqld_auth_response *network_mysqld_auth_response_new() {
1313         network_mysqld_auth_response *auth;
1314
1315         auth =g_new0(network_mysqld_auth_response, 1);
1316
1317         /* we have to make surescramble->buf is not-NULL to get
1318          * the "empty string" andnot a "NULL-string"
1319          */
1320         auth->response =g_string_new("");
1321         auth->username =g_string_new("");
1322         auth->database =g_string_new("");
1323         auth->capabilities = CLIENT_RESERVED2 | CLIENT_PROTOCOL_41;
1324
1325         return auth;
1326 }
 
1378                 if (auth->capabilities& CLIENT_SECURE_CONNECTION) {
1379                         err = err ||network_mysqld_proto_get_lenenc_gstring(packet, auth->response);
1380                 } else {
1381                         err = err ||network_mysqld_proto_get_gstring(packet, auth->response);
1382                 }
1383
1384                 if (packet->offset !=packet->data->len) {
1385                         /* database isoptional and may include a trailing \0 char */
1386                         err = err ||network_mysqld_proto_get_gstring_len
修改1378行为如下:
1378                 if (auth->capabilities& CLIENT_RESERVED2) {
1379                         err = err ||network_mysqld_proto_get_lenenc_gstring(packet, auth->response);
1380                 } else {
1381                         err = err ||network_mysqld_proto_get_gstring(packet, auth->response);
1382                 }
1383
1384                 if (packet->offset !=packet->data->len) {
1385                         /* database isoptional and may include a trailing \0 char */
1386                         err = err ||network_mysqld_proto_get_gstring_len
 
viplugins/admin/admin-plugin.c
195NETWORK_MYSQLD_PLUGIN_PROTO(server_con_init) {
196         network_mysqld_auth_challenge*challenge;
197         GString *packet;
198
199         challenge =network_mysqld_auth_challenge_new();
200         challenge->server_version_str =g_strdup("5.0.99-agent-admin");
201         challenge->server_version     = 50099;
202         challenge->charset            = 0x08; /* latin1 */
203         challenge->capabilities       = CLIENT_PROTOCOL_41 |CLIENT_SECURE_CONNECTION | CLIENT_LONG_PASSWORD;
204         challenge->server_status      = SERVER_STATUS_AUTOCOMMIT;
205         challenge->thread_id          = 1;
修改203行为如下:
195NETWORK_MYSQLD_PLUGIN_PROTO(server_con_init) {
196         network_mysqld_auth_challenge*challenge;
197         GString *packet;
198
199         challenge =network_mysqld_auth_challenge_new();
200         challenge->server_version_str =g_strdup("5.0.99-agent-admin");
201         challenge->server_version     = 50099;
202         challenge->charset            = 0x08; /* latin1 */
203         challenge->capabilities       = CLIENT_PROTOCOL_41 | CLIENT_RESERVED2 | CLIENT_LONG_PASSWORD;
204         challenge->server_status      = SERVER_STATUS_AUTOCOMMIT;
205         challenge->thread_id          = 1;

6.重新编译安装

7.导入mysql5.7库文件

# echo ‘/usr/local/mysql5.7.16/lib‘ >> /etc/ld.so.conf

# ldconfig

8.启动atlas

# /usr/local/mysql-proxy/bin/mysql-proxyd test start


本文出自 “linux之路” 博客,请务必保留此出处http://hnr520.blog.51cto.com/4484939/1887750

以上是关于使用mysql5.7.16头文件库文件编译安装atlas的主要内容,如果未能解决你的问题,请参考以下文章

centos7.x编译安装mysql5.7.16

MYSQL5.7.16 编译安装

CentOS6.8编译安装Nginx1.10.2+MySQL5.7.16+PHP7.0.12

MySQL5.7.16安装及配置

CentOS 7.x编译安装Nginx1.10.3+MySQL5.7.16+PHP5.2 5.3 5.4 5.5 5.6 7.0 7.1多版本全能环境

161204win10安装mysql5.7.16数据库