你的位置:首页 > 开源世界

CentOS下PhxSQL编译安装第二版

2016-09-12 浏览:(9328) 开源世界 评论(5)

【注】官方已经更新了依赖的第三方包的版本,最新获取的文件编译安装会遇到之前没有遇到的问题,下面是用全新最小化安装的CentOS 6.7 来编译安装的,更新系统后是CentOS 6.8了。

CentOS 6 全新最小化安装的操作系统:

yum install -y patch make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel kernel-headers libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel gmp-devel unzip automake libxslt libxslt-devel wget tar libcurl libcurl-devel libcap diffutils ca-certificates net-tools libc-client-devel psmisc libXpm-devel git git-core c-ares-devel libicu-devel libzip libzip-devel perl perl-devel python python-devel

#更新系统

yum update

#相关依赖的包

yum install -y readline readline-devel libstdc++-static glibc-static perl-Module-Install.noarch

一:获取源码:

git clone --recursive https://github.com/tencent-wechat/phxsql.git (--recursive参数可以同时获得所依赖的第三方库colib,glog,leveldb,protobuf源码,和依赖库phxpaxos,phxrpc)

1.1:升级相关依赖的库及工具。

1.1.1:autoconf

下载地址:http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz

tar xzvf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure --prefix=/usr/local/autoconf-2.69
make && make install

mv /usr/bin/autoconf /usr/bin/bak_autoconf
mv /usr/bin/autoheader /usr/bin/bak_autoheader
mv /usr/bin/autom4te /usr/bin/bak_autom4te
mv /usr/bin/autoreconf /usr/bin/bak_autoreconf
mv /usr/bin/autoscan /usr/bin/bak_autoscan
mv /usr/bin/autoupdate /usr/bin/bak_autoupdate   
ln -sf /usr/local/autoconf-2.69/bin/autoconf /usr/bin/autoconf
ln -sf /usr/local/autoconf-2.69/bin/autoheader /usr/bin/autoheader
ln -sf /usr/local/autoconf-2.69/bin/autom4te /usr/bin/autom4te
ln -sf /usr/local/autoconf-2.69/bin/autoreconf /usr/bin/autoreconf
ln -sf /usr/local/autoconf-2.69/bin/autoscan /usr/bin/autoscan
ln -sf /usr/local/autoconf-2.69/bin/autoupdate /usr/bin/autoupdate

1.1.2:automake

下载地址:http://ftp.gnu.org/gnu/automake/automake-1.14.tar.gz

tar xzvf automake-1.14.tar.gz
cd automake-1.14
./configure --prefix=/usr/local/automake-1.14
make && make install

ln -sf /usr/local/automake-1.14/bin/aclocal-1.14 /usr/bin/aclocal-1.14
ln -sf /usr/local/automake-1.14/bin/automake-1.14 /usr/bin/automake-1.14
ln -sf /usr/local/automake-1.14/bin/aclocal-1.14 /usr/bin/aclocal-1.14
mkdir /usr/share/automake-1.14
ln -sf /usr/local/automake-1.14/share/automake-1.14/test-driver  /usr/share/automake-1.14/test-driver

1.1.3:cmake

下载地址:https://cmake.org/files/v3.6/cmake-3.6.1.tar.gz

tar xzvf cmake-3.6.1.tar.gz
cd cmake-3.6.1
./configure
make && make install

1.1.4:python

下载地址:https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz

tar xzvf Python-2.7.12.tgz
cd Python-2.7.12
./configure --prefix=/usr/local/python27
make && make install

1.1.5:gcc

下载地址:http://ftp.gnu.org/gnu/gcc/gcc-6.2.0/gcc-6.2.0.tar.gz

tar xzvf gcc-6.2.0.tar.gz
cd gcc-6.2.0/
./contrib/download_prerequisites
cd ..
mkdir gcc-build-6.2.0
cd gcc-build-6.2.0/
../gcc-6.2.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
make -j4 (-j4参数根据自己的cpu核心数来设置,这样编译的速度会快点,其实加了编译的时间也很长的)
make install

ls /usr/local/bin | grep gcc
update-alternatives --install /usr/bin/gcc gcc /usr/local/bin/x86_64-pc-linux-gnu-gcc-6.2.0 40 (优先使用6.2.0版本的gcc)
执行以上操作之后使用 gcc --version 就可以看见当前使用的gcc版本是gcc (GCC) 6.2.0的新版本了。

cp ./x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.22 /usr/lib64/
删除原来低版本的软链:rm -rf /usr/lib64/libstdc++.so.6
创建新版本的软链:ln -sf /usr/lib64/libstdc++.so.6.0.22 /usr/lib64/libstdc++.so.6
二、编译相关依赖
2.1:colib
cd /home/phxsql/third_party/colib
make

2.2:glog
cd /home/phxsql/third_party/glog
./configure CXXFLAGS=-fPIC --prefix=/home/phxsql/third_party/glog
make
make install

2.3:leveldb
/home/phxsql/third_party/leveldb
make
mkdir lib
cp libleveldb.* ./lib

2.4:protobuf
cd /home/phxsql/third_party/protobuf
./autogen.sh
./configure CXXFLAGS=-fPIC --prefix=/home/phxsql/third_party/protobuf
make
make install

#执行autogen.sh的时候curl报超时的问题:
autogen.sh 文件的第34行gmock的下载地址是https://googlemock.googlecode.com/files/gmock-1.7.0.zip,这个地址在国内正常是访问不了的,所以在执行./autogen.sh的时候会报curl超时,翻出墙外之后这个地址也不能下载,404,应该不会是忘了上传了吧。

解决办法1:
修改autogen.sh文件第34行的下载地址,把https://googlemock.googlecode.com/files/gmock-1.7.0.zip 改为wget http://www.zhanghaijun.com/soft/gmock-1.7.0.zip,这个我已经把两个包都下载了,打包好了。

解决办法2:
项目地址:https://github.com/google/googlemock
项目地址:https://github.com/google/googletest
wget https://github.com/google/googlemock/archive/release-1.7.0.zip
unzip -q release-1.7.0.zip
rm release-1.7.0.zip
mv googlemock-release-1.7.0 gmock

wget https://github.com/google/googletest/archive/release-1.7.0.zip
unzip -q release-1.7.0.zip
rm release-1.7.0.zip
mv googletest-release-1.7.0 gmock/gtest

解决办法三:
wget http://www.zhanghaijun.com/soft/gmock-1.7.0.zip
unzip gmock-1.7.0.zip
mv gmock-1.7.0 gmock


2.5:phxrpc
cd /home/phxsql/third_party/phxrpc
mv third_party/protobuf third_party/bak_protobuf
ln -sf /home/phxsql/third_party/protobuf /home/phxsql/third_party/phxrpc/third_party/protobuf
make

2.6:phxpaxos
cd /home/phxsql/third_party/phxpaxos
mv third_party/protobuf third_party/bak_protobuf
mv third_party/leveldb third_party/bak_leveldb
mv third_party/glog third_party/bak_glog
ln -sf /home/phxsql/third_party/protobuf /home/phxsql/third_party/phxpaxos/third_party/protobuf
ln -sf /home/phxsql/third_party/leveldb /home/phxsql/third_party/phxpaxos/third_party/leveldb
ln -sf /home/phxsql/third_party/glog /home/phxsql/third_party/phxpaxos/third_party/glog

./autoinstall.sh
make
make install
cd plugin
make
make install

三、编译安装PHXSQL

cd /home/phxsql
wget https://www.percona.com/downloads/Percona-Server-5.6/Percona-Server-5.6.31-77.0/source/tarball/percona-server-5.6.31-77.0.tar.gz
tar xzvf percona-server-5.6.31-77.0.tar.gz
mv percona-server-5.6.31-77.0 percona
sh autoinstall.sh
make
make install

3.1:生成安装包

[root@localhost phxsql]# make package

creating package phxsql-0.8.0.tar.gz...

生成的压缩包名称为:phxsql-0.8.0.tar.gz,把它拷贝到其他机器上就可以部署了。

四、部署测试

把安装包拷贝到其他测试的机器上,解压,本文目录为/home/phxsql

创建mysql用户

useradd -d /home/datacenter -s /sbin/nologin mysql

mkdir /home/phxsql/etc

cd /home/phxsql/tools

把director_operator.py文件第26行中的chown user:mysql 修改为chown mysql:mysql

#因为前面测试的时候已经用三台虚拟机搭过一个集群了,这次就把这台机器加入到之前部署的集群中

[root@localhost sbin]# ./phxbinlogsvr_tools_phxrpc -f AddMember -h192.168.1.241 -p17000 -m 192.168.1.243

get master 192.168.1.241 expire time 1473413135

AddMember 192.168.1.243 done

#初始化PhxSQL

mkdir /home/datacenter

/usr/local/python27/bin/python2.7 install.py -i"192.168.1.243" -p 54321 -g 6000 -y 11111 -P 17000 -a 8001 -f /home/datacenter/

#备份集群中其他机器的percona数据

/home/phxsql/percona.src/bin/mysqldump --set-gtid-purged=off -h 192.168.1.186 -P11111 -u root --all-databases >/home/all.sql

#kill掉新加入机器的phxbinlogsvr进程

ps axf|grep phxbinlogsvr|grep -v grep|awk '{print $1}'|xargs kill

#通过本地端口登录新加机器的percona

/home/phxsql/percona.src/bin/mysql -h 127.0.0.1 -P11111 -u root

#登录之后执行以下操作

set GLOBAL super_read_only = 0; set GLOBAL read_only = 0;

#导入其他机器备份出的percona数据

/home/phxsql/percona.src/bin/mysql -h 127.0.0.1 -P11111 -u root < /home/all.sql

#启动phxbinlogsvr

nohup /home/phxsql/sbin/phxbinlogsvr_phxrpc &

之前的测试的集群由3台变成4台了

[root@localhost sbin]# ./phxbinlogsvr_tools_phxrpc -f GetMemberList -h"192.168.1.186" -p 17000

get master 192.168.1.241 expire time 1473416759

ip 192.168.1.186 port 17000

ip 192.168.1.180 port 17000

ip 192.168.1.241 port 17000

ip 192.168.1.243 port 17000

#查看复制状态,如果都是YES就可以测试了。

/home/phxsql/percona.src/bin/mysql -h 127.0.0.1 -P11111 -u root -e "show slave status\G;"

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

#测试

./test_phxsql.sh 54321 192.168.1.186 192.168.1.180 192.168.1.241 192.168.1.243

【附】:已编译版本下载:http://pan.baidu.com/s/1c1PgDQK 提取密码: dhxm,MD5:ffcebea7eebf51b2b9bcd52696bd2b1f

  • 发表评论
  • 查看评论
【现已经有5条评论】

aaa  2017-06-30 09:55:39 回复该评论
centos 6.8编译报错,如何解决[ 87%] Building C object storage/perfschema/unittest/CMakeFiles/pfs_connect_attr-t.dir/__/__/__/mysys/string.c.oLinking CXX executable pfs_connect_attr-tmake[3]: *** [storage/perfschema/unittest/pfs_connect_attr-t] Error 1make[3]: Leaving directory `/data/phxsql/percona'make[2]: *** [storage/perfschema/unittest/CMakeFiles/pfs_connect_attr-t.dir/all] Error 2make[2]: Leaving directory `/data/phxsql/percona'make[1]: *** [all] Error 2make[1]: Leaving directory `/data/phxsql/percona'make: *** [mysql] Error 2
xiao  2016-12-12 11:39:03 回复该评论
libleveldb有个问题,应该是进入third_party/leveldb目录。make,编译完成后会在out-static目录生成libleveldb.a文件。mkdir lib建立一个lib目录,然后cd lib;ln -s ../out-static/libleveldb.a libleveldb.a建立一个软链,PhxSQL通过lib这个目录来寻址静态库。
ERIC  2016-12-01 21:06:02 回复该评论
在安装protobuf时,进行make,总是报这个错,百度,谷歌无解\n\n\n\n----------------libtool: compile: g++ -DHAVE_CONFIG_H -I. -I.. -pthread -DHAVE_PTHREAD=1 -DHAVE_ZLIB=1 -Wall -Wno-sign-compare -fPIC -MT google/protobuf/any.pb.lo -MD -MP -MF google/protobuf/.deps/any.pb.Tpo -c google/protobuf/any.pb.cc -fPIC -DPIC -o google/protobuf/.libs/any.pb.oIn file included from ./google/protobuf/any.pb.h:25, from google/protobuf/any.pb.cc:5:./google/protobuf/metadata.h: In constructor ‘google::protobuf::internal::InternalMetadataWithArena::InternalMetadataWithArena(google::protobuf::Arena*)’:./google/protobuf/metadata.h:175: error: class ‘google::protobuf::internal::InternalMetadataWithArena’ does not have any field named ‘InternalMetadataWithArenaBase’./google/protobuf/metadata.h: In constructor ‘google::protobuf::internal::InternalMetadataWithArenaLite::InternalMetadataWithArenaLite(google::protobuf::Arena*)’:./google/protobuf/metadata.h:204: error: class ‘google::protobuf::internal::InternalMetadata
freya  2016-11-02 15:08:12 回复该评论
get master expire time 0get master expire time 0get master expire time 0init svr fail, ret -202初始化过程中,增加member过程中出错,无法继续安装,怎么解决哈
freya  2016-11-02 15:06:12 回复该评论
get master expire time 0get master expire time 0get master expire time 0init svr fail, ret -202这是什么错误,怎么解决哈

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。