1. 查找yum里有哪些安装版本
环境说明:
[root@localhost ~]# cat /etc/redhat-release
CentOS Stream release 8
[root@localhost yum.repos.d]# curl -O http://192.168.13.234:7777/local.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2410 100 2410 0 0 60528 0 --:--:-- --:--:-- --:--:-- 61794
[root@localhost yum.repos.d]# ls
local.repo
[root@localhost ~]# yum list postgresql*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
postgresql-jdbc.noarch 42.3.3-1.rhel7 pgdg-common
postgresql-jdbc-javadoc.noarch 42.3.3-1.rhel7 pgdg-common
postgresql-pgpool-II.x86_64 3.4.6-1.el7 epel
postgresql-pgpool-II-devel.x86_64 3.4.6-1.el7 epel
postgresql-pgpool-II-extensions.x86_64 3.4.6-1.el7 epel
postgresql-plruby.x86_64 0.5.3-13.el7 epel
postgresql-plruby-doc.x86_64 0.5.3-13.el7 epel
postgresql-unit13.x86_64 7.2-1.rhel7.1 pgdg13
postgresql-unit_13.x86_64 7.4-1.rhel7 pgdg13
postgresql12-odbc.x86_64 12.02.0000-1PGDG.rhel7 pgdg-common
postgresql12-odbc-debuginfo.x86_64 12.02.0000-1PGDG.rhel7 pgdg-common
postgresql13.x86_64 13.6-1PGDG.rhel7 pgdg13
postgresql13-contrib.x86_64 13.6-1PGDG.rhel7 pgdg13
postgresql13-devel.x86_64 13.6-1PGDG.rhel7 pgdg13
postgresql13-docs.x86_64 13.6-1PGDG.rhel7 pgdg13
postgresql13-libs.x86_64 13.6-1PGDG.rhel7 pgdg13
postgresql13-llvmjit.x86_64 13.6-1PGDG.rhel7 pgdg13
postgresql13-odbc.x86_64 13.02.0000-1PGDG.rhel7 pgdg13
postgresql13-plperl.x86_64 13.6-1PGDG.rhel7 pgdg13
postgresql13-plpython3.x86_64 13.6-1PGDG.rhel7 pgdg13
postgresql13-pltcl.x86_64 13.6-1PGDG.rhel7 pgdg13
postgresql13-server.x86_64 13.6-1PGDG.rhel7 pgdg13
postgresql13-test.x86_64 13.6-1PGDG.rhel7 pgdg13
postgresql_anonymizer13.x86_64 0.7.1-1.rhel7 pgdg13
postgresql_anonymizer_13.x86_64 0.9.0-1.rhel7 pgdg13
postgresql_autodoc.noarch 1.41.1-1.rhel7.1 pgdg-common
postgresql_faker_13.noarch 0.4.0-1.rhel7 pgdg13
postgresql_faker_13.x86_64 0.5.3-1.rhel7 pgdg13
postgresqltuner.noarch 1.0.1-4.el7 epel
[root@localhost ~]#
2. 开始安装
[root@localhost ~]# yum install -y postgresql13 postgresql13-server
3. 初始化数据库
[root@localhost ~]# cd /usr/pgsql-13/bin/
[root@localhost bin]# postgresql-13-setup initdb
Initializing database ... OK
[root@localhost bin]#
4. 设置postgresql开机自启
[root@localhost bin]# systemctl enable --now postgresql-13
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-13.service to /usr/lib/systemd/system/postgresql-13.service.
[root@localhost bin]# systemctl status postgresql-13
● postgresql-13.service - PostgreSQL 13 database server
Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2022-03-24 10:30:24 CST; 19s ago
Docs: https://www.postgresql.org/docs/13/static/
Process: 1721 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Main PID: 1727 (postmaster)
CGroup: /system.slice/postgresql-13.service
├─1727 /usr/pgsql-13/bin/postmaster -D /var/lib/pgsql/13/data/
├─1729 postgres: logger
├─1731 postgres: checkpointer
├─1732 postgres: background writer
├─1733 postgres: walwriter
├─1734 postgres: autovacuum launcher
├─1735 postgres: stats collector
└─1736 postgres: logical replication launcher
Mar 24 10:30:23 localhost.localdomain systemd[1]: Starting PostgreSQL 13 database server...
Mar 24 10:30:24 localhost.localdomain postmaster[1727]: 2022-03-24 10:30:24.020 CST [1727]...s
Mar 24 10:30:24 localhost.localdomain postmaster[1727]: 2022-03-24 10:30:24.020 CST [1727]....
Mar 24 10:30:24 localhost.localdomain systemd[1]: Started PostgreSQL 13 database server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost bin]#
5. 修改账户密码
//进入psql shell
[root@localhost ~]# su postgres
bash-4.2$ psql
could not change directory to "/root": Permission denied
psql (13.6)
Type "help" for help.
postgres=# CREATE DATABASE decdb;
CREATE DATABASE
postgres=# ALTER USER postgres WITH PASSWORD 'whyh2021';
ALTER ROLE
postgres=# \q
bash-4.2$ exit
exit
[root@localhost ~]#
6. 修改ip绑定
//修改配置文件
[root@localhost ~]# vi /var/lib/pgsql/13/data/postgresql.conf
//将监听地址修改为*#默认listen_addresses配置是注释掉的,所以可以直接在配置文件开头加入该行listen_addresses='*'
7. 允许所有ip访问
[root@localhost ~]# vi /var/lib/pgsql/13/data/pg_hba.conf
84 local all all md5
86 host all all 127.0.0.1/32 scram-sha-256
87 host all all 0.0.0.0/0 md5 //添加这一行
[root@localhost bin]# systemctl restart postgresql-13.service
[root@localhost bin]# psql -U postgres
Password for user postgres:
psql (13.6)
Type "help" for help.
postgres=# \q
[root@localhost bin]#