【创建个人服务器】一.安装软件-数据库

目录

【创建个人服务器】一.安装软件-数据库
【创建个人服务器】二.创建一个Springboot项目
【创建个人服务器】三.部署springboot
【创建个人服务器】四.第一个应用:文档合并
【创建个人服务器】五.项目部署

数据库使用PostgreSql-14.5

参考 (感谢!)

【详细】远程连接PgSQL设置
centos7安装pgsql

0.安装

下载地址: https://www.postgresql.org/ftp/source/

1.安装依赖包

yum -y install readline gcc -y readline-devel zlib-devel

2.编译安装

tar -xvf postgresql-14.5.tar.gz
mkdir -p /opt/postgresql-14.5
cd postgresql-14.5
./configure --prefix=/opt/postgresql-14.5 --with-blocksize=32 && make && make install

3.创建相应的用户

groupadd postgres
useradd -g postgres postgres
创建数据及日志目录,并做相应授权
mkdir -p /opt/postgresql-14.5/{data,log}
chown -R postgres:postgres /opt/postgresql-14.5

4.初始化数据库

su - postgres
[postgres@localhost bin]$ cd /opt/postgresql-14.5/bin
[postgres@localhost bin]$ ./initdb -D /opt/postgresql-14.5/data/

5.启动数据库

[postgres@localhost bin]$ cd /opt/postgresql-11.6/bin
[postgres@localhost bin]$./pg_ctl -D /opt/postgresql-14.5/data/ -l /opt/postgresql-14.5/log/postgres.log start

6.修改环境变量

[postgres@localhost ~]$ vim .bash_profile

# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/opt/postgresql-11.6/bin
export PATH

source .bash_profile

【错误】postgresql报错Error while loading shared libraries: libpq.so.5: cannot open shared object file

解决办法,在~/.bashrc中加入:

export LD_LIBRARY_PATH=/usr/local/postgresql/lib
路径视自己的安装路径情况而定。

然后source ~/.bashrc

7.配置postgresql允许远程访问

只需要修改data目录下的pg_hba.conf和postgresql.conf这两个文件:

pg_hba.conf:配置对数据库的访问权限;

postgresql.conf:配置PostgreSQL数据库服务器的相应的参数

8.修改pg_hba.conf

vim /opt/postgresql-11.6/data/pg_hba.conf

host all all 0/0 md5

8.重新加载配置文件

su - postgres

pg_ctl -D /opt/postgresql-11.6/data reload

9.修改postgresql.conf

vim /opt/postgresql-11.6/data/postgresql.conf

listen_addresses = '*' # what IP address(es) to listen on;

10.修改该改参数需要重启动

pg_ctl -D /opt/postgresql-11.6/data -l /opt/postgresql/log/postgres.log stop

pg_ctl -D /opt/postgresql-11.6/data -l /opt/postgresql/log/postgres.log start

11. 修改配置文件(postgresql.conf)

vim /opt/postgresql-11.6/data/postgresql.conf

找到相应的参数进行如下配置修改

wal_level = replica

archive_mode = on

archive_command = 'cp %p /opt/postgresql/data/pg_archive/%f'

##%p = path of file to archive

##%f = file name only

max_wal_senders = 6

wal_keep_segments = 10240

wal_sender_timeout = 60s

12.创建归档日志目录

mkdir -p /opt/postgresql/data/pg_archive

重启主库

pg_ctl -D /opt/postgresql/data/ -l /opt/postgresql/log/postgres.log restart

13.连接时

默认的初始数据库和用户名都是postgres

密码需要使用postgres账号进入数据库
psql
ALTER USER postgres WITH PASSWORD ‘postgres’;

posted @ 2022-09-21 23:19  Raiyon  阅读(79)  评论(0编辑  收藏  举报