注册
达梦V8数据库on openeuler系统 单机环境安装
技术分享/ 文章详情 /

达梦V8数据库on openeuler系统 单机环境安装

Mañjuśrī 2025/01/03 444 1 0

1 安装环境

最近正在学习达梦数据库,正好用户有需求需要搭建一套信创测试环境,对此做了一下记录。

1.1系统环境

[root@ecs-00348852-001 ~]# cat /etc/os-release
NAME="openEuler"
VERSION="22.03 (LTS-SP4)"
ID="openEuler"
VERSION_ID="22.03"
PRETTY_NAME="openEuler 22.03 (LTS-SP4)"
ANSI_COLOR="0;31"
[root@ecs-00348852-001 ~]#

1.2CPU环境

[root@ecs-00348852-001 ~]# lscpu
Architecture:           aarch64
  CPU op-mode(s):       64-bit
  Byte Order:           Little Endian
CPU(s):                 16
  On-line CPU(s) list:  0-15
Vendor ID:              HiSilicon
  BIOS Vendor ID:       QEMU
  Model name:           Kunpeng-920
    BIOS Model name:    virt-6.2
    Model:              0
    Thread(s) per core: 1
    Core(s) per socket: 8
    Socket(s):          2
    Stepping:           0x1
    Frequency boost:    disabled
    CPU max MHz:        2400.0000
    CPU min MHz:        2400.0000
    BogoMIPS:           200.00
    Flags:              fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma dcpop asimddp asimdfhm
Caches (sum of all):
  L1d:                  1 MiB (16 instances)
  L1i:                  1 MiB (16 instances)
  L2:                   8 MiB (16 instances)
  L3:                   64 MiB (2 instances)
NUMA:
  NUMA node(s):         2
  NUMA node0 CPU(s):    0-7
  NUMA node1 CPU(s):    8-15
Vulnerabilities:
  Gather data sampling: Not affected
  Itlb multihit:        Not affected
  L1tf:                 Not affected
  Mds:                  Not affected
  Meltdown:             Not affected
  Mmio stale data:      Not affected
  Retbleed:             Not affected
  Spec rstack overflow: Not affected
  Spec store bypass:    Vulnerable
  Spectre v1:           Mitigation; __user pointer sanitization
  Spectre v2:           Not affected
  Srbds:                Not affected
  Tsx async abort:      Not affected
[root@ecs-00348852-001 ~]#

系统版本信息

Linux ecs-00348852-001 5.10.0-221.0.0.120.oe2203sp4.aarch64 #1 SMP Wed Jul 31 19:29:47 CST 2024 aarch64 aarch64 aarch64 GNU/Linux

2 磁盘环境与分区创建

2.1 利用fdisk创建物理分区

[root@ecs-00348852-001 ~]# fdisk -l
Disk /dev/sdb: 500 GiB, 536870912000 bytes, 1048576000 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: F2DE55D7-D10B-41CE-BB22-55E954C5A436
Device       Start      End  Sectors Size Type
/dev/sda1     2048  2099199  2097152   1G EFI System
/dev/sda2  2099200 83886046 81786847  39G Linux filesystem

[root@coremailDB ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x028384e3.
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-1048575999, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1048575999, default 1048575999):
Created a new partition 1 of type 'Linux' and of size 500 GiB.
Command (m for help): p

Disk /dev/sdb: 500 GiB, 536870912000 bytes, 1048576000 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x028384e3

Device     Boot Start        End    Sectors  Size Id Type
/dev/sdb1        2048 1048575999 1048573952  500G 83 Linux

Command (m for help): t
Selected partition 1
Hex code or alias (type L to list all): l

00 Empty            24 NEC DOS          81 Minix / old Lin  bf Solaris
01 FAT12            27 Hidden NTFS Win  82 Linux swap / So  c1 DRDOS/sec (FAT-
02 XENIX root       39 Plan 9           83 Linux            c4 DRDOS/sec (FAT-
03 XENIX usr        3c PartitionMagic   84 OS/2 hidden or   c6 DRDOS/sec (FAT-
04 FAT16 <32M       40 Venix 80286      85 Linux extended   c7 Syrinx
05 Extended         41 PPC PReP Boot    86 NTFS volume set  da Non-FS data
06 FAT16            42 SFS              87 NTFS volume set  db CP/M / CTOS / .
07 HPFS/NTFS/exFAT  4d QNX4.x           88 Linux plaintext  de Dell Utility
08 AIX              4e QNX4.x 2nd part  8e Linux LVM        df BootIt
09 AIX bootable     4f QNX4.x 3rd part  93 Amoeba           e1 DOS access
0a OS/2 Boot Manag  50 OnTrack DM       94 Amoeba BBT       e3 DOS R/O
0b W95 FAT32        51 OnTrack DM6 Aux  9f BSD/OS           e4 SpeedStor
0c W95 FAT32 (LBA)  52 CP/M             a0 IBM Thinkpad hi  ea Linux extended
0e W95 FAT16 (LBA)  53 OnTrack DM6 Aux  a5 FreeBSD          eb BeOS fs
0f W95 Ext'd (LBA)  54 OnTrackDM6       a6 OpenBSD          ee GPT
10 OPUS             55 EZ-Drive         a7 NeXTSTEP         ef EFI (FAT-12/16/
11 Hidden FAT12     56 Golden Bow       a8 Darwin UFS       f0 Linux/PA-RISC b
12 Compaq diagnost  5c Priam Edisk      a9 NetBSD           f1 SpeedStor
14 Hidden FAT16 <3  61 SpeedStor        ab Darwin boot      f4 SpeedStor
16 Hidden FAT16     63 GNU HURD or Sys  af HFS / HFS+       f2 DOS secondary
17 Hidden HPFS/NTF  64 Novell Netware   b7 BSDI fs          fb VMware VMFS
18 AST SmartSleep   65 Novell Netware   b8 BSDI swap        fc VMware VMKCORE
1b Hidden W95 FAT3  70 DiskSecure Mult  bb Boot Wizard hid  fd Linux raid auto
1c Hidden W95 FAT3  75 PC/IX            bc Acronis FAT32 L  fe LANstep
1e Hidden W95 FAT1  80 Old Minix        be Solaris boot     ff BBT

Aliases:
   linux          - 83
   swap           - 82
   extended       - 05
   uefi           - EF
   raid           - FD
   lvm            - 8E
   linuxex        - 85
Hex code or alias (type L to list all): 8e
Changed type of partition 'Linux' to 'Linux LVM'.
[root@coremailDB ~]# fdisk -l
Disk /dev/sdb: 500 GiB, 536870912000 bytes, 1048576000 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x028384e3
Device     Boot Start        End    Sectors  Size Id Type
/dev/sdb1        2048 1048575999 1048573952  500G 8e Linux LVM
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: F2DE55D7-D10B-41CE-BB22-55E954C5A436
Device       Start      End  Sectors Size Type
/dev/sda1     2048  2099199  2097152   1G EFI System
/dev/sda2  2099200 83886046 81786847  39G Linux filesystem
[root@coremailDB ~]#

2.2创建LVM分区

[root@coremailDB ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
[root@coremailDB ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               dbvg
  PV Size               <500.00 GiB / not usable 3.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              127999
  Free PE               127999
  Allocated PE          0
  PV UUID               dELDxl-pAXc-8Mqy-9hUy-GcvC-z25M-181Bci

2.3创建卷组名称为dbvg

[root@coremailDB ~]# vgcreate  dbvg /dev/sdb1
  Volume group "dbvg" successfully created
[root@coremailDB ~]# vgdisplay
  --- Volume group ---
  VG Name               dbvg
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <500.00 GiB
  PE Size               4.00 MiB
  Total PE              127999
  Alloc PE / Size       0 / 0
  Free  PE / Size       127999 / <500.00 GiB
  VG UUID               zftlHh-69xq-5bW4-O3Y4-iJG1-EdMV-N5oDg3

2.4创建逻辑卷

[root@coremailDB ~]# lvcreate -l 100%FREE -n lvdb dbvg
  Logical volume "lvdb" created.
[root@coremailDB ~]#
[root@coremailDB ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/dbvg/lvdb
  LV Name                lvdb
  VG Name                dbvg
  LV UUID                ReMo9U-cgA9-PxoY-0MGi-w5YK-hArI-r4OGJL
  LV Write Access        read/write
  LV Creation host, time CoremailDB, 2024-10-27 16:43:34 +0800
  LV Status              available
  # open                 0
  LV Size                <500.00 GiB
  Current LE             127999
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

2.5格式化磁盘

[root@coremailDB ~]# mkfs.xfs /dev/dbvg/lvdb
meta-data=/dev/dbvg/lvdb         isize=512    agcount=4, agsize=32767744 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=0
data     =                       bsize=4096   blocks=131070976, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=63999, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
Discarding blocks...Done.

2.6挂载分区

挂载创建的逻辑卷分区,挂载后的分区为497GB
[root@coremailDB ~]# mount /dev/dbvg/lvdb  /opt/
[root@coremailDB ~]# cd /opt/
[root@coremailDB opt]# ls
[root@coremailDB opt]# pwd
/opt
[root@coremailDB opt]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               4.0M     0  4.0M   0% /dev
tmpfs                   32G     0   32G   0% /dev/shm
tmpfs                   13G  944K   13G   1% /run
tmpfs                  4.0M     0  4.0M   0% /sys/fs/cgroup
/dev/sda2               39G  2.0G   35G   6% /
tmpfs                   32G     0   32G   0% /tmp
/dev/sda1             1022M  6.5M 1016M   1% /boot/efi
/dev/mapper/dbvg-lvdb  500G  3.6G  497G   1% /opt

2.7创建数据库安装路径

创建挂载路径
[root@CoremailDB /]# mkdir /dmsoft
查看磁盘分区的UUID
[root@CoremailDB /]# blkid
/dev/sr0: BLOCK_SIZE="2048" UUID="2024-10-25-12-03-06-00" LABEL="config-2" TYPE="iso9660"
/dev/sda2: UUID="9ff912dc-3511-416a-9271-56329baa9f73" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="550dc1a2-64cc-4606-82b5-abbccfcde96a"
/dev/sda1: UUID="B142-14B5" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="f03e5521-48ed-49c7-adec-602a02f25b3f"
/dev/sdb1: UUID="dELDxl-pAXc-8Mqy-9hUy-GcvC-z25M-181Bci" TYPE="LVM2_member" PARTUUID="028384e3-01"
/dev/mapper/dbvg-lvdb: UUID="c9131d8c-1aa5-4bf9-a8b0-6faa3dadab30" BLOCK_SIZE="512" TYPE="xfs"
[root@CoremailDB /]#
编辑挂载路径
[root@CoremailDB /]# cat /etc/fstab
# /etc/fstab
# Created by anaconda on Fri Aug  9 03:20:59 2024
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=9ff912dc-3511-416a-9271-56329baa9f73 /                       ext4    defaults        1 1
UUID=B142-14B5          /boot/efi               vfat    umask=0077,shortname=winnt 0 2
UUID=c9131d8c-1aa5-4bf9-a8b0-6faa3dadab30 /dmsoft xfs defaults 1 1

3.数据库安装前准备

3.1数据库初始化参数确认

页大小	32	32
簇大小	32	32
字符集	0(GB18030),1(UTF-8)	1(UTF-8)
大小写是否敏感	Y(敏感)/N(不敏感)	N(不敏感)
VARCHAR 类型是否以字符为单位	Y(是)/N(否)	
注意:在生产环境中,字符集,大小写是否敏感,VARCHAR 类型是否以字符为单位,这三个参数依据用户实际需求进行指定

3.2硬件检查

3.2.1磁盘空间检查

使用 df -h 检查磁盘空间是否符合要求。
下面按照实际 300-400GB 数据量来划分,实际提供挂载容量需要根据数据量和磁盘划分
/dmsoft  400G
/dmlog  200G
/dmdata 500G
/dmarch 300G
/dmbak  500G

3.2.2磁盘性能检查

模拟数据库读写小数据来测试硬盘的 IO,使用 dd 命令测试系统盘如下:

dd if=/dev/dbvg/lvdb  of=/opt/test  bs=32k count=10k oflag=dsync
[root@coremailDB /]# dd if=/dev/dbvg/lvdb  of=/dmsoft  bs=32k count=10k oflag=dsync
10240+0 records in
10240+0 records out
335544320 bytes (336 MB, 320 MiB) copied, 24.0971 s, 13.9 MB/s
测试速度要求大于 50M/S。
说明:oflag=dsync 单进程测试,结果仅供参考

直接写

dd if=/dev/zero of=/dmsoft/test.dbf bs=32k count=20k oflag=dsync

直接读

dd of=/dmsoft/test.dbf if=/dmsoft.dbf bs=32k count=20k oflag=dsync

dd 只能测试顺序读写,它没有考虑并发和随机 IO 情况,所以测试结果可能不太准确,如果想更加准确的测试 IO 读写情况可以使用 fio 进行测试。测试命令如下:

fio -fimename=/dev/dbvg/lvdb -direct=1 -rw=randwrite -iodepth=1 -ioengine=psync -bs=32k -size=10G -numjobs=1 -runtime=60 -group_reporting -name=/dmsoft/test.dbf

3.2.3磁盘调度算法检查

[root@coremailDB /]# cat /sys/block/sdb/queue/scheduler
[none] mq-deadline kyber bfq

sda 为实际磁盘名称。
注意上图选中的调度算法是[cfq],需要修改调度算法为 deadline
永久的更改 I/O 调度方法:
修改内核引导参数,增加 elevator=deadline

grubby --update-kernel=ALL --args="elevator=deadline"
[root@coremailDB /]# cat /sys/block/sdb/queue/scheduler
[none] mq-deadline kyber bfq

3.2.4设置系统时间

[root@CoremailDB ~]# timedatectl
               Local time: Sun 2024-10-27 17:44:27 CST
           Universal time: Sun 2024-10-27 09:44:27 UTC
                 RTC time: Sun 2024-10-27 09:44:27
                Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
[root@CoremailDB ~]# timedatectl set-timezone "Asia/Shanghai" //设置时间同步

3.2.5设置系统名称

[root@ecs-00348852-001 ~]# hostnamectl
 Static hostname: ecs-00348852-001
       Icon name: computer-vm
         Chassis: vm
      Machine ID: 382c0354023c4d14a247cb082bcd52a0
         Boot ID: 88c8d065bb174f0086f82426c9590dfe
  Virtualization: kvm
Operating System: openEuler 22.03 (LTS-SP4)
          Kernel: Linux 5.10.0-221.0.0.120.oe2203sp4.aarch64
    Architecture: arm64
 Hardware Vendor: QEMU
  Hardware Model: KVM Virtual Machine
[root@ecs-00348852-001 ~]#
[root@coremailDB ~]# hostnamectl  hostname CoremailDB

3.3操作系统环境检查

3.3.1操作系统要求

检查数据库服务器上安装的操作系统是否能够满足需求,建议安装主流稳定版的 Linux 操作系统,推荐采用 64 位的 CPU 和操作系统,为方便后期维护时分析问题,建议安装 perf、gdb、nmon、pstack 等工具包。

3.3.2调整sysctl.conf参数

配置参数 overcommit_memory 表示系统的内存分配策略。可以选值为 0,1,2。
0:表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
1:表示内核允许分配所有的物理内存,不管当前的内存状态如何。
2:表示内核允许分配超过所有物理内存和交换空间总和的内存。
以 root 用户登录服务器,修改/etc/sysctl.conf,在文件末尾添加如下内容:

修改sysctl.conf文件参数
[root@CoremailDB ~]# cat  /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
kernel.sysrq=0
net.ipv4.ip_forward=0
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.default.send_redirects=0
net.ipv4.conf.all.accept_source_route=0
net.ipv4.conf.default.accept_source_route=0
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.all.secure_redirects=0
net.ipv4.conf.default.secure_redirects=0
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.icmp_ignore_bogus_error_responses=1
net.ipv4.conf.all.rp_filter=1
net.ipv4.conf.default.rp_filter=1
net.ipv4.tcp_syncookies=1
kernel.dmesg_restrict=1
net.ipv6.conf.all.accept_redirects=0
net.ipv6.conf.default.accept_redirects=0
vm.overcommit_memory=0
vm.swappiness=10
kernel.core_pattern=/dmsoft/dmdbms/bin/core_%e_%p_%t
kernel.core_uses_pid=1
[root@CoremailDB ~]#
保存sysctl文件并使配置生效
sysctl -p

3.3.3调整 system.conf 参数

system.conf 为系统和服务管理的配置文件,当运行系统实例时,systemd 将读取这个配置文件 system.conf,相反读取 user.conf。达梦数据库服务注册为系统服务的进程,如通过 systemctl或者 service 方式设定随机自启动的数据库服务,其能打开的最大文件描述符、proc 数量等不受limits.conf 控制,需要修改 /etc/systemd/system.conf 文件,添加如下内容:

[root@CoremailDB ~]# cat  /etc/systemd/system.conf
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it under the
#  terms of the GNU Lesser General Public License as published by the Free
#  Software Foundation; either version 2.1 of the License, or (at your option)
#  any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the system.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
#
# Use 'systemd-analyze cat-config systemd/system.conf' to display the full config.
#
# See systemd-system.conf(5) for details.

[Manager]
#LogLevel=info
#LogTarget=journal-or-kmsg
#LogColor=yes
#LogLocation=no
#LogTime=no
#OptionalLog=no
#DumpCore=yes
#ShowStatus=yes
#CrashChangeVT=no
#CrashShell=no
#CrashReboot=no
#CtrlAltDelBurstAction=reboot-force
#CPUAffinity=
#NUMAPolicy=default
#NUMAMask=
#RuntimeWatchdogSec=0
#RebootWatchdogSec=10min
#KExecWatchdogSec=0
#WatchdogDevice=
#CapabilityBoundingSet=
#NoNewPrivileges=no
#SystemCallArchitectures=
#TimerSlackNSec=
#StatusUnitFormat=description
#DefaultTimerAccuracySec=1min
#DefaultStandardOutput=journal
#DefaultStandardError=inherit
#DefaultTimeoutStartSec=90s
#DefaultTimeoutStopSec=90s
#DefaultTimeoutAbortSec=
#DefaultRestartSec=100ms
#DefaultStartLimitIntervalSec=10s
#DefaultStartLimitBurst=5
#DefaultEnvironment=
#DisableCGroupControllers=no
#DefaultCPUAccounting=no
#DefaultIOAccounting=no
#DefaultIPAccounting=no
#DefaultBlockIOAccounting=no
#DefaultMemoryAccounting=yes
#DefaultCpusetAccounting=
#DefaultFreezerAccounting=no
#DefaultTasksAccounting=yes
#DefaultTasksMax=80%
#DefaultLimitCPU=
#DefaultLimitFSIZE=
#DefaultLimitDATA=
#DefaultLimitSTACK=
#DefaultLimitCORE=
#DefaultLimitRSS=
#DefaultLimitNOFILE=1024:524288
#DefaultLimitAS=
#DefaultLimitNPROC=
DefaultLimitMEMLOCK=64M
#DefaultLimitLOCKS=
#DefaultLimitSIGPENDING=
#DefaultLimitMSGQUEUE=
#DefaultLimitNICE=
#DefaultLimitRTPRIO=
#DefaultLimitRTTIME=
#DefaultInvalidateCgroup=yes
#DefaultOOMPolicy=stop
DefaultDFXReboot=yes

在上面的文件中追加下面几行
DefaultLimitFSIZE=unlimited
DefaultLimitDATA=unlimited
DefaultLimitCORE=unlimited
DefaultLimitNOFILE=65536
DefaultLimitAS=unlimited
DefaultLimitNPROC=10240
DefaultLimitNICE=0

3.3.4关闭防火墙

可以使用命令只开放相关端口或者关闭防火墙:
[root@CoremailDB ~]# systemctl status firewalld
○ firewalld.service - firewalld - dynamic firewall daemon
     Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
     Active: inactive (dead)
       Docs: man:firewalld(1)
[root@CoremailDB ~]# systemctl stop  firewalld
[root@CoremailDB ~]# systemctl disable  firewalld

3.3.5禁用 SELINUX

SELinux 组件可用来加强系统安全性。在 Linux 中,SELinux 凌驾于 root 权限之上,设置了很多额外的配置项。如果了解这些配置项,可以进行相应设置,但如果不了解,那么 SELinux 可能不仅没有一些实际性的帮助,反而会带来很多不确定因素,所以建议关闭。关闭方法如下:

##临时关闭 SELinux:
[root@localhost ~]# setenforce 0
##临时开启 SELinux:
[root@localhost ~]# setenforce 1
##查看当前状态命令:
[root@localhost ~]# getenforce
Permissive
##永久关闭 SELinux 需修改配置文件:/etc/selinux/config,修改 SELINUX=disabled
[root@localhost ~]# cat /etc/selinux/config
SELINUX=disabled #修改为 disabled
[root@CoremailDB ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

修改 SELinux 永久关闭,必须重启服务器,才能生效。且永久关闭后,不能通过 setenforce 1命令临时打开。

3.3.6关闭 swap 分区

在 Linux 下,SWAP 的作用类似 Windows 系统下的“虚拟内存”。当物理内存不足时,拿出部分硬盘空间当 SWAP 分区(虚拟成内存)使用,从而解决内存容量不足的情况。
数据库系统一般都对响应延迟比较敏感,如果使用 swap 代替内存,数据库服务性能必然不可接受。对于响应延迟极其敏感的系统来讲,延迟太大和服务不可用没有任何区别,比服务不可用更严重的是,swap 场景下进程就是不卡死,也意味着系统一直不可用,所以不使用 swap 直接oom,是更好的选择。
注:swap 的关闭需要视情况而定,不是必选项,内存充裕关闭,内存太小不关闭,建议内存小于 32G,开启 swap 分区,内存大于 32G,关闭 swap 分区。

[root@localhost ~]# swapoff -a         永久修改
--永久关闭 swap 分区
[root@localhost ~]# sed -ri 's/.*swap.*/#&/' /etc/fstab
[root@localhost ~]#reboot  //重启生效
[root@localhost ~]#free -g   //查看swap空间

3.3.7禁用透明大页

在 khugepaged 进行扫描进程占用内存,并将 4kPage 交换为 Huge Pages 的这个过程中,
对于操作的内存的各种分配活动都需要各种内存锁,直接影响程序的内存访问性能。并且,这个过程对于应用是透明的,在应用层面不可控制,对于专门为 4k page 优化的程序来说,可能会造成随机的性能下降现象。查看是否启用透明大页

[root@CoremailDB dmsoft]# cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
[root@CoremailDB dmsoft]#
[always]表示透明大页启用 [never]表示透明大页禁用。[]扩号内的表示是生效的配置
关闭透明大页:
vi /etc/default/grub
在GRUB_CMDLINE_LINUX行增加"transparent_hugepage=never"
grub2-mkconfig -o /boot/efi/EFI/openEuler/grub.cfg 
reboot				//需要重启生效
[root@CoremailDB ~]# vi /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="video=VGA-1:640x480-32@60me cgroup_disable=files apparmor=0 crashkernel=512M,high smmu.bypassdev=0x1000:0x17 smmu.bypassdev=0x1000:0x15 arm64.nopauth console=tty0 console=ttyAMA0 net.ifnames=0 biosdevname=0 nopti nohz=off quiet transparent_hugepage=never"
GRUB_DISABLE_RECOVERY="true"
[root@CoremailDB ~]# grub2-mkconfig  -o /boot/efi/EFI/openEuler/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.10.0-221.0.0.120.oe2203sp4.aarch64
Found initrd image: /boot/initramfs-5.10.0-221.0.0.120.oe2203sp4.aarch64.img
Found linux image: /boot/vmlinuz-0-rescue-382c0354023c4d14a247cb082bcd52a0
Found initrd image: /boot/initramfs-0-rescue-382c0354023c4d14a247cb082bcd52a0.img
Adding boot menu entry for UEFI Firmware Settings ...
done
[root@CoremailDB ~]# cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
cat /sys/kernel/mm/transparent_hugepage/defrag

3.3.8关闭NUMA

NUMA(Non-Uniform Memory Access)架构是为了解决多 CPU 下内存访问冲突,简单来说
不在将整个物理内存作为一个整体,而是根据不同的 CPU 区分不同的内存块儿,如 2 颗 CPU 每颗CPU 使用 64G 内存。
当 NUMA 参数 zone_reclaim_mode 在设置为 1 时,内核将要求多路 CPU 尽量从距离较近的系统内存节点(服务器的整体内存在 numa 架构下将被分成若干个节点)分配内存而不是在整个服务器可访问内存的范围内进行内存分配,因此在较高内存占用压力下内存申请会触发内存频繁回收整理的机制严重影响了系统整体性能(长期处于内核态 sys 很高)。进而可能导致 SQL 卡顿问题的发生。
查看 numa 是否启用

[root@CoremailDB ~]# dmesg|grep -i numa
[    0.000000] NUMA: NODE_DATA [mem 0x83fffa2c0-0x83fffffff]
[    0.000000] NUMA: NODE_DATA [mem 0x101fee82c0-0x101feedfff]
[    0.000000] ACPI: NUMA: SRAT: PXM 0 -> MPIDR 0x0 -> Node 0
[    0.000000] ACPI: NUMA: SRAT: PXM 0 -> MPIDR 0x1 -> Node 0
[    0.000000] ACPI: NUMA: SRAT: PXM 0 -> MPIDR 0x2 -> Node 0
[    0.000000] ACPI: NUMA: SRAT: PXM 0 -> MPIDR 0x3 -> Node 0
[    0.000000] ACPI: NUMA: SRAT: PXM 0 -> MPIDR 0x4 -> Node 0
[    0.000000] ACPI: NUMA: SRAT: PXM 0 -> MPIDR 0x5 -> Node 0
[    0.000000] ACPI: NUMA: SRAT: PXM 0 -> MPIDR 0x6 -> Node 0
[    0.000000] ACPI: NUMA: SRAT: PXM 0 -> MPIDR 0x7 -> Node 0
[    0.000000] ACPI: NUMA: SRAT: PXM 1 -> MPIDR 0x8 -> Node 1
[    0.000000] ACPI: NUMA: SRAT: PXM 1 -> MPIDR 0x9 -> Node 1
[    0.000000] ACPI: NUMA: SRAT: PXM 1 -> MPIDR 0xa -> Node 1
[    0.000000] ACPI: NUMA: SRAT: PXM 1 -> MPIDR 0xb -> Node 1
[    0.000000] ACPI: NUMA: SRAT: PXM 1 -> MPIDR 0xc -> Node 1
[    0.000000] ACPI: NUMA: SRAT: PXM 1 -> MPIDR 0xd -> Node 1
[    0.000000] ACPI: NUMA: SRAT: PXM 1 -> MPIDR 0xe -> Node 1
[    0.000000] ACPI: NUMA: SRAT: PXM 1 -> MPIDR 0xf -> Node 1
[    0.000085] mempolicy: Enabling automatic NUMA balancing. Configure with numa_balancing= or the kernel.numa_balancing sysctl
[    0.189136] pci_bus 0000:00: Unknown NUMA node; performance will be reduced
[root@CoremailDB ~]#

出现红色字体部分表示 numa 开启,关闭 NUMA 方法如下:
编辑 grub 文件,如下图所示在 GRUB_CMDLINE_LINUX 一行加上:
numa=off 配置需要放在双引号内

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="video=VGA-1:640x480-32@60me cgroup_disable=files apparmor=0 crashkernel=512M,high smmu.bypassdev=0x1000:0x17 smmu.bypassdev=0x1000:0x15 arm64.nopauth console=tty0 console=ttyAMA0 net.ifnames=0 biosdevname=0 nopti nohz=off quiet transparent_hugepage=never numa=off"
GRUB_DISABLE_RECOVERY="true"
[root@CoremailDB ~]# grub2-mkconfig -o /boot/efi/EFI/openEuler/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.10.0-221.0.0.120.oe2203sp4.aarch64
Found initrd image: /boot/initramfs-5.10.0-221.0.0.120.oe2203sp4.aarch64.img
Found linux image: /boot/vmlinuz-0-rescue-382c0354023c4d14a247cb082bcd52a0
Found initrd image: /boot/initramfs-0-rescue-382c0354023c4d14a247cb082bcd52a0.img
Adding boot menu entry for UEFI Firmware Settings ...
done
[root@CoremailDB ~]#

4.安装数据库

4.1创建安装数据库管理员帐号

创建数据库安装组

[root@CoremailDB ~]# groupadd  dminstall

创建安装用户

useradd -g dminstall -d /home/dmdba -s /bin/bash dmdba

修改dmdba的密码

[root@CoremailDB /]# passwd dmdba
Changing password for user dmdba.
New password:
BAD PASSWORD: The password contains less than 1 digits
Retype new password:
passwd: all authentication tokens updated successfully.
切换到dmdba帐号
su – dmdba

4.2修改/etc/security/limits.conf

以 root 用户登录服务器,修改/etc/security/limits.conf

dmdba  hard      nice       0
dmdba  soft      as         unlimited
dmdba  hard      as         unlimited
dmdba  soft      fsize      unlimited
dmdba  hard      fsize      unlimited
dmdba  soft      nproc      65536
dmdba  hard      nproc      65536
dmdba  soft      nofile     65536
dmdba  hard      nofile     65536
dmdba  soft      core       unlimited
dmdba  hard      core       unlimited
dmdba  soft      data       unlimited
dmdba  hard      data       unlimited

增加/etc/security/limits.conf 文件的读取权限
su - root
chmod -R a+x /etc/security
保存后,切换到 dmdba 用户,执行如下命令检查设置是否生效

ulimit -a
core file size          (blocks, -c) unlimited
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 61776
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1048576
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192

4.3限制 arena 的最大数量

Glibc 为了分配内存的性能,使用了很多叫做 arena 的 memory pool,在 64 位下每一个 arena是 64M,一个进程最多可以有 core*8 个 arena。数量如果多的话,会造成服务器占用内存严重情况,可以设置为 MALLOC_ARENA_MAX=1

vi /etc/profile
export MALLOC_ARENA_MAX=1

4.4修改目录权限

chown -R dmdba:dminstall /dmsoft
chmod -R 755 /dmsoft
[root@CoremailDB /]# ls -lh
total 66K
dr-xr-xr-x.   2 root  root      4.0K May 25 11:43 afs
lrwxrwxrwx.   1 root  root         7 May 25 11:43 bin -> usr/bin
dr-xr-xr-x.   7 root  root      4.0K Oct 27 18:33 boot
drwxr-xr-x   19 root  root      3.3K Oct 27 21:53 dev
drwxr-xr-x    2 dmdba dminstall   47 Oct 27 21:38 dmsoft
drwxr-xr-x.  96 root  root       12K Oct 27 19:35 etc
drwxr-xr-x.   3 root  root      4.0K Oct 27 19:14 home
lrwxrwxrwx.   1 root  root         7 May 25 11:43 lib -> usr/lib
lrwxrwxrwx.   1 root  root         9 May 25 11:43 lib64 -> usr/lib64
drwx------.   2 root  root       16K Aug  9 11:20 lost+found
dr-xr-xr-x    1 root  root      2.0K Sep 11 11:20 media
drwxr-xr-x.   2 root  root      4.0K May 25 11:43 mnt
drwxr-xr-x.   2 root  root      4.0K May 25 11:43 opt
dr-xr-xr-x  336 root  root         0 Oct 27 19:08 proc
dr-xr-x---.   4 root  root      4.0K Oct 27 21:34 root
drwxr-xr-x   34 root  root      1.1K Oct 27 19:08 run
lrwxrwxrwx.   1 root  root         8 May 25 11:43 sbin -> usr/sbin
drwxr-xr-x.   2 root  root      4.0K May 25 11:43 srv
dr-xr-xr-x   12 root  root         0 Oct 27 19:08 sys
drwxrwxrwt    9 root  root       180 Oct 27 21:53 tmp
drwxr-xr-x.  12 root  root      4.0K Aug  9 11:21 usr
drwxr-xr-x.  19 root  root      4.0K Aug  9 11:29 var

4.5安装数据库软件

挂载镜像

mount /dmsoft/dm8_20240911_HWarm_centos7_64.iso /media/

切换到dmdba用户下开始安装

[root@CoremailDB /]# su - dmdba
Last login: Sun Oct 27 22:06:36 CST 2024 on pts/0
Welcome to 5.10.0-221.0.0.120.oe2203sp4.aarch64
System information as of time:  Sun Oct 27 10:09:10 PM CST 2024
System load:    0.15
Memory used:    .3%
Swap used:      0.0%
Usage On:       9%
IP address:     192.168.0.112
Users online:   1
To run a command as administrator(user "root"),use "sudo <command>".
[dmdba@CoremailDB ~]$ cd /media/ 

[dmdba@CoremailDB media]$ ./DMInstall.bin -i
Installer Language:
[1]: 简体中文
[2]: English
Please select the installer's language [2]:1
解压安装程序..........
硬件架构校验通过!
欢迎使用达梦数据库安装程序
是否输入Key文件路径? (Y/y:是 N/n:否) [Y/y]:n
是否设置时区? (Y/y:是 N/n:否) [Y/y]:y
设置时区:
[ 1]: (GTM-12:00) 日界线西
[ 2]: (GTM-11:00) 萨摩亚群岛
[ 3]: (GTM-10:00) 夏威夷
[ 4]: (GTM-09:00) 阿拉斯加
[ 5]: (GTM-08:00) 太平洋时间(美国和加拿大)
[ 6]: (GTM-07:00) 亚利桑那
[ 7]: (GTM-06:00) 中部时间(美国和加拿大)
[ 8]: (GTM-05:00) 东部部时间(美国和加拿大)
[ 9]: (GTM-04:00) 大西洋时间(美国和加拿大)
[10]: (GTM-03:00) 巴西利亚
[11]: (GTM-02:00) 中大西洋
[12]: (GTM-01:00) 亚速尔群岛
[13]: (GTM) 格林威治标准时间
[14]: (GTM+01:00) 萨拉热窝
[15]: (GTM+02:00) 开罗
[16]: (GTM+03:00) 莫斯科
[17]: (GTM+04:00) 阿布扎比
[18]: (GTM+05:00) 伊斯兰堡
[19]: (GTM+06:00) 达卡
[20]: (GTM+07:00) 曼谷,河内
[21]: (GTM+08:00) 中国标准时间
[22]: (GTM+09:00) 首尔
[23]: (GTM+10:00) 关岛
[24]: (GTM+11:00) 所罗门群岛
[25]: (GTM+12:00) 斐济
[26]: (GTM+13:00) 努库阿勒法
[27]: (GTM+14:00) 基里巴斯
请选择时区 [21]:21
安装类型:
1 典型安装
2 服务器
3 客户端
4 自定义
请选择安装类型的数字序号 [1 典型安装]:4
1 服务器组件
2 客户端组件
  2.1 DM管理工具
  2.2 DM性能监视工具
  2.3 DM数据迁移工具
  2.4 DM控制台工具
  2.5 DM审计分析工具
  2.6 SQL交互式查询工具
3 驱动
4 用户手册
5 数据库服务
  5.1 实时审计服务
  5.2 作业服务
  5.3 实例监控服务
  5.4 辅助插件服务
请选择安装组件的序号 (使用空格间隔) [1 2 3 4 5]:1 2 3 4 5
所需空间: 2322M
请选择安装目录 [/home/dmdba/dmdbms]:/dmsoft
可用空间: 496G
是否确认安装路径(/dmsoft)? (Y/y:是 N/n:否)  [Y/y]:y
安装前小结
安装位置: /dmsoft
所需空间: 2322M
可用空间: 496G
版本信息:
有效日期:
安装类型: 自定义
是否确认安装? (Y/y:是 N/n:否):y
2024-10-27 22:10:23
[INFO] 安装 基础 模块...
2024-10-27 22:10:23
[INFO] 安装达梦数据库...
2024-10-27 22:10:26
[INFO] 安装 服务器 模块...
2024-10-27 22:10:27
[INFO] 安装 客户端 模块...
2024-10-27 22:10:30
[INFO] 安装 驱动 模块...
2024-10-27 22:10:30
[INFO] 安装 手册 模块...
2024-10-27 22:10:30
[INFO] 安装 服务 模块...
2024-10-27 22:10:31
[INFO] 移动日志文件。
2024-10-27 22:10:31
[INFO] 安装达梦数据库完成。

请以root系统用户执行命令:
/dmsoft/script/root/root_installer.sh
安装结束
[dmdba@CoremailDB media]$
[root@CoremailDB ~]# /dmsoft/script/root/root_installer.sh
移动 /dmsoft/bin/dm_svc.conf 到/etc目录

4.6用命令行初始化数据库

以下命令设置页大小为 32 KB,簇大小为 32 KB,大小写不敏感CASE_SENSITIVE=N,字符集为 utf_8 CHARSET=1,数据库名为 DMTEST,实例名为 DBSERVER,端口为 5237。

cd /dmsoft/bin/
./dminit PATH=/dmsoft/CoremailDB/data PAGE_SIZE=32 LOG_SIZE=2048 CASE_SENSITIVE=N EXTENT_SIZE=32 CHARSET=1 DB_NAME=CoremailDB INSTANCE_NAME=CoremailDB PORT_NUM=5237
[root@CoremailDB bin]# ./dminit PATH=/dmsoft/CoremailDB/data PAGE_SIZE=32 LOG_SIZE=2048 CASE_SENSITIVE=N EXTENT_SIZE=32 CHARSET=1 DB_NAME=CoremailDB INSTANCE_NAME=CoremailDB PORT_NUM=5237
initdb V8
db version: 0x7000c
file dm.key not found, use default license!
License will expire on 2025-09-11
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL

 log file path: /dmsoft/CoremailDB/data/CoremailDB/CoremailDB01.log
 log file path: /dmsoft/CoremailDB/data/CoremailDB/CoremailDB02.log

write to dir [/dmsoft/CoremailDB/data/CoremailDB].
create dm database success. 2024-10-27 22:34:29
[root@CoremailDB bin]#

4.8安装数据库许可

将dm.key许可文件复制到安装目录下面
[root@CoremailDB bin]# pwd
/dmsoft/bin
[root@CoremailDB bin]# ll |grep key
-r-xr-xr-x 1 dmdba dminstall     77024 Sep 11 11:14 dmfekey
-rw-r--r-- 1 root  root            648 Oct 27 22:39 dm.key
-r-xr-xr-x 1 dmdba dminstall     76248 Sep 11 11:14 dmkey
-r-xr-xr-x 1 dmdba dminstall     72392 Sep 11 11:14 dmukey_gen

4.9注册数据库服务

[root@CoremailDB root]# cd /dmsoft/script/root
[root@CoremailDB root]# ./dm_service_installer.sh -t dmserver -dm_ini /dmdata/data/DMTEST/dm.ini -p CoremailDB

-t 服务类型 注册服务类型,支持一下服务类型:dmap、dmamon、dmserver、dmwatcher、dmmonitor、dmasmsvr、dmasmsvrm、dmcss、dmcssm。
-dm_ini INI文件路径 指定服务所需要的 dm.ini 文件路径。
-p 服务名后缀 指定服务名后缀,生成的操作系统服务名为“服务脚本模板名,称 + 服务名后缀”。此参数只针对 dmserver、
dmwatcher、dmmonitor、dmasmsvr、dmasmsvrm、dmcss、dmcssm 服务脚本生效。

[root@CoremailDB root]#./dm_service_installer.sh -t dmserver -dm_ini /dmsoft/CoremailDB/data/CoremailDB/dm.ini -p CoremailDB
Created symlink /etc/systemd/system/multi-user.target.wants/DmServiceCoremailDB.service → /usr/lib/systemd/system/DmServiceCoremailDB.service.
创建服务(DmServiceCoremailDB)完成
设置数据库服务自动启动
systemctl enable  DmServiceCoremailDB.service
启服数据库
systemctl start  DmServiceCoremailDB.service

4.10 查看服务状态

[root@CoremailDB bin]# systemctl start   DmServiceCoremailDB
[root@CoremailDB bin]# systemctl status    DmServiceCoremailDB
● DmServiceCoremailDB.service - DM Instance Service(DmServiceCoremailDB).
     Loaded: loaded (/usr/lib/systemd/system/DmServiceCoremailDB.service; enabled; vendor preset: disabled)
     Active: active (running) since Sun 2024-10-27 22:58:48 CST; 8s ago
    Process: 41409 ExecStart=/dmsoft/bin/DmServiceCoremailDB start (code=exited, status=0/SUCCESS)
   Main PID: 41436 (dmserver)
      Tasks: 129
     Memory: 797.8M
     CGroup: /system.slice/DmServiceCoremailDB.service
             └─ 41436 /dmsoft/bin/dmserver path=/dmsoft/CoremailDB/data/CoremailDB/dm.ini -noconsole

Oct 27 22:58:33 CoremailDB systemd[1]: Starting DM Instance Service(DmServiceCoremailDB)....
Oct 27 22:58:48 CoremailDB DmServiceCoremailDB[41409]: [41B blob data]
Oct 27 22:58:48 CoremailDB systemd[1]: Started DM Instance Service(DmServiceCoremailDB)..
[root@CoremailDB bin]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1040/rpcbind
tcp        0      0 0.0.0.0:36213           0.0.0.0:*               LISTEN      1581/sshd: /usr/sbi
tcp6       0      0 :::111                  :::*                    LISTEN      1040/rpcbind
tcp6       0      0 :::5237                 :::*                    LISTEN      41436/dmserver
tcp6       0      0 :::36213                :::*                    LISTEN      1581/sshd: /usr/sbi
评论
后发表回复

作者

文章

阅读量

获赞

扫一扫
联系客服