前言
有台 ARM 架构的服务器,需要安装 “国产” Kylin 系统,然后部署 MySQL5.7 版本。
经过查阅网络上的相关资料和自身积累,整体思路如下:
- 通过源码编译安装 MySQL 5.7
- 网络上的资料几乎没有在Kylin arm64 系统上进行编译安装,转而决定先行在 CentOS arm64系统上编译安装,编译完成后,复制到 Kylin arm64 系统上运行,缺啥补啥。
- 通过 docker 进行安装部署 MySQL 5.7
- 容器确实很方便,一切皆容器。
下面记录实现这两种方式的整体过程。
环境介绍
系统版本信息:
尝试使用 yum 直接安装:
没有 mysql-server
,但是有 mariadb-server
。如果没有硬性要求,直接使用 mariadb-server
也就不必要折腾了。
编译安装
Kylin 系统版本为:Kylin-Server-10-SP1
,查阅资料是 CentOS 8 修改而成。这里采用 CentOS 7 arm64 版本来编译 MySQL5.7
首先,需要一台安装有 CentOS 7 arm64 的主机(最好是虚拟机)。
更改yum源
mv /etc/yum.repos.d/CentOS-Base.repo /tmp/
curl https://mirrors.huaweicloud.com/repository/conf/CentOS-AltArch-7.repo -o /etc/yum.repos.d/CentOS-Base.repo
yum install bison* ncurses* gcc* vim -y
安装 cmake
yum install cmake -y
编译安装 gcc
~]#tar xf make_mysql5.7.tar.gz
~/make_mysql5.7]#ls
gcc-7.3.0.tar.gz mysql-boost-5.7.31.tar.gz
~/make_mysql5.7]#tar xf gcc-7.3.0.tar.gz
~/make_mysql5.7]#cd gcc-7.3.0
~/make_mysql5.7/gcc-7.3.0]#mkdir gcc-build-7.3.0 ; cd gcc-build-7.3.0
~/make_mysql5.7/gcc-7.3.0/gcc-build-7.3.0]#../configure --enable-checking=release --enable-language=c,c++ --disable-multilib --prefix=/usr
~/make_mysql5.7/gcc-7.3.0/gcc-build-7.3.0]#lscpu | grep -i '^CPU(s)' ### 查看有多少逻辑CPU
~/make_mysql5.7/gcc-7.3.0/gcc-build-7.3.0]#time make -j 8 ### 指定多线程同时进行,大约半个小时
~/make_mysql5.7/gcc-7.3.0/gcc-build-7.3.0]#make install
~/make_mysql5.7/gcc-7.3.0/gcc-build-7.3.0]#gcc -v
本次编译gcc 所用时间:
源码编译MySQL
~/make_mysql5.7]#yum install openssl-devel -y
~/make_mysql5.7]#tar xf mysql-boost-5.7.31.tar.gz
~/make_mysql5.7]#cd mysql-5.7.31/
~/make_mysql5.7/mysql-5.7.31]#yum install patch -y
~/make_mysql5.7/mysql-5.7.31]#patch -p1 < 0001-Bug-94699-Mysql-deadlock-and-bugcheck-on-aarch64.patch
patching file storage/innobase/sync/sync0rw.cc
Reversed (or previously applied) patch detected! Assume -R? [n] #回车
Apply anyway? [n] #回车
Skipping patch.
2 out of 2 hunks ignored -- saving rejects to file storage/innobase/sync/sync0rw.cc.rej
重要步骤,不然编译时会报错
~/make_mysql5.7/mysql-5.7.31]#cp -a /usr/include/sys/prctl.h /root/make_mysql5.7/mysql-5.7.31/include/
~/make_mysql5.7/mysql-5.7.31]#vim /root/make_mysql5.7/mysql-5.7.31/sql/mysqld.cc
添加如下图所示的一样:
创建编译脚本:
~/make_mysql5.7/mysql-5.7.31]#vim cmake.sh
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/usr/local/mysql/data
-DSYSCONFDIR=/etc
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_MYISAM_STORAGE_ENGINE=1
-DENABLED_LOCAL_INFILE=1
-DENABLE_DTRACE=0
-DDEFAULT_CHARSET=utf8mb4
-DDEFAULT_COLLATION=utf8mb4_general_ci
-DWITH_EMBEDDED_SERVER=1
-DDOWNLOAD_BOOST=1
-DWITH_BOOST=/root/make_mysql5.7/mysql-5.7.31/boost/boost_1_59_0/
~/make_mysql5.7/mysql-5.7.31]#sh cmake.sh ### 开始编译
~/make_mysql5.7/mysql-5.7.31]#time make -j 8
~/make_mysql5.7/mysql-5.7.31]#make install
到此,MySQL5.7 编译完成。
配置启动MySQL
~]#cd /usr/local/mysql/
/usr/local/mysql]#groupadd -g 306 mysql
/usr/local/mysql]#useradd -u 306 -g 306 -M -s /sbin/nologin mysql
/usr/local/mysql]#mkdir -p data run log
/usr/local/mysql]#chown -R mysql:mysql /usr/local/mysql/
/usr/local/mysql]#touch log/mysql.log
/usr/local/mysql]#touch run/mysql.pid
注意:先检查 /usr/local/mysql/data/ 目录下是否有文件,有则删除后再进行初始化。
/usr/local/mysql]#bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
卸载遗留的 maridb-libs 包
/usr/local/mysql]#rpm -qf /etc/my.cnf
mariadb-libs-5.5.68-1.el7.aarch64
/usr/local/mysql]#rpm -e --nodeps mariadb-libs-5.5.68-1.el7.aarch64
编写配置文件
/usr/local/mysql]#vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data/
socket=/usr/local/mysql/mysql.sock
[mysqld_safe]
log-error=/usr/local/mysql/log/mysql.log
pid-file=/usr/local/mysql/run/mysql.pid
启动MySQL服务
/usr/local/mysql]#cp -a support-files/mysql.server /etc/init.d/mysqld
/usr/local/mysql]#chmod +x /etc/init.d/mysqld
/usr/local/mysql]#/etc/init.d/mysqld start
Starting MySQL. SUCCESS!
客户端尝试连接MySQL
~]#cat << "EOF" > /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
EOF
~]#source /etc/profile.d/mysql.sh
~]#ln -vs /usr/local/mysql/mysql.sock /tmp/
‘/tmp/mysql.sock’ -> ‘/usr/local/mysql/mysql.sock’
~]#mysql -uroot -p'q>y/(+NJl4Vq'
登录成功。
接下来就需要将编译好的MySQL 迁移到 Kylin 系统里,然后查缺补漏。
迁移编译后的MySQL
首先停止 MySQL服务:
/usr/local]#/etc/init.d/mysqld stop
Shutting down MySQL. SUCCESS!
删除初始化数据:
/usr/local/mysql]#rm -rf data/*
打包拷贝到Kylin主机:
/usr/local]#tar zcf mysql.tar.gz mysql/
/usr/local]#scp mysql.tar.gz 192.168.1.98:/usr/local/
[192.168.1.98] 系统配置如下
初始化数据库
### 初始化 ###
/usr/local/mysql]# bin/mysqld --initialize --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --user=mysql
bin/mysqld: error while loading shared libraries: libssl.so.10: cannot open shared object file: No such file or directory
缺少什么就从之前编译的 CentOS arm64 主机上拷贝到对应的目录下
切换到 CentOS arm64 主机上操作
~]#yum install mlocate -y
~]#updatedb
~]#locate libssl.so.10
/usr/lib64/.libssl.so.10.hmac
/usr/lib64/libssl.so.10
- 拷贝到Kylin 系统对应的位置 -
~]#scp /usr/lib64/libssl.so.10 192.168.1.98:/usr/lib64/
~]#scp /usr/lib64/libcrypto.so.10 192.168.1.98:/usr/lib64/
~]#scp /usr/lib64/libatomic.so.1 192.168.1.98:/usr/lib64/
Kylin 启动MySQL
创建用户并初始化
~]#cd /usr/local/mysql/
/usr/local/mysql]#groupadd -g 306 mysql
/usr/local/mysql]#useradd -u 306 -g 306 -M -s /sbin/nologin mysql
/usr/local/mysql]#mkdir -p data run log
/usr/local/mysql]#chown -R mysql:mysql /usr/local/mysql/
/usr/local/mysql]#touch log/mysql.log
/usr/local/mysql]#touch run/mysql.pid
添加配置并启动服务
/usr/local/mysql]#rpm -qf /etc/my.cnf.d/
mariadb-connector-c-3.0.6-6.ky10.aarch64
/usr/local/mysql]#rpm -e --nodeps mariadb-connector-c-3.0.6-6.ky10.aarch64
~]#vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data/
socket=/usr/local/mysql/mysql.sock
[mysqld_safe]
log-error=/usr/local/mysql/log/mysql.log
pid-file=/usr/local/mysql/run/mysql.pid
/usr/local/mysql]#cp -a support-files/mysql.server /etc/init.d/mysqld
/usr/local/mysql]#chmod +x /etc/init.d/mysqld
~]#/etc/init.d/mysqld start
Starting MySQL. SUCCESS!
~]#lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 3603 mysql 28u IPv6 32448 0t0 TCP *:mysql (LISTEN)
配置环境变量
cat << 'EOF' > /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
EOF
~]#source /etc/profile.d/mysql.sh
配置MySQL 用户权限
~]#ln -vs /usr/local/mysql/mysql.sock /tmp/
~]#mysql -uroot -p'shmPIMtqX3-f'
mysql> alter user user() identified by '123123';
mysql> flush privileges;
- 用修改后的密码登录 -
~]#mysql -uroot -p123123
mysql> grant all privileges on *.* to 'root'@'%' identified by '123123' with grant option;
到此, 编译安装MySQL5.7 然后拷贝到 Kylin 系统中初始化并启动成功。
容器启动MySQL
Kylin arm64 使用docker 启动 MySQL 相比较 源码编译安装就方便很多。
安装docker
~]# yum install docker docker-compose -y
~]# cat << 'EOF' > /etc/docker/daemon.json
{
"data-root": "/opt/docker",
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"http://f1361db2.m.daocloud.io",
"http://hub-mirror.c.163.com"
]
}
EOF
~]# systemctl restart docker
创建 docker-compose.yaml文件
cat << 'EOF' > docker-compose.yml
version: '3.1'
services:
db:
image: biarms/mysql:5.7.30-linux-arm64v8
restart: always
container_name: mysql
environment:
- TZ=Asia/Shanghai
- MYSQL_ROOT_PASSWORD=123456
command:
--default-authentication-plugin=mysql_native_password
--sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=0
ports:
- 3306:3306
volumes:
- ./data:/var/lib/mysql
EOF
通过 docker-compose 启动容器
docker-compose -f docker-compose.yml up -d
启动完成后,即可通过外部工具访问 MySQL 。