LINUX手动安装万里开源单实例

下载安装包

https://gitee.com/GreatSQL/GreatSQL/releases/

关闭 selinux 和防火墙

#关闭selinux
$ setenforce=0
$ sed -i '/^SELINUX=/c'SELINUX=disabled /etc/selinux/config

#关闭防火墙
$ systemctl disable firewalld
$ systemctl stop firewalld
$ systemctl disable iptables
$ systemctl stop iptables

下载二进制包并安装

将下载的二进制包放在安装目录 /usr/local/ 下,并解压缩:

# 下载
$ cd /usr/local
$ wget wget https://product.greatdb.com/GreatSQL-8.0.32-26/GreatSQL-8.0.32-26-Linux-glibc2.17-x86_64.tar.xz
#或者用curl
$ curl -o GreatSQL-8.0.32-26-Linux-glibc2.17-x86_64.tar.xz https://product.greatdb.com/GreatSQL-8.0.32-26/GreatSQL-8.0.32-26-Linux-glibc2.17-x86_64.tar.xz

#解压缩
$ tar xf GreatSQL-8.0.32-26-Linux-glibc2.17-x86_64.tar.xz

编辑systemd系统服务文件,增加GreatSQL服务文件:务必确认文件中目录及文件名是否正确。

vi /usr/lib/systemd/system/greatsql.service

[Unit]
Description=GreatSQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=notify
TimeoutSec=0
PermissionsStartOnly=true
ExecStartPre=/usr/local/GreatSQL-8.0.32-26-Linux-glibc2.17-x86_64/bin/mysqld_pre_systemd
ExecStart=/usr/local/GreatSQL-8.0.32-26-Linux-glibc2.17-x86_64/bin/mysqld $MYSQLD_OPTS
EnvironmentFile=-/etc/sysconfig/mysql
LimitNOFILE = 10000
Restart=on-failure
RestartPreventExitStatus=1
Environment=MYSQLD_PARENT_PID=1
PrivateTmp=false

执行命令重载systemd,加入 greatsql 服务,如果没问题就不会报错:

这就安装成功并将GreatSQL添加到系统服务中,后面可以用 systemctl 来管理GreatSQL服务。

systemctl daemon-reload

编辑GreatSQL全局配置文件 /etc/my.cnf,加入下面内容并保存退出

[mysqld]
user = mysql
port = 3306
server_id = 3306
basedir=/usr/local/GreatSQL-8.0.32-26-Linux-glibc2.17-x86_64
datadir = /data/GreatSQL
socket = /data/GreatSQL/mysql.sock
pid-file = mysql.pid
character-set-server = UTF8MB4
skip_name_resolve = 1
#若你的MySQL数据库主要运行在境外,请务必根据实际情况调整本参数
default_time_zone = "+8:00"

#performance setttings
lock_wait_timeout = 3600
open_files_limit    = 65535
back_log = 1024
max_connections = 512
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
thread_stack = 512K
sort_buffer_size = 4M
join_buffer_size = 4M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
thread_cache_size = 768
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M

#log settings
log_timestamps = SYSTEM
log_error = /data/GreatSQL/error.log
log_error_verbosity = 3
slow_query_log = 1
log_slow_extra = 1
slow_query_log_file = /data/GreatSQL/slow.log
long_query_time = 0.1
log_queries_not_using_indexes = 1
log_throttle_queries_not_using_indexes = 60
min_examined_row_limit = 100
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_bin = /data/GreatSQL/binlog
binlog_format = ROW
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G
binlog_rows_query_log_events = 1
binlog_expire_logs_seconds = 604800
#MySQL 8.0.22前,想启用MGR的话,需要设置binlog_checksum=NONE才行
binlog_checksum = CRC32
gtid_mode = ON
enforce_gtid_consistency = TRUE

#myisam settings
key_buffer_size = 32M
myisam_sort_buffer_size = 128M

#replication settings
master_info_repository = TABLE
relay_log_info_repository = TABLE
relay_log_recovery = 1
slave_parallel_type = LOGICAL_CLOCK
#可以设置为逻辑CPU数量的2倍
slave_parallel_workers = 64
binlog_transaction_dependency_tracking = WRITESET
slave_preserve_commit_order = 1
slave_checkpoint_period = 2

#mgr settings
loose-plugin_load_add = 'mysql_clone.so'
loose-plugin_load_add = 'group_replication.so'
loose-group_replication_group_name = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1"
#MGR本地节点IP:PORT,请自行替换
loose-group_replication_local_address = "172.16.16.10:33061"
#MGR集群所有节点IP:PORT,请自行替换
loose-group_replication_group_seeds = "172.16.16.10:33061,172.16.16.11:33061,172.16.16.12:33061"
loose-group_replication_start_on_boot = OFF
loose-group_replication_bootstrap_group = OFF
loose-group_replication_exit_state_action = READ_ONLY
loose-group_replication_flow_control_mode = "DISABLED"
loose-group_replication_single_primary_mode = ON

#innodb settings
transaction_isolation = REPEATABLE-READ
innodb_buffer_pool_size = 2G
innodb_buffer_pool_instances = 8
innodb_data_file_path = ibdata1:12M:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 1G
innodb_log_files_in_group = 3
innodb_max_undo_log_size = 4G
# 根据您的服务器IOPS能力适当调整
# 一般配普通SSD盘的话,可以调整到 10000 - 20000
# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_open_files = 65535
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_online_alter_log_max_size = 4G
innodb_print_ddl_logs = 1
innodb_status_file = 1
#注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log_error文件增长较快
innodb_status_output = 0
innodb_status_output_locks = 1
innodb_sort_buffer_size = 67108864

#innodb monitor settings
innodb_monitor_enable = "module_innodb"
innodb_monitor_enable = "module_server"
innodb_monitor_enable = "module_dml"
innodb_monitor_enable = "module_ddl"
innodb_monitor_enable = "module_trx"
innodb_monitor_enable = "module_os"
innodb_monitor_enable = "module_purge"
innodb_monitor_enable = "module_log"
innodb_monitor_enable = "module_lock"
innodb_monitor_enable = "module_buffer"
innodb_monitor_enable = "module_index"
innodb_monitor_enable = "module_ibuf_system"
innodb_monitor_enable = "module_buffer_page"
innodb_monitor_enable = "module_adaptive_hash"

#pfs settings
performance_schema = 1
#performance_schema_instrument = '%memory%=on'
performance_schema_instrument = '%lock%=on'

创建mysql系统用户:

$ /sbin/groupadd mysql
$ /sbin/useradd -g mysql mysql -d /dev/null -s /sbin/nologin

创建相关文件夹,并修改用户组(将文件中的 /usr/local/GreatSQL-8.0.32-25-Linux-glibc2.28-x86_64/改为实际安装目录):

mkdir /var/run/mysqld/ /var/lib/mysql-files/ /var/lib/mysql/ 

chown mysql:mysql /var/run/mysqld/ /var/lib/mysql-files/ /var/lib/mysql/ /usr/local/GreatSQL-8.0.32-26-Linux-glibc2.17-x86_64/

启动GreatSQL

执行下面的命令启动GreatSQL服务

systemctl start greatsql

检查服务是否已启动,以及进程状态:

[root@192 data]# systemctl status greatsql
● greatsql.service - GreatSQL Server
   Loaded: loaded (/usr/lib/systemd/system/greatsql.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2025-02-09 18:43:14 CST; 45min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 31673 (mysqld)
   Status: "Server is operational"
    Tasks: 54 (limit: 100480)
   Memory: 639.4M
   CGroup: /system.slice/greatsql.service
           └─31673 /usr/local/GreatSQL-8.0.32-26-Linux-glibc2.17-x86_64/bin/mysqld

2月 09 18:42:58 192.168.188.23 systemd[1]: Starting GreatSQL Server...
2月 09 18:43:14 192.168.188.23 systemd[1]: Started GreatSQL Server.
[root@192 data]# ps -ef | grep mysqld
mysql      31673       1  0 18:42 ?        00:00:13 /usr/local/GreatSQL-8.0.32-26-Linux-glibc2.17-x86_64/bin/mysqld
root       32664    1646  0 19:28 pts/0    00:00:00 grep --color=auto mysqld
[root@192 data]# ss -lntp | grep mysqld
LISTEN 0      70                 *:33060            *:*    users:(("mysqld",pid=31673,fd=46))
LISTEN 0      1024               *:3306             *:*    users:(("mysqld",pid=31673,fd=51))
#查看数据文件
[root@192 data]# ls /data/GreatSQL
 auto.cnf        binlog.000004   ca.pem           '#file_purge'         '#ib_16384_12.dblwr'  '#ib_16384_1.dblwr'  '#ib_16384_5.dblwr'  '#ib_16384_9.dblwr'  '#innodb_redo'         mysql.ibd         performance_schema   server-key.pem   undo_002
 binlog.000001   binlog.000005   client-cert.pem  '#ib_16384_0.dblwr'   '#ib_16384_13.dblwr'  '#ib_16384_2.dblwr'  '#ib_16384_6.dblwr'   ib_buffer_pool       innodb_status.31673   mysql.pid         private_key.pem      slow.log
 binlog.000002   binlog.index    client-key.pem   '#ib_16384_10.dblwr'  '#ib_16384_14.dblwr'  '#ib_16384_3.dblwr'  '#ib_16384_7.dblwr'   ibdata1             '#innodb_temp'         mysql.sock        public_key.pem       sys
 binlog.000003   ca-key.pem      error.log        '#ib_16384_11.dblwr'  '#ib_16384_15.dblwr'  '#ib_16384_4.dblwr'  '#ib_16384_8.dblwr'   ibtmp1               mysql                 mysql.sock.lock   server-cert.pem      undo_001
[root@192 data]#

可以看到,GreatSQL服务已经正常启动了。

连接登入GreatSQL

采用minimal二进制包安装GreatSQL后,通过log-error日志查看初始化密码,即可登入。

$ cat /var/log/mysqld.log|grep password
[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: NrkNcJya<9f6

若使用了GreatSQL推荐的my.cnf则错误日志路径发生改变,请使用以下命令查看初始化密码

$ $ grep -i root /data/GreatSQL/error.log
... A temporary password is generated for root@localhost: ji!pjndiw5sJ

复制密码即可登入GreatSQL

/usr/local/GreatSQL-8.0.32-26-Linux-glibc2.17-x86_64/bin/mysql -uroot -p'ji!pjndiw5sJ'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 8.0.32-26 GreatSQL, Release 26, Revision a68b3034c3d

Copyright (c) 2021-2024 GreatDB Software Co., Ltd
Copyright (c) 2009-2024 Percona LLC and/or its affiliates
Copyright (c) 2000, 2024, 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> 
mysql> 
mysql> 
mysql> 
mysql> \s
--------------
/usr/local/GreatSQL-8.0.32-26-Linux-glibc2.17-x86_64/bin/mysql  Ver 8.0.32-26 for Linux on x86_64 (GreatSQL, Release 26, Revision a68b3034c3d)

Connection id:          22
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         8.0.32-26 GreatSQL, Release 26, Revision a68b3034c3d
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
UNIX socket:            /tmp/mysql.sock
Binary data as:         Hexadecimal
Uptime:                 59 min 16 sec

Threads: 4  Questions: 71  Slow queries: 2  Opens: 255  Flush tables: 3  Open tables: 172  Queries per second avg: 0.019
--------------

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> 

登录报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

解决办法:将sock文件建立软连接到mysql用到的sock文件
ln -s /data/GreatSQL/mysql.sock /tmp/mysql.sock

登录报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

解决办法:实现免密登录
/etc/my.cnf 添加 skip-grant-tables 
然后重启数据库:systemctl restart greatsql

修改密码

ALTER USER 'root'@'%' IDENTIFIED BY 'passwd';
FLUSH PRIVILEGES;

实现远程登录

update user set host = '%' where user = 'root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'  WITH GRANT OPTION;
FLUSH PRIVILEGES;