openstack 管理二十六 - rpm 方式部署 openstack [mariadb]

目的

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;
### CentOS 7上安装和配置单机版OpenStack #### 更新系统并启用OpenStack仓库 为了确保系统的稳定性和兼容性,在开始之前需要先更新操作系统中的软件包。运行以下命令完成系统升级: ```bash yum -y update ``` 接着,通过`yum-config-manager`工具启用OpenStack Queens版本的RPM仓库,并安装对应的CentOS发行版文件[^1]。 ```bash yum-config-manager --enable Openstack-queens yum install -y centos-release-openstack-queens ``` #### 配置国内YUM源 为了避免因国外镜像下载速度慢而导致的问题,可以切换到阿里云提供的国内YUM源。具体操作如下: ```bash wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo yum clean all ``` 这一步骤能够显著提升后续依赖库以及组件的下载效率[^3]。 #### 安装基础服务与初始化环境 按照官方文档指引逐步安装MariaDB、RabbitMQ等必要支持服务之后,继续设置Keystone身份认证模块以及其他核心组件如Nova计算服务、Neutron网络管理器和服务存储Cinder等等。这里不再赘述每项的具体实施细节,请参照相关指南逐一落实各项参数调整工作直至整个框架搭建完毕为止。 #### 创建虚拟机实例测试功能正常与否 当所有前期准备工作都已完成以后就可以尝试创建第一个VM验证整体流程是否通畅无阻塞点了。下面给出了一组典型指令用于快速构建一台小型Linux服务器作为演示用途: ```bash $ openstack flavor create --ram 512 --disk 1 --vcpus 1 m1.tiny $ openstack image create "cirros-0.3.5-x86_64-disk" \ --file cirros-0.3.5-x86_64-disk.img \ --disk-format qcow2 --container-format bare \ --public $ openstack keypair create mykey > ~/.ssh/mykey.pem && chmod 600 ~/.ssh/mykey.pem $ neutron net-create ext-net --shared --router:external=True $ neutron subnet-create ext-net 192.168.100.0/24 --name ext-subnet --allocation-pool start=192.168.100.10,end=192.168.100.250 --gateway 192.168.100.1 $ neutron router-create demo-router $ neutron router-gateway-set demo-router ext-net $ neutron net-create private-net $ neutron subnet-create private-net 10.0.0.0/24 --name private-subnet --gateway 10.0.0.1 $ neutron router-interface-add demo-router private-subnet $ openstack server create --flavor m1.tiny --image "cirros-0.3.5-x86_64-disk" --nic net-id=$(neutron net-list | grep private-net | awk '{print $2}') --security-group default --key-name mykey test-instance ``` 上述脚本涵盖了从规格定义至最终实例上线全过程所需的关键环节[^2]。 #### 解决常见问题——数据库连接数不足 如果遇到类似于“Too many connections”的错误提示,则表明当前MySQL/MariaDB允许的最大并发链接数目不足以满足实际需求。此时应当登录数据库管理系统内部修改全局变量max_connections值达到适当范围比如设定成5000即可解决问题;另外记得同步重启关联的服务进程使得更改生效同时密切监控日志记录确认异常现象已经消失不见踪影[^4]: ```bash set global max_connections=5000; systemctl restart openstack-cinder-api openstack-cinder-backup openstack-cinder-scheduler openstack-cinder-volume ``` --- 相关问题
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Terry_Tsang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值