目的
1. 配置 openstack 可用的 mariadb
2. mariadb 用于存储 openstack 中的所有信息
3. 暂不以高可用为目的
软件源建议
新增 /etc/yum.repos.d/mariadb.repo ( gaiera + mariadb 专用 rpm repo)
[mariadb]
name=mariadb
baseurl=http://mirror.centos.org/centos/7.9.2009/cloud/x86_64/openstack-queens
enabled=1
gpgcheck=0
安装
yum install -y mariadb.x86_64 mariadb-server.x86_64 mariadb-server-galera galera mariadb-galera-common mariadb-server-galera
配置
必须要设定默认字符集为 utf8, 否则无法自动创建表
注 因测试环境, 暂无对 innodb 进行优化
/etc/my.cnf.d/mariadb-server.cnf
[mysql]
default_character_set=utf8
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
user = mysql
port = 3306
basedir = /usr
tmpdir = /tmp
skip-external-locking
innodb-log-file-size = 2048M
innodb_buffer_pool_size = 4G
innodb_file_per_table=1
bind-address = 0.0.0.0
skip-name-resolve
key_buffer_size = 384M
max_allowed_packet = 128M
thread_stack = 192K
thread_cache_size = 32
myisam-recover-options = BACKUP
query_cache_limit = 1M
query_cache_size = 64M
max-connections = 6000
open-files-limit = 6000
character_set_server = utf8
table_open_cache = 512
sort_buffer_size = 32M
read_buffer_size = 32M
read_rnd_buffer_size = 64M
myisam_sort_buffer_size = 64M
default-storage-engine = InnoDB
innodb_buffer_pool_size = 32768M
innodb_log_buffer_size = 256M
innodb_purge_threads = 1
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
修改 /usr/lib/systemd/system/mariadb.service
解决 number of open files 问题
[Service]
Type=notify
User=mysql
Group=mysql
LimitNOFILE=infinity <- 增加
额外工作
如果需要创建集群 (双主服务器)
则修改 /etc/my.cnf.d/galera.cnf
[mysqld]
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
skip-name-resolve
wsrep_on=1
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_provider_options="gcache.size=1G"
wsrep_cluster_name="my_yun_cluster" <-- 集群名称 其他服务器都必须配置相同集群名称
wsrep_cluster_address="gcomm://" <-- 第一台启动的服务器这里必须设定为空,
### 第一台启动成功, 3306 端口启动后,再启动第二台, 第二台写入第一台服务器地址
### 第二台写法 wsrep_cluster_address="gcomm://10.1.1.1" <- 第一台 IP 地址就可以
wsrep_slave_threads=1
wsrep_certify_nonPK=1
wsrep_max_ws_rows=131072
wsrep_max_ws_size=1073741824
wsrep_debug=0
wsrep_convert_LOCK_to_trx=0
wsrep_retry_autocommit=1
wsrep_auto_increment_control=1
wsrep_drupal_282555_workaround=0
wsrep_causal_reads=0
wsrep_notify_cmd=
wsrep_sst_method=rsync
wsrep_sst_auth=vip_user:vip_password_salt <- 用户名/密码 (集群认证用)
验证文件是否存在
不存在则安装软件 galera-25.3.16-3.el7.x86_64
# ls -lh /usr/lib64/galera/libgalera_smm.so
-rwxr-xr-x 1 root root 2.4M Jul 11 2017 /usr/lib64/galera/libgalera_smm.so
启动
systemctl daemon-reload
systemctl restart maraidb (el7)
验证
mysql 命令能够直接登入 mysql> 终端则可
验证集群
第一台成功后,会看到启动的服务器地址
MariaDB [(none)]> show status like 'wsrep_incoming_addresses';
+--------------------------+-------------------+
| Variable_name | Value |
+--------------------------+-------------------+
| wsrep_incoming_addresses | 10.189.20.37:3306 |
+--------------------------+-------------------+
集群同步成功后,会看到集群中所有服务器地址
MariaDB [(none)]> show status like 'wsrep_incoming_addresses';
+--------------------------+-------------------------------------+
| Variable_name | Value |
+--------------------------+-------------------------------------+
| wsrep_incoming_addresses | 10.189.20.37:3306,10.189.20.38:3306 |
+--------------------------+-------------------------------------+
salve 服务器详细启动日志,用于参考
2025-02-07 9:56:10 139979487631552 [Note] WSREP: CRC-32C: using hardware acceleration.
2025-02-07 9:56:10 139979487631552 [Note] WSREP: Found saved state: 00000000-0000-0000-0000-000000000000:-1
2025-02-07 9:56:10 139979487631552 [Note] WSREP: Passing config to GCS: base_dir = /var/lib/mysql/; base_host = 10.189.20.38; base_port = 4567; cert.log_conflicts = no; debug = no; evs.auto_evict = 0; evs.delay_margin = PT1S; evs.delayed_keep_period = PT30S; evs.inactive_check_period = PT0.5S; evs.inactive_timeout = PT15S; evs.join_retrans_period = PT1S; evs.max_install_timeouts = 3; evs.send_window = 4; evs.stats_report_period = PT1M; evs.suspect_timeout = PT5S; evs.user_send_window = 2; evs.view_forget_timeout = PT24H; gcache.dir = /var/lib/mysql/; gcache.keep_pages_size = 0; gcache.mem_size = 0; gcache.name = /var/lib/mysql//galera.cache; gcache.page_size = 128M; gcache.size = 1G; gcomm.thread_prio = ; gcs.fc_debug = 0; gcs.fc_factor = 1.0; gcs.fc_limit = 16; gcs.fc_master_slave = no; gcs.max_packet_size = 64500; gcs.max_throttle = 0.25; gcs.recv_q_hard_limit = 9223372036854775807; gcs.recv_q_soft_limit = 0.25; gcs.sync_donor = no; gmcast.segment = 0; gmcast.version = 0; pc.announce_timeout = PT3S; pc.checksum = false; pc.ignore_quorum = false; p
2025-02-07 9:56:10 139979308107520 [Note] WSREP: Service thread queue flushed.
2025-02-07 9:56:10 139979487631552 [Note] WSREP: Assign initial position for certification: -1, protocol version: -1
2025-02-07 9:56:10 139979487631552 [Note] WSREP: wsrep_sst_grab()
2025-02-07 9:56:10 139979487631552 [Note] WSREP: Start replication
2025-02-07 9:56:10 139979487631552 [Note] WSREP: Setting initial position to 00000000-0000-0000-0000-000000000000:-1
2025-02-07 9:56:10 139979487631552 [Note] WSREP: protonet asio version 0
2025-02-07 9:56:10 139979487631552 [Note] WSREP: Using CRC-32C for message checksums.
2025-02-07 9:56:10 139979487631552 [Note] WSREP: backend: asio
2025-02-07 9:56:10 139979487631552 [Note] WSREP: gcomm thread scheduling priority set to other:0
2025-02-07 9:56:10 139979487631552 [Warning] WSREP: access file(/var/lib/mysql//gvwstate.dat) failed(No such file or directory)
2025-02-07 9:56:10 139979487631552 [Note] WSREP: restore pc from disk failed
2025-02-07 9:56:10 139979487631552 [Note] WSREP: GMCast version 0
2025-02-07 9:56:10 139979487631552 [Note] WSREP: (b3e64f42, 'tcp://0.0.0.0:4567') listening at tcp://0.0.0.0:4567
2025-02-07 9:56:10 139979487631552 [Note] WSREP: (b3e64f42, 'tcp://0.0.0.0:4567') multicast: , ttl: 1
2025-02-07 9:56:10 139979487631552 [Note] WSREP: EVS version 0
2025-02-07 9:56:10 139979487631552 [Note] WSREP: gcomm: connecting to group 'my_yun_cluster', peer '10.189.20.37:'
2025-02-07 9:56:10 139979487631552 [Note] WSREP: (b3e64f42, 'tcp://0.0.0.0:4567') turning message relay requesting on, nonlive peers:
2025-02-07 9:56:10 139979487631552 [Note] WSREP: declaring b096007b at tcp://10.189.20.37:4567 stable
2025-02-07 9:56:10 139979487631552 [Note] WSREP: Node b096007b state prim
2025-02-07 9:56:10 139979487631552 [Note] WSREP: view(view_id(PRIM,b096007b,2) memb {
b096007b,0
b3e64f42,0
} joined {
} left {
} partitioned {
})
2025-02-07 9:56:10 139979487631552 [Note] WSREP: save pc into disk
2025-02-07 9:56:11 139979487631552 [Note] WSREP: gcomm: connected
2025-02-07 9:56:11 139979487631552 [Note] WSREP: Changing maximum packet size to 64500, resulting msg size: 32636
2025-02-07 9:56:11 139979487631552 [Note] WSREP: Shifting CLOSED -> OPEN (TO: 0)
2025-02-07 9:56:11 139979487631552 [Note] WSREP: Opened channel 'my_yun_cluster'
2025-02-07 9:56:11 139978117981952 [Note] WSREP: New COMPONENT: primary = yes, bootstrap = no, my_idx = 1, memb_num = 2
2025-02-07 9:56:11 139978117981952 [Note] WSREP: STATE EXCHANGE: Waiting for state UUID.
2025-02-07 9:56:11 139979487631552 [Note] WSREP: Waiting for SST to complete.
2025-02-07 9:56:11 139978117981952 [Note] WSREP: STATE EXCHANGE: sent state msg: b4332291-e4f6-11ef-9878-b7c47a7119e6
2025-02-07 9:56:11 139978117981952 [Note] WSREP: STATE EXCHANGE: got state msg: b4332291-e4f6-11ef-9878-b7c47a7119e6 from 0 (ns-yun-020037.vclound.com)
2025-02-07 9:56:11 139978117981952 [Note] WSREP: STATE EXCHANGE: got state msg: b4332291-e4f6-11ef-9878-b7c47a7119e6 from 1 (ns-yun-020038.vclound.com)
2025-02-07 9:56:11 139978117981952 [Note] WSREP: Quorum results:
version = 4,
component = PRIMARY,
conf_id = 1,
members = 1/2 (joined/total),
act_id = 0,
last_appl. = -1,
protocols = 0/7/3 (gcs/repl/appl),
group UUID = b0964307-e4f5-11ef-9530-d3857360fc8b
2025-02-07 9:56:11 139978117981952 [Note] WSREP: Flow-control interval: [23, 23]
2025-02-07 9:56:11 139978117981952 [Note] WSREP: Shifting OPEN -> PRIMARY (TO: 0)
2025-02-07 9:56:11 139979299714816 [Note] WSREP: State transfer required:
Group state: b0964307-e4f5-11ef-9530-d3857360fc8b:0
Local state: 00000000-0000-0000-0000-000000000000:-1
2025-02-07 9:56:11 139979299714816 [Note] WSREP: New cluster view: global state: b0964307-e4f5-11ef-9530-d3857360fc8b:0, view# 2: Primary, number of nodes: 2, my index: 1, protocol version 3
2025-02-07 9:56:11 139979299714816 [Warning] WSREP: Gap in state sequence. Need state transfer.
2025-02-07 9:56:11 139978109589248 [Note] WSREP: Running: 'wsrep_sst_rsync --role 'joiner' --address '10.189.20.38' --datadir '/var/lib/mysql/' --parent '24359' '' '
2025-02-07 9:56:11 139979299714816 [Note] WSREP: Prepared SST request: rsync|10.189.20.38:4444/rsync_sst
2025-02-07 9:56:11 139979299714816 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification.
2025-02-07 9:56:11 139979299714816 [Note] WSREP: REPL Protocols: 7 (3, 2)
2025-02-07 9:56:11 139979308107520 [Note] WSREP: Service thread queue flushed.
2025-02-07 9:56:11 139979299714816 [Note] WSREP: Assign initial position for certification: 0, protocol version: 3
2025-02-07 9:56:11 139979308107520 [Note] WSREP: Service thread queue flushed.
2025-02-07 9:56:11 139979299714816 [Warning] WSREP: Failed to prepare for incremental state transfer: Local state UUID (00000000-0000-0000-0000-000000000000) does not match group state UUID (b0964307-e4f5-11ef-9530-d3857360fc8b): 1 (Operation not permitted)
at galera/src/replicator_str.cpp:prepare_for_IST():482. IST will be unavailable.
2025-02-07 9:56:11 139978117981952 [Note] WSREP: Member 1.0 (ns-yun-020038.vclound.com) requested state transfer from '*any*'. Selected 0.0 (ns-yun-020037.vclound.com)(SYNCED) as donor.
2025-02-07 9:56:11 139978117981952 [Note] WSREP: Shifting PRIMARY -> JOINER (TO: 0)
2025-02-07 9:56:11 139979299714816 [Note] WSREP: Requesting state transfer: success, donor: 0
2025-02-07 9:56:13 139978126374656 [Note] WSREP: (b3e64f42, 'tcp://0.0.0.0:4567') turning message relay requesting off
2025-02-07 9:56:49 139978117981952 [Note] WSREP: 0.0 (ns-yun-020037.vclound.com): State transfer to 1.0 (ns-yun-020038.vclound.com) complete.
2025-02-07 9:56:49 139978117981952 [Note] WSREP: Member 0.0 (ns-yun-020037.vclound.com) synced with group.
WSREP_SST: [INFO] Joiner cleanup. rsync PID: 24428 (20250207 09:56:49.691)
WSREP_SST: [INFO] Joiner cleanup done. (20250207 09:56:50.196)
2025-02-07 9:56:50 139979487631552 [Note] WSREP: SST complete, seqno: 0
2025-02-07 9:56:50 139979487631552 [Note] CONNECT: Version 1.04.0008 August 10, 2016
2025-02-07 9:56:50 139979487631552 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2025-02-07 9:56:50 139979487631552 [Note] InnoDB: The InnoDB memory heap is disabled
2025-02-07 9:56:50 139979487631552 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2025-02-07 9:56:50 139979487631552 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2025-02-07 9:56:50 139979487631552 [Note] InnoDB: Compressed tables use zlib 1.2.7
2025-02-07 9:56:50 139979487631552 [Note] InnoDB: Using Linux native AIO
2025-02-07 9:56:50 139979487631552 [Note] InnoDB: Using SSE crc32 instructions
2025-02-07 9:56:50 139979487631552 [Note] InnoDB: Initializing buffer pool, size = 32.0G
2025-02-07 9:56:51 139979487631552 [Note] InnoDB: Completed initialization of buffer pool
2025-02-07 9:56:51 139979487631552 [Note] InnoDB: Highest supported file format is Barracuda.
2025-02-07 9:56:51 139979487631552 [Note] InnoDB: The log sequence numbers 1622838 and 1622838 in ibdata files do not match the log sequence number 1623012 in the ib_logfiles!
2025-02-07 9:56:51 139979487631552 [Note] InnoDB: Database was not shutdown normally!
2025-02-07 9:56:51 139979487631552 [Note] InnoDB: Starting crash recovery.
2025-02-07 9:56:51 139979487631552 [Note] InnoDB: Reading tablespace information from the .ibd files...
2025-02-07 9:56:51 139979487631552 [Note] InnoDB: Restoring possible half-written data pages
2025-02-07 9:56:51 139979487631552 [Note] InnoDB: from the doublewrite buffer...
2025-02-07 9:56:52 139979487631552 [Note] InnoDB: 128 rollback segment(s) are active.
2025-02-07 9:56:52 139979487631552 [Note] InnoDB: Waiting for purge to start
2025-02-07 9:56:52 139979487631552 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.6.34-79.1 started; log sequence number 1623012
2025-02-07 9:56:52 139939881146112 [Note] InnoDB: Dumping buffer pool(s) not yet started
2025-02-07 9:56:52 139979487631552 [Note] Plugin 'FEEDBACK' is disabled.
2025-02-07 9:56:52 139979487631552 [Note] Server socket created on IP: '0.0.0.0'.
2025-02-07 9:56:52 139979487631552 [Warning] 'user' entry 'root@ns-yun-020037.vclound.com' ignored in --skip-name-resolve mode.
2025-02-07 9:56:52 139979487631552 [Warning] 'user' entry '@ns-yun-020037.vclound.com' ignored in --skip-name-resolve mode.
2025-02-07 9:56:52 139979487631552 [Warning] 'proxies_priv' entry '@% root@ns-yun-020037.vclound.com' ignored in --skip-name-resolve mode.
2025-02-07 9:56:52 139979487631552 [Note] WSREP: Signalling provider to continue.
2025-02-07 9:56:52 139979487631552 [Note] WSREP: SST received: b0964307-e4f5-11ef-9530-d3857360fc8b:0
2025-02-07 9:56:52 139978117981952 [Note] WSREP: 1.0 (ns-yun-020038.vclound.com): State transfer from 0.0 (ns-yun-020037.vclound.com) complete.
2025-02-07 9:56:52 139978117981952 [Note] WSREP: Shifting JOINER -> JOINED (TO: 0)
2025-02-07 9:56:52 139978117981952 [Note] WSREP: Member 1.0 (ns-yun-020038.vclound.com) synced with group.
2025-02-07 9:56:52 139978117981952 [Note] WSREP: Shifting JOINED -> SYNCED (TO: 0)
2025-02-07 9:56:52 139979299714816 [Note] WSREP: Synchronized with group, ready for connections
2025-02-07 9:56:52 139979299714816 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification.
2025-02-07 9:56:52 139979487631552 [Note] /usr/libexec/mysqld: ready for connections.
Version: '10.1.20-MariaDB' socket: '/var/lib/mysql/mysql.sock' port: 3306 MariaDB Server
创建用户
创建 keystone 用户
create database keystone character set utf8;
GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'%' identified by 'test123';
GRANT ALL PRIVILEGES ON keystone.* TO 'keystone'@'localhost' identified by 'test123';
flush privileges;
创建 glance 用户
create database glance character set utf8;
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'%' identified by 'glance';
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'localhost' identified by 'glance';
GRANT ALL PRIVILEGES ON glance.* TO 'glance'@'127.0.0.1' identified by 'glance';
flush privileges;
创建 cinder 用户
grant all on cinder.* to 'cinder'@'localhost' identified by 'cinder';
grant all on cinder.* to 'cinder'@'240.10.130.25' identified by 'cinder';
flush privileges;
create databae cinder character set utf8;
创建 neutron 用户
create database neutron_ml2 character set utf8;
GRANT ALL PRIVILEGES ON neutron_ml2.* TO 'neutron'@'%' identified by 'openstack';
GRANT ALL PRIVILEGES ON neutron_ml2.* TO 'neutron'@'localhost' identified by 'openstack';
GRANT ALL PRIVILEGES ON neutron_ml2.* TO 'neutron'@'127.0.0.1' identified by 'openstack';
flush privileges;
创建 nova 用户
CREATE DATABASE nova character set utf8;
GRANT ALL ON nova.* TO 'nova'@'%' IDENTIFIED BY 'openstack';
GRANT ALL ON nova.* TO 'nova'@'localhost' IDENTIFIED BY 'openstack';
FLUSH PRIVILEGES;