【PostgreSQL实战1】基于openEuler部署PostgreSQL

【PostgreSQL实战1】基于openEuler部署PostgreSQL



前言

本文是基于openEuler部署PostgreSQL的安装实践。
适用于所有使用openEuler操作系统的用户,特别是初次使用或想了解openEuler的用户,包括系统工程师、管理员及维护人员等。使用本手册的用户需要具备基础的Linux系统管理知识。

一、PostgreSQL是什么?

PostgreSQL是一个高度可定制的、功能丰富的数据库管理系统,它支持复杂的查询、事务处理、多版本并发控制等高级数据库功能。PostgreSQL以POSTGRES 4.2版本为基础,经过多年的发展,已经成为许多企业和开发者首选的开源数据库解决方案。

二、环境准备

安装数据库前请先安装好操作系统,这里我们使用openEuler
,下面我们介绍一下,配置情况,也可以根据实践情况进行规划。

-项目--配置-
CPU2C
内存8G
硬盘20G

2.1 操作系统

[root@localhost etc]# cat /etc/openEuler-release 
openEuler release 20.03 (LTS-SP4)
[root@localhost etc]# cat /etc/os-release 
NAME="openEuler"
VERSION="20.03 (LTS-SP4)"
ID="openEuler"
VERSION_ID="20.03"
PRETTY_NAME="openEuler 20.03 (LTS-SP4)"
ANSI_COLOR="0;31"

2.2 内存

[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          7.3Gi       285Mi       6.4Gi        16Mi       579Mi       6.7Gi
Swap:         2.0Gi          0B       2.0Gi

2.3 CPU

[root@localhost ~]# lscpu
架构:                              x86_64
CPU 运行模式:                      32-bit, 64-bit
字节序:                            Little Endian
Address sizes:                      45 bits physical, 48 bits virtual
CPU:                                4
在线 CPU 列表:                     0-3
每个核的线程数:                    1
每个座的核数:                      2
座:                                2
NUMA 节点:                         1
厂商 ID:                           GenuineIntel
CPU 系列:                          6
型号:                              140
型号名称:                          11th Gen Intel(R) Core(TM) i5-1155G7 @ 2.50GHz
步进:                              2
CPU MHz:                           2496.001
BogoMIPS:                          4992.00
超管理器厂商:                      VMware
虚拟化类型:                        完全
L1d 缓存:                          192 KiB
L1i 缓存:                          128 KiB
L2 缓存:                           5 MiB
L3 缓存:                           16 MiB
NUMA 节点0 CPU:                    0-3
Vulnerability Gather data sampling: Unknown: Dependent on hypervisor status
Vulnerability Itlb multihit:        KVM: Vulnerable
Vulnerability L1tf:                 Not affected
Vulnerability Mds:                  Not affected
Vulnerability Meltdown:             Not affected
Vulnerability Mmio stale data:      Not affected
Vulnerability Retbleed:             Not affected
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Vulnerable: eIBRS with unprivileged eBPF
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Not affected
标记:                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_p
                                    erfmon rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes
                                     xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbase tsc_adjust bmi1 avx2 smep bmi2 er
                                    ms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves arat avx512vbmi 
                                    umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b md_clear flush_l1d arch_capabilities

[root@localhost ~]# lscpu -e
CPU NODE SOCKET CORE L1d:L1i:L2:L3 ONLINE
  0    0      0    0 0:0:0:0           是
  1    0      0    1 1:1:1:0           是
  2    0      1    2 2:2:2:1           是
  3    0      1    3 3:3:3:1           是


2.4 关闭selinux

setenforce 0 临时关闭后,修改/etc/selinux/config文件 永久关闭。

getenforce 查看状态,
setenforce 0 关闭
setenforce 1 开启。

[root@localhost ~]# getenforce 
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce 
Permissive

永久关闭 修改/etc/selinux/config
SELINUX=enforcing 改为 SELINUX=disabled

vim /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状态

[root@localhost ~]# getenforce 
Disabled

2.5 关闭防火墙

为了方便我先关闭系统防火墙,生产环境建议开启,根据业务需要配置。
systemctl status firewalld 查看防火墙状态
systemctl stop firewalld 关闭防火墙
systemctl disable firewalld 永久关闭防火墙
systemctl start firewalld 开启防火墙

[root@localhost ~]# systemctl status firewalld 
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2024-11-26 14:11:04 CST; 4min 34s ago
     Docs: man:firewalld(1)
 Main PID: 849 (firewalld)
    Tasks: 2
   Memory: 35.9M
   CGroup: /system.slice/firewalld.service
           └─849 /usr/bin/python3 /usr/sbin/firewalld --nofork --nopid

1126 14:11:03 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
1126 14:11:04 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
[root@localhost ~]# systemctl disable  firewalld 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# systemctl stop firewalld 
[root@localhost ~]# 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)

1126 14:11:03 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
1126 14:11:04 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
1126 14:16:46 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewall daemon...
1126 14:16:47 localhost.localdomain systemd[1]: firewalld.service: Succeeded.
1126 14:16:47 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon.

三、部署安装

3.1 创建用户名

groupadd -g 60000 postgres
useradd -u 60000 -g postgres postgres
echo "postgres" | passwd --stdin postgres

3.2 创建目录

mkdir -p /dbs/pg14/data
mkdir -p /pg14/soft
chown -R postgres:postgres /dbs 
chown -R postgres:postgres /pg14
chmod -R 775 /pg14
chmod -R 775 /dbs 

3.3 安装依赖

dnf install -y perl-ExtUtils-Embed readline-devel python3-devel pam-devel libxml2-devel libxslt-devel openldap-devel lz4-devel llvm-devel systemd-devel container-selinux selinux-policy-devel openssl-devel clang-devel flex-devel bison-devel glibc-devel gcc-c++ gcc cmake lsof net-tools tar zlib-devel --allowerasing --skip-broken 

3.4 安装包下载

安装包下载: PostgreSQL官网 选择自己需要的版本
这里采用postgresql-14.11.tar.gz 源码编译安装。

[root@localhost ~]# su - postgres
[postgres@localhost ~]$ wget https://ftp.postgresql.org/pub/source/v14.11/postgresql-14.11.tar.gz

3.5 编译安装

[postgres@localhost ~]$ ls
postgresql-14.11.tar.gz
[postgres@localhost ~]$ mv postgresql-14.11.tar.gz /pg14/soft
[postgres@localhost ~]$ cd postgresql
[postgres@localhost ~]$ ./configure --prefix=/pg14/soft --without-readline
[postgres@localhost ~]$ make && make install

3.6 配置环境变量

cat >> ~/.bash_profile <<"EOF"
export PGPORT=5666
export PGDATA=/dbs/pg14/data
export PGHOME=/pg14/soft
export PATH=$PGHOME/bin:$PATH:.
EOF

3.7 初始化

[postgres@localhost ~]$ initdb

3.8 启动postgres服务

[postgres@localhost ~]$ pg_ctl start -D $PGDATA

安装完成

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

云计算老王

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

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

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

打赏作者

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

抵扣说明:

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

余额充值