CentOS 7.9 环境安装 PolarDB-X 数据库
0. 参考官方

1. 基本环境
[root@c79-model ~]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
[root@c79-model ~]#
[root@c79-model opt]# free -h
total used free shared buff/cache available
Mem: 3.7G 205M 1.7G 8.5M 1.8G 3.3G
Swap: 0B 0B 0B
[root@c79-model opt]#
[root@c79-model ~]# ll
total 658596
-rw-------. 1 root root 1300 Dec 31 08:04 anaconda-ks.cfg
drwxr-xr-x. 2 root root 42 Dec 31 09:18 bin
-rw-r--r--. 1 root root 674397380 Jan 8 11:46 t-polardbx-engine-8.4.19-20250825_17558853.el7.x86_64.rpm
[root@c79-model ~]#
2. 配置本地 Yum 私服
[root@c79-model ~]# cd /isos/
[root@c79-model isos]# ll
total 9961476
-rw-r--r--. 1 root root 10200547328 Dec 31 08:08 CentOS-7-x86_64-Everything-2009.iso
-rw-r--r--. 1 root root 53 Dec 31 08:16 mount.sh
[root@c79-model isos]# cat mount.sh
mount /isos/CentOS-7-x86_64-Everything-2009.iso /mnt
[root@c79-model isos]# sh mount.sh
mount: /dev/loop0 is write-protected, mounting read-only
[root@c79-model isos]#
[root@c79-model isos]# cd
[root@c79-model ~]#
[root@c79-model ~]# cd /etc/yum.repos.d/
[root@c79-model yum.repos.d]# vim CentOS-local.repo
[root@c79-model yum.repos.d]# cat CentOS-local.repo
[base]
name=CentOS-$releasever - Local
baseurl=file:///mnt
enabled=1
gpgcheck=0
[root@c79-model yum.repos.d]#
[root@c79-model ~]#
[root@c79-model ~]# yum makecache fast
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
(1/2): base/group_gz | 153 kB 00:00:00
(2/2): base/primary_db | 6.1 MB 00:00:00
Metadata Cache Created
[root@c79-model ~]#
3. 安装 PolardbX 单机版
[root@c79-model ~]# yum install ./t-polardbx-engine-8.4.19-20250825_17558853.el7.x86_64.rpm
Loaded plugins: fastestmirror
Examining ./t-polardbx-engine-8.4.19-20250825_17558853.el7.x86_64.rpm: t-polardbx-engine-8.4.19-20250825_17558853.el7.x86_64
Marking ./t-polardbx-engine-8.4.19-20250825_17558853.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package t-polardbx-engine.x86_64 0:8.4.19-20250825_17558853.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================
Installing:
t-polardbx-engine x86_64 8.4.19-20250825_17558853.el7 /t-polardbx-engine-8.4.19-20250825_17558853.el7.x86_64 2.8 G
Transaction Summary
======================================================================================================================================
Install 1 Package
Total size: 2.8 G
Installed size: 2.8 G
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : t-polardbx-engine-8.4.19-20250825_17558853.el7.x86_64 1/1
Copying /u01/xcluster80_20250825_current to /u01/xcluster80
Copying /u01/xcluster80_20250825_current to /u01/xcluster80_20250825
Verifying : t-polardbx-engine-8.4.19-20250825_17558853.el7.x86_64 1/1
Installed:
t-polardbx-engine.x86_64 0:8.4.19-20250825_17558853.el7
Complete!
[root@c79-model ~]#

4. 检查安装后的路径
[root@c79-model ~]# ll /opt/polardbx_engine/
total 708
drwxr-xr-x. 2 root root 4096 Jan 8 11:51 bin
drwxr-xr-x. 2 root root 87 Jan 8 11:51 docs
drwxr-xr-x. 3 root root 4096 Jan 8 11:51 include
drwxr-xr-x. 6 root root 207 Jan 8 11:51 lib
-rwxr-xr-x. 1 root root 283374 Jan 8 11:50 LICENSE
-rwxr-xr-x. 1 root root 121462 Jan 8 11:50 LICENSE.router
-rwxr-xr-x. 1 root root 283374 Jan 8 11:50 LICENSE-test
drwxr-xr-x. 4 root root 30 Jan 8 11:51 man
-rwxr-xr-x. 1 root root 1622 Jan 8 11:51 mysqlrouter-log-rotate
-rwxr-xr-x. 1 root root 952 Jan 8 11:50 README
-rwxr-xr-x. 1 root root 679 Jan 8 11:50 README.router
-rwxr-xr-x. 1 root root 952 Jan 8 11:50 README-test
drwxr-xr-x. 2 root root 6 Jan 8 11:51 run
drwxr-xr-x. 28 root root 4096 Jan 8 11:51 share
drwxr-xr-x. 2 root root 77 Jan 8 11:51 support-files
drwxr-xr-x. 3 root root 17 Jan 8 11:51 var
[root@c79-model ~]#
[root@c79-model ~]# ll /opt/polardbx_engine/bin

5. 创建 polarx 用户,PolarDB-X 基本配置
[root@c79-model ~]# useradd -ms /bin/bash polarx
[root@c79-model ~]#
[root@c79-model ~]# echo "polarx:polarx" | chpasswd
[root@c79-model ~]#
[root@c79-model ~]# echo "polarx ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
[root@c79-model ~]#
[root@c79-model ~]# su - polarx
[polarx@c79-model ~]$
[polarx@c79-model ~]$ mkdir polardbx-engine
[polarx@c79-model ~]$ cd polardbx-engine && mkdir log mysql run data tmp
[polarx@c79-model polardbx-engine]$
[polarx@c79-model polardbx-engine]$ ll
total 0
drwxrwxr-x. 2 polarx polarx 6 Jan 8 11:54 data
drwxrwxr-x. 2 polarx polarx 6 Jan 8 11:54 log
drwxrwxr-x. 2 polarx polarx 6 Jan 8 11:54 mysql
drwxrwxr-x. 2 polarx polarx 6 Jan 8 11:54 run
drwxrwxr-x. 2 polarx polarx 6 Jan 8 11:54 tmp
[polarx@c79-model polardbx-engine]$
[polarx@c79-model polardbx-engine]$ vim my.cnf
[polarx@c79-model polardbx-engine]$ cat my.cnf
[mysqld]
basedir = /opt/polardbx_engine
log_error_verbosity = 2
default_authentication_plugin = mysql_native_password
gtid_mode = ON
enforce_gtid_consistency = ON
log_bin = mysql-binlog
binlog_format = row
binlog_row_image = FULL
master_info_repository = TABLE
relay_log_info_repository = TABLE
# change me if needed
datadir = /home/polarx/polardbx-engine/data
tmpdir = /home/polarx/polardbx-engine/tmp
socket = /home/polarx/polardbx-engine/tmp.mysql.sock
log_error = /home/polarx/polardbx-engine/log/alert.log
port = 4886
cluster_id = 1234
cluster_info = 127.0.0.1:14886@1
server_id = 2712347953
[mysqld_safe]
pid_file = /home/polarx/polardbx-engine/run/mysql.pid
[polarx@c79-model polardbx-engine]$


6. 数据库初始化
[polarx@c79-model polardbx-engine]$ /opt/polardbx_engine/bin/mysqld --defaults-file=my.cnf --initialize-insecure
/opt/polardbx_engine/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
[polarx@c79-model polardbx-engine]$
- 安装下 libaio-devel 依赖
[polarx@c79-model polardbx-engine]$ sudo yum install libaio-devel -y
[polarx@c79-model polardbx-engine]$

- 重新初始化
[polarx@c79-model polardbx-engine]$ /opt/polardbx_engine/bin/mysqld --defaults-file=my.cnf --initialize-insecure
[polarx@c79-model polardbx-engine]$

7. 启动 PolarDB-X 数据库
[polarx@c79-model polardbx-engine]$ /opt/polardbx_engine/bin/mysqld_safe --defaults-file=my.cnf &
[1] 1569
[polarx@c79-model polardbx-engine]$ 2026-01-08T03:58:43.495978Z mysqld_safe Logging to '/home/polarx/polardbx-engine/log/alert.log'.
2026-01-08T03:58:43.515539Z mysqld_safe Starting mysqld daemon with databases from /home/polarx/polardbx-engine/data
[polarx@c79-model polardbx-engine]$
8. 检查 端口号(默认 4886)
[polarx@c79-model polardbx-engine]$ netstat -antp|grep 4886
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6 0 0 :::4886 :::* LISTEN 1866/mysqld
tcp6 0 0 :::14886 :::* LISTEN 1866/mysqld
[polarx@c79-model polardbx-engine]$
9. 客户端登录
[polarx@c79-model polardbx-engine]$ mysql -h127.0.0.1 -P4886 -uroot
-bash: mysql: command not found
[polarx@c79-model polardbx-engine]$
- 绝对路径使用
[polarx@c79-model polardbx-engine]$ /opt/polardbx_engine/bin/mysql -h127.0.0.1 -P4886 -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.32-X-Cluster-8.4.19-20250825 Source distribution
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select version();
+----------------------------------+
| version() |
+----------------------------------+
| 8.0.32-X-Cluster-8.4.19-20250825 |
+----------------------------------+
1 row in set (0.00 sec)
mysql>

我们下期见咯!
关于笔者张阳,曾就职于 中国人保、麒麟软件、华为、铁科院、中广核工程、南方电网、华夏银行,欢迎有坑位的大大 chat w e: zhangyang_bigdata

