Sep
8
官方更新了第三方库的版本之后,编译方法和可能遇到的错误和本文部分内容不一样了,全新安装的朋友请看【CentOS下PhxSQL编译安装第2版】
注:仅测试在CentOS release 6.7 和 CentOS Linux release 7.2.1511下编译通过,本文以用户使用较多的CentOS 6 操作系统为例,centos 7 的差别是不需要升级autoconf、automake、gcc和python的版本,其他操作系统的用户请参考官方提供的中文详细编译手册:https://github.com/tencent-wechat/phxsql/wiki/%E4%B8%AD%E6%96%87%E8%AF%A6%E7%BB%86%E7%BC%96%E8%AF%91%E6%89%8B%E5%86%8C
一、准备工作
1.1:相关项目地址:
https://github.com/tencent-wechat/phxsql
https://github.com/google/glog
https://github.com/google/googlemock
https://github.com/google/leveldb
https://github.com/tencent-wechat/phxpaxos
https://github.com/tencent-wechat/phxrpc
https://github.com/tencent-wechat/libco
https://github.com/google/protobuf
1.2:获取源码:
git clone --recursive https://github.com/tencent-wechat/phxsql.git (--recursive参数可以同时获得所依赖的第三方库colib,glog,leveldb,protobuf源码,和依赖库phxpaxos,phxrpc)
1.3:编译前的准备工作,由于centos自带或者使用yum安装的工具软件版本都比较低,所以要升级相关依赖的库及工具。
1.3.1:
yum install readline readline-devel libstdc++-static glibc-static perl-Module-Install.noarch -y
1.3.2:autoconf
下载地址:http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
1.3.3:automake
下载地址:http://ftp.gnu.org/gnu/automake/automake-1.14.tar.gz
1.3.4:cmake
下载地址:https://cmake.org/files/v3.6/cmake-3.6.1.tar.gz
1.3.5:python
下载地址:https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz
1.3.6:gcc
下载地址:http://ftp.gnu.org/gnu/gcc/gcc-4.9.4/gcc-4.9.4.tar.gz
####################################################################
1.3.7:boost (此步可忽略)
官网:http://www.boost.org/
下载地址:https://sourceforge.net/projects/boost/files/boost/1.61.0/
tar xzvf boost_1_61_0.tar.gz
cd boost_1_61_0
./bootstrap.sh --prefix=/usr/local/boost
./b2
./b2 install
echo /usr/local/boost/lib >/etc/ld.so.conf.d/boost.conf
ldconfig
####################################################################
二、编译相关依赖
三、编译安装PHXSQL
四、部署测试
把安装包拷贝到其他测试的机器上,解压,本文目录全部为/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
把binary_installer.py文件第35行中的 cd %s/percona.src; ./scripts/mysql_install_db --defaults-file=%s/etc/my.cnf 修改为:cd %spercona.src; ./scripts/mysql_install_db --defaults-file=%setc/my.cnf
测试部署是用的三台虚拟机:
python install.py -i"192.168.1.186" -p 54321 -g 6000 -y 11111 -P 17000 -a 8001 -f /home/datacenter/
python install.py -i"192.168.1.180" -p 54321 -g 6000 -y 11111 -P 17000 -a 8001 -f /home/datacenter/
/usr/local/python27/bin/python2.7 install.py -i"192.168.1.241" -p 54321 -g 6000 -y 11111 -P 17000 -a 8001 -f /home/datacenter/
在任意一台机器上执行
cd /home/phxsql/sbin/
./phxbinlogsvr_tools_phxrpc -f InitBinlogSvrMaster -h"192.168.1.186,192.168.1.180,192.168.1.241" -p 17000 (集群初始化完成之后就可以使用了。)
./phxbinlogsvr_tools_phxrpc -f GetMemberList -h"192.168.1.186" -p 17000
get master 192.168.1.241 expire time 1473313474
ip 192.168.1.186 port 17000
ip 192.168.1.180 port 17000
ip 192.168.1.241 port 17000
登录数据库:
/home/phxsql/percona.src/bin/mysql -uroot -h"192.168.1.186" -P54321
#获取master信息:
./phxbinlogsvr_tools_phxrpc -f GetMasterInfoFromGlobal -h 192.168.1.186 -p 17000
get master 192.168.1.241 expire time 1473314016
修改管理帐号及密码:
./phxbinlogsvr_tools_phxrpc -f SetMySqlAdminInfo -h 192.168.1.180 -p 17000 -u root -d "" -U zhj -D zhj2016
get master 192.168.1.241 expire time 1473313844
SetMySqlAdminInfo admin username root -> new admin username zhj
用官方提供的测试工具测试:
cd /home/phxsql/tools/
chmod +x test_phxsql.sh
./test_phxsql.sh 54321 192.168.1.186 192.168.1.180 192.168.1.241
sysbench 简单测试:
注:仅测试在CentOS release 6.7 和 CentOS Linux release 7.2.1511下编译通过,本文以用户使用较多的CentOS 6 操作系统为例,centos 7 的差别是不需要升级autoconf、automake、gcc和python的版本,其他操作系统的用户请参考官方提供的中文详细编译手册:https://github.com/tencent-wechat/phxsql/wiki/%E4%B8%AD%E6%96%87%E8%AF%A6%E7%BB%86%E7%BC%96%E8%AF%91%E6%89%8B%E5%86%8C
一、准备工作
1.1:相关项目地址:
https://github.com/tencent-wechat/phxsql
https://github.com/google/glog
https://github.com/google/googlemock
https://github.com/google/leveldb
https://github.com/tencent-wechat/phxpaxos
https://github.com/tencent-wechat/phxrpc
https://github.com/tencent-wechat/libco
https://github.com/google/protobuf
1.2:获取源码:
git clone --recursive https://github.com/tencent-wechat/phxsql.git (--recursive参数可以同时获得所依赖的第三方库colib,glog,leveldb,protobuf源码,和依赖库phxpaxos,phxrpc)
1.3:编译前的准备工作,由于centos自带或者使用yum安装的工具软件版本都比较低,所以要升级相关依赖的库及工具。
1.3.1:
yum install readline readline-devel libstdc++-static glibc-static perl-Module-Install.noarch -y
1.3.2: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
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.3.3: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
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.3.4: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
cd cmake-3.6.1
./configure
make && make install
1.3.5: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
cd Python-2.7.12
./configure --prefix=/usr/local/python27
make && make install
1.3.6:gcc
下载地址:http://ftp.gnu.org/gnu/gcc/gcc-4.9.4/gcc-4.9.4.tar.gz
tar xzvf gcc-4.9.4.tar.gz
cd gcc-4.9.4
./contrib/download_prerequisites
cd ..
mkdir gcc-build-4.9.4
cd gcc-build-4.9.4
../gcc-4.9.4/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-unknown-linux-gnu-gcc-4.9.4 40 (优先使用4.9.4版本的gcc)
使用 gcc --version 就可以看见当前使用的gcc版本是刚才编译的新版本了。
cp gcc-build-4.9.4/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.20 /usr/lib64/
删除原来低版本的软链:rm -rf /usr/lib64/libstdc++.so.6
创建新版本的软链:ln -sf /usr/lib64/libstdc++.so.6.0.20 /usr/lib64/libstdc++.so.6
cd gcc-4.9.4
./contrib/download_prerequisites
cd ..
mkdir gcc-build-4.9.4
cd gcc-build-4.9.4
../gcc-4.9.4/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-unknown-linux-gnu-gcc-4.9.4 40 (优先使用4.9.4版本的gcc)
使用 gcc --version 就可以看见当前使用的gcc版本是刚才编译的新版本了。
cp gcc-build-4.9.4/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.20 /usr/lib64/
删除原来低版本的软链:rm -rf /usr/lib64/libstdc++.so.6
创建新版本的软链:ln -sf /usr/lib64/libstdc++.so.6.0.20 /usr/lib64/libstdc++.so.6
####################################################################
1.3.7:boost (此步可忽略)
官网:http://www.boost.org/
下载地址:https://sourceforge.net/projects/boost/files/boost/1.61.0/
tar xzvf boost_1_61_0.tar.gz
cd boost_1_61_0
./bootstrap.sh --prefix=/usr/local/boost
./b2
./b2 install
echo /usr/local/boost/lib >/etc/ld.so.conf.d/boost.conf
ldconfig
####################################################################
二、编译相关依赖
2.1:colib
cd /home/phxsql/third_party/colib
make
2.2:glog
cd /home/phxsql/third_party/glog
mkdir build && cd build
export CXXFLAGS="-fPIC" && cmake .. -DCMAKE_INSTALL_PREFIX=/home/phxsql/third_party/glog && make VERBOSE=1
make
make install
2.3:leveldb
/home/phxsql/third_party/leveldb
make
mkdir lib
cp -ar out-shared lib/
cp -ar out-static lib/
2.4:protobuf
cd /home/phxsql/third_party/protobuf
./autogen.sh
./configure CXXFLAGS=-fPIC --prefix=/home/phxsql/third_party/protobuf
make
make install
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
ln -sf /usr/local/boost/include/boost /home/phxsql/third_party/phxrpc/boost
make
make boost (如果前面boost忽略,此步略过)
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
cd /home/phxsql/third_party/colib
make
2.2:glog
cd /home/phxsql/third_party/glog
mkdir build && cd build
export CXXFLAGS="-fPIC" && cmake .. -DCMAKE_INSTALL_PREFIX=/home/phxsql/third_party/glog && make VERBOSE=1
make
make install
2.3:leveldb
/home/phxsql/third_party/leveldb
make
mkdir lib
cp -ar out-shared lib/
cp -ar out-static lib/
2.4:protobuf
cd /home/phxsql/third_party/protobuf
./autogen.sh
./configure CXXFLAGS=-fPIC --prefix=/home/phxsql/third_party/protobuf
make
make install
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
ln -sf /usr/local/boost/include/boost /home/phxsql/third_party/phxrpc/boost
make
make boost (如果前面boost忽略,此步略过)
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:生成安装包
make package
生成的压缩包名称为:phxsql-0.8.0.tar.gz
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:生成安装包
make package
生成的压缩包名称为: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
把binary_installer.py文件第35行中的 cd %s/percona.src; ./scripts/mysql_install_db --defaults-file=%s/etc/my.cnf 修改为:cd %spercona.src; ./scripts/mysql_install_db --defaults-file=%setc/my.cnf
测试部署是用的三台虚拟机:
python install.py -i"192.168.1.186" -p 54321 -g 6000 -y 11111 -P 17000 -a 8001 -f /home/datacenter/
python install.py -i"192.168.1.180" -p 54321 -g 6000 -y 11111 -P 17000 -a 8001 -f /home/datacenter/
/usr/local/python27/bin/python2.7 install.py -i"192.168.1.241" -p 54321 -g 6000 -y 11111 -P 17000 -a 8001 -f /home/datacenter/
在任意一台机器上执行
cd /home/phxsql/sbin/
./phxbinlogsvr_tools_phxrpc -f InitBinlogSvrMaster -h"192.168.1.186,192.168.1.180,192.168.1.241" -p 17000 (集群初始化完成之后就可以使用了。)
./phxbinlogsvr_tools_phxrpc -f GetMemberList -h"192.168.1.186" -p 17000
get master 192.168.1.241 expire time 1473313474
ip 192.168.1.186 port 17000
ip 192.168.1.180 port 17000
ip 192.168.1.241 port 17000
登录数据库:
/home/phxsql/percona.src/bin/mysql -uroot -h"192.168.1.186" -P54321
#获取master信息:
./phxbinlogsvr_tools_phxrpc -f GetMasterInfoFromGlobal -h 192.168.1.186 -p 17000
get master 192.168.1.241 expire time 1473314016
修改管理帐号及密码:
./phxbinlogsvr_tools_phxrpc -f SetMySqlAdminInfo -h 192.168.1.180 -p 17000 -u root -d "" -U zhj -D zhj2016
get master 192.168.1.241 expire time 1473313844
SetMySqlAdminInfo admin username root -> new admin username zhj
用官方提供的测试工具测试:
cd /home/phxsql/tools/
chmod +x test_phxsql.sh
./test_phxsql.sh 54321 192.168.1.186 192.168.1.180 192.168.1.241
sysbench 简单测试: