安装流程
1. 第一步创建目录 把二进制tar包放到里面,并解压
[root@hadoop 100~]# mkdir -p /pgsql/postgresql
[root@hadoop 100 ~]# tar xf postgresql-11.1.tar.gz
解压之后 进入那个解压出来的文件夹
[root@hadoop100 postgresql-11.1]# ./configure --prefix=/pgsql/postgresql/ --without-readline
[root@hadoop100 postgresql-11.1]# make && make install
接下来编译时间比较长
配置用户部分
[root@hadoop100 postgresql-11.1]# groupadd postgres
[root@hadoop100 postgresql-11.1]# useradd -g postgres postgres
[root@hadoop100 postgresql-11.1]# id postgres
接下来退回上一层目录
[root@hadoop100 postgresql-11.1]# cd ..
[root@hadoop100 postgresql]# mkdir data
[root@hadoop100 postgresql]# chown postgres.postgres data
接下来配置环境变量
[root@hadoop100 postgresql]# vi /home/postgres/.bash_profile
文件内容
export PGHOME=/pgsql/postgresql
export PGDATA=/pgsql/postgresql/data
PATH=$PATH:$HOME/bin:$PGHOME/bin
重新编译文件 使其生效
[root@hadoop100 postgresql]# source /home/postgres/.bash_profile
切换到 postgres用户 因为这个数据库规定root不能使用那些命令 除非配置
[root@hadoop100 postgresql]# su - postgres
[postgres@hadoop100 ~]$ initdb 初始化数据库
退出用户 配置其它文件
[postgres@hadoop100 ~]$ exit
登出
[root@hadoop100 postgresql]# cd data/
[root@hadoop100 data]# vi postgresql.conf
文件内容
第一行允许所有ip连接
修改 pg_hba.conf 文件
[root@hadoop100 data]# vi pg_hba.conf
内容 method里面输入的时候 不能多空格不然会莫名其妙报错
# IPv4 local connections:
host all all 0.0.0.0/0 md5
host all all 127.0.0.1/32 md5
# 在pg_hba.conf添加本地账户为ident
local all all ident map=map_root
配置pg_ident.conf 中添加映射,将本地root账户映射为pgsql管理员账户postgres
这样就能够在root中使用postgresql
[root@hadoop100 data]# vi pg_ident.conf
在文件最后一行
map_root root postgres
# 启动程序
先进入这个文件夹
[root@hadoop100 start-scripts]# cd /pgsql/postgresql/postgresql-11.1/contrib/start-scripts
[root@hadoop100 start-scripts]# cp linux /etc/init.d/postgresql
# 修改启动配置文件
[root@hadoop100 start-scripts]# vi /etc/init.d/postgresql
文件内容:
# Installation prefix
prefix=/pgsql/postgresql
# Data directory
PGDATA="/pgsql/postgresql/data"
# 设置postgresql服务开机自启动
[root@hadoop100 start-scripts]# cd /etc/init.d/
[root@hadoop100 init.d]# chkconfig --add postgresql
[root@hadoop100 init.d]# chkconfig
[root@hadoop100 init.d]# service postgresql start
[root@hadoop100 init.d]# psql -Upostgres
# 设置密码
postgres=# ALTER USER postgres WITH PASSWORD 'postgres123';
如果启动失败 可以在这里查看日志 然后gpt 或百度都可以
[root@hadoop100 data]# cat /pgsql/postgresql/data/logfile.log