postgresql centos7 安装 本是古典 何须时尚 2022-12-08 14:26 156阅读 0赞 # 1、postgresql安装 # # 1.1 导入yum源 # >yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm # 1.2 安装postgresql12 # >yum install -y postgresql12 postgresql12-server # 1.3 初始化数据库 # >/usr/pgsql-12/bin/postgresql-12-setup initdb # 1.4 常用命令 # #启动PostgreSQL服务 >systemctl start postgresql-12 #设置PostgreSQL服务为开机启动 >systemctl enable postgresql-12 #关闭PostgreSQL服务 >systemctl stop postgresql-12 #PostgreSQL服务状态 >systemctl status postgresql-12 # 1.5 修改密码 # PostgreSQL安装成功之后,会默认创建一个名为postgres的Linux用户,初始化数据库后,会有名为postgres的数据库,来存储数据库的基础信息,例如用户信息等等,相当于MySQL中默认的名为mysql数据库。postgres数据库中会初始化一名超级用户postgres。为了方便我们使用postgres账号进行管理,我们可以修改该账号的密码。 #切换postgres >su postgres #启动sql shell >psql #修改密码为123456 >ALTER USER postgres WITH PASSWORD '123456'; # 2、配置远程访问 # ## 2.1 开放端口 ## 防火墙 >firewall-cmd --add-port=5432/tcp --permanent >firewall-cmd --reload 云服务器开启服务器,如阿里云 ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpeGluZ3poZTI_size_16_color_FFFFFF_t_70][] ## 2.2 修改配置文件 ## ### 2.2.1 修改postgresql.conf ### >vi /var/lib/pgsql/12/data/postgresql.conf 将localhost改为\* listen_addresses = '*' # what IP address(es) to listen on; ### 2.2.2 修改pg\_hba.conf ### >vi /var/lib/pgsql/12/data/pg_hba.conf host all all 0.0.0.0/0 md5 ## 2.3 重启 ## >systemctl restart postgresql-12 [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3hpeGluZ3poZTI_size_16_color_FFFFFF_t_70]: /images/20221123/5486ff21f08e4e01bfeb9ff199e40232.png
还没有评论,来说两句吧...