容器运行常见数据库

一.涉及镜像压缩包

  • 均为amd架构
  • 版本:mysql:5.7.42、postgres:13.16、dm8:20250206_rev257733_x86_rh6_64、oceanbase-ce:v4.0、opengauss:5.0.2

通过网盘分享的文件:db.tgz
链接: https://pan.baidu.com/s/1EBbFPZj1FxCA4_GxjVunWg?pwd=563s 提取码: 563s

二.mysql-5.7.42

  • my.cnf文件(/data/mysql/my.cnf)
[mysqld]
port=3306
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/run/mysqld/mysqld.sock
secure-file-priv=/var/lib/mysql-files
user=mysql
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
slow_query_log_file = /var/lib/mysql/mysql-slow.log
log_bin = mysql-bin
slow_query_log_file = /var/lib/mysql/mysql-slow.log
server-id = 1
bind-address = 0.0.0.0
default_time_zone = '+08:00'
log_timestamps = SYSTEM
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
back_log = 300
max_connections = 5000
max_connect_errors = 1000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
binlog_format = mixed
expire_logs_days = 30
max_binlog_size =1G
slow_query_log = 1
long_query_time = 1
performance_schema = 0
explicit_defaults_for_timestamp
lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
interactive_timeout = 28800
wait_timeout = 28800

[mysqldump]
quick
max_allowed_packet = 100M

[client]
port = 3306
socket=/run/mysqld/mysqld.sock

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
  • 容器执行命令创建mysql容器
docker run --name mysql -p 20307:3306 --restart=always --privileged=true \
-e MYSQL_ROOT_PASSWORD="SLBmysql2025" \
-v /data/mysql/my.cnf:/etc/my.cnf \
-v /data/mysql/data:/var/lib/mysql \
-d registry.cn-chengdu.aliyuncs.com/su03/mysql:5.7.42

三.postgresql:13.16

  • 容器执行命令
docker run --name postgres13-16 --restart=always --privileged=true \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD="SLBpg2025" \
-p 25432:5432 \
-v /data/pg/data:/var/lib/postgresql/data \
-d registry.cn-chengdu.aliyuncs.com/su03/postgres:13.16
  • 运行后修改/data/pg/data/postgresql.conf
listen_addresses = '*'
port = 5432
max_connections = 2000
superuser_reserved_connections = 10
password_encryption = scram-sha-256
shared_buffers = 128MB          
dynamic_shared_memory_type = posix
wal_level = replica
max_wal_size = 4096MB    
min_wal_size = 80MB   
max_wal_senders = 10
wal_keep_size= 4096MB   
synchronous_standby_names = '*'
hot_standby = on
log_destination = 'stderr'
logging_collector = on
log_directory = 'log'
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
log_rotation_age = 1d
log_rotation_size = 0
log_line_prefix = '%m [%p] '
log_timezone = 'PRC'
log_statement = 'all'  
log_duration = on  
log_min_duration_sample = 30000ms
log_statement_sample_rate = 0.2
datestyle = 'iso, mdy'
timezone = 'PRC'
lc_messages = 'en_US.UTF-8'
lc_monetary = 'en_US.UTF-8'
lc_numeric = 'en_US.UTF-8'
lc_time = 'en_US.UTF-8'
default_text_search_config = 'pg_catalog.english'
archive_mode = on   
archive_command = 'gzip < %p > /var/lib/postgresql/data/pg_wal/%f.gz'         
shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.max = 10000
pg_stat_statements.track = all
  • 创建扩展
--连接到数据库后创建扩展
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;
SELECT * FROM pg_extension WHERE extname = 'pg_stat_statements';

四.dm V8

  • 容器执行命令
docker run -p 30236:5236 --restart=always --name=dm8 --privileged=true \
-e SYSDBA_PWD="SLBsysdba2025" \
-e LD_LIBRARY_PATH=/opt/dmdbms/bin \
-e PAGE_SIZE=16 -e EXTENT_SIZE=32 -e CASE_SENSITIVE=1 \
-e LOG_SIZE=1024 -e UNICODE_FLAG=1  \
-e INSTANCE_NAME=dm8 \
-v /data/dm/data:/opt/dmdbms/data \
-d registry.cn-chengdu.aliyuncs.com/su03/dm8:20250206_rev257733_x86_rh6_64

五.oceanbase V4.0

  • 容器执行命令
docker run -p 22881:2881 -m 8G --name=obce-4.0 --restart=always --privileged=true \
-e MODE=NORMAL -e OB_DATA_DIR=/data \
-itd registry.cn-chengdu.aliyuncs.com/su03/oceanbase-ce:v4.0
  • 进入容器启动server
docker exec -it obce-4.0 bash

[admin@0fd82061e752 ~]$ obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+--------+---------------------------------+-----------------+
| Name   | Configuration Path              | Status (Cached) |
+--------+---------------------------------+-----------------+
| obdemo | /home/admin/.obd/cluster/obdemo | deployed        |
+--------+---------------------------------+-----------------+
[admin@0fd82061e752 ~]$ obd cluster start obdemo 
Get local repositories ok
Search plugins ok
Open ssh connection ok
Load cluster param plugin ok
Check before start observer ok
[WARN] (127.0.0.1) clog and data use the same disk (/)

Check before start obproxy ok
Start observer ok
observer program health check ok
Connect to observer ok
Initialize cluster ok
Start obproxy ok
obproxy program health check ok
Connect to obproxy ok
Initialize cluster ok
Wait for observer init ok
+---------------------------------------------+
|                   observer                  |
+-----------+---------+------+-------+--------+
| ip        | version | port | zone  | status |
+-----------+---------+------+-------+--------+
| 127.0.0.1 | 4.0.0.0 | 2881 | zone1 | ACTIVE |
+-----------+---------+------+-------+--------+
obclient -h127.0.0.1 -P2881 -uroot -prootPWD123 -Doceanbase

+---------------------------------------------+
|                   obproxy                   |
+-----------+------+-----------------+--------+
| ip        | port | prometheus_port | status |
+-----------+------+-----------------+--------+
| 127.0.0.1 | 2883 | 2884            | active |
+-----------+------+-----------------+--------+
obclient -h127.0.0.1 -P2883 -uroot -prootPWD123 -Doceanbase
obdemo running
  • 根据输出信息验证联通性
obclient -h127.0.0.1 -P2881 -uroot -prootPWD123 -Doceanbase
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221487617
Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov  1 2022 14:56:31)

Copyright (c) 2000, 2018, OB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
obclient [oceanbase]>
obclient [oceanbase]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| LBACSYS            |
| mysql              |
| oceanbase          |
| ORAAUDITOR         |
| SYS                |
| test               |
+--------------------+
7 rows in set (0.008 sec)

六.opengauss 5.0.2

  • 容器运行命令
docker run --name=opengauss-5.0.2 --privileged=true --restart=always \
-e GS_PASSWORD=SLBopengauss@2025 \
-e LD_LIBRARY_PATH="/usr/local/opengauss/lib:$LD_LIBRARY_PATH" \
-v /data/opengauss/data:/var/lib/opengauss  \
-u root -p 15432:5432 \
-d registry.cn-chengdu.aliyuncs.com/su03/opengauss:5.0.2
  • 进入容器创建软链接,验证连通性
[root@master01 opengauss]# docker exec -it opengauss-5.0.2 bash
root@bb7dece59a51:/# ln -s /usr/local/opengauss/bin/gsql /usr/local/bin/gsql
root@bb7dece59a51:/# gsql -dpostgres -Ugaussdb -W'SLBopengauss@2025' -h127.0.0.1 -p5432
gsql ((openGauss 5.0.2 build 48a25b11) compiled at 2024-05-14 10:26:01 commit 0 last mr  )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=> \l
                         List of databases
   Name    | Owner | Encoding | Collate | Ctype | Access privileges 
-----------+-------+----------+---------+-------+-------------------
 omm       | omm   | UTF8     | C       | C     | 
 postgres  | omm   | UTF8     | C       | C     | 
 template0 | omm   | UTF8     | C       | C     | =c/omm           +
           |       |          |         |       | omm=CTc/omm
 template1 | omm   | UTF8     | C       | C     | =c/omm           +
           |       |          |         |       | omm=CTc/omm
(4 rows)
  • 在/data/opengauss/data/data/postgresql.conf中修改配置文件所需参数即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

树下一少年

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

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

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

打赏作者

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

抵扣说明:

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

余额充值