运维开发技术交流群欢迎大家加入一起学习(QQ:722381733)

一、postgresql数据库部署

  1、前往postgresql安装包的目录(这里我部署的是10.5的版本)

[root@web1 ~]# cd /package/
[root@web1 package]# ls
apache-tomcat-8.5..tar.gz jdk-8u131-linux-x64.tar.gz postgresql-10.5.tar.gz redis-3.2..tar.gz
[root@web1 package]#

  2、解压缩包

[root@web1 package]# tar xf postgresql-10.5.tar.gz
[root@web1 package]# ls
apache-tomcat-8.5..tar.gz jdk-8u131-linux-x64.tar.gz postgresql-10.5 postgresql-10.5.tar.gz redis-3.2..tar.gz
[root@web1 package]#

  3、进入解压后生成的目录文件进行编译

[root@web1 postgresql-10.5]# ./configure --prefix=/usr/local/pgsql-10.5
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether NLS is wanted... no
checking for default port number...
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for WAL segment size... 16MB

  4、提示如下信息是缺少包文件

checking for library containing readline... no
configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure. It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.

  5、安装相应的包文件文件

[root@web1 postgresql-10.5]#yum install ncurses* readline* zlib* -y
######################################
[root@web1 postgresql-10.5]# rpm -aq ncurses* readline* zlib*
readline-devel-6.2-.el7.x86_64
zlib-static-1.2.-.el7.x86_64
ncurses-libs-5.9-14.20130511.el7_4.x86_64
ncurses-devel-5.9-14.20130511.el7_4.x86_64
readline-static-6.2-.el7.x86_64
zlib-devel-1.2.-.el7.x86_64
readline-6.2-.el7.x86_64
ncurses-base-5.9-14.20130511.el7_4.noarch
ncurses-5.9-14.20130511.el7_4.x86_64
zlib-1.2.-.el7.x86_64
[root@web1 postgresql-10.5]#

  6、安装完成后重新编译下

[root@web1 postgresql-10.5]# ./configure --prefix=/usr/local/pgsql-10.5
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether NLS is wanted... no
checking for default port number...
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for WAL segment size... 16MB
checking for gcc... gcc

  7、解析文件(在postgresql-10.5目录执行:make install),最后输出结果没提示异常【error】便可开始安装了

rm -f pg_regress.o && ln -s ../../../src/test/regress/pg_regress.o .
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -Wl,--as-needed -Wl,-rpath,'/usr/local/pgsql-10.5/lib',--enable-new-dtags -lpgcommon -lpgport -lpthread -lz -lreadline -lrt -lcrypt -ldl
make[]: Leaving directory `/package/postgresql-10.5/src/test/isolation'
make -C test/perl all
make[]: Entering directory `/package/postgresql-10.5/src/test/perl'
make[]: Nothing to be done for `all'.
make[]: Leaving directory `/package/postgresql-10.5/src/test/perl'
make[]: Leaving directory `/package/postgresql-10.5/src'
make -C config all
make[]: Entering directory `/package/postgresql-10.5/config'
make[]: Nothing to be done for `all'.
make[]: Leaving directory `/package/postgresql-10.5/config'
All of PostgreSQL successfully made. Ready to install.

  8、开始安装(在postgresql-10.5目录执行:make install),最后输出结果没提示异常【error】便表示安装成功

/bin/install -c -m  Makefile.global '/usr/local/pgsql-10.5/lib/pgxs/src/Makefile.global'
/bin/install -c -m Makefile.port '/usr/local/pgsql-10.5/lib/pgxs/src/Makefile.port'
/bin/install -c -m ./Makefile.shlib '/usr/local/pgsql-10.5/lib/pgxs/src/Makefile.shlib'
/bin/install -c -m ./nls-global.mk '/usr/local/pgsql-10.5/lib/pgxs/src/nls-global.mk'
make[]: Leaving directory `/package/postgresql-10.5/src'
make -C config install
make[]: Entering directory `/package/postgresql-10.5/config'
/bin/mkdir -p '/usr/local/pgsql-10.5/lib/pgxs/config'
/bin/install -c -m ./install-sh '/usr/local/pgsql-10.5/lib/pgxs/config/install-sh'
/bin/install -c -m ./missing '/usr/local/pgsql-10.5/lib/pgxs/config/missing'
make[]: Leaving directory `/package/postgresql-10.5/config'
PostgreSQL installation complete.

  9、安装完成后可以看到在/usr/local目录上成了pgsql-10.5目录

[root@web1 postgresql-10.5]# ll /usr/local/ |grep pgsql-10.5
drwxr-xr-x root root May : pgsql-10.5
[root@web1 postgresql-10.5]#

  10、创建用户及设置/usr/local/pgsql-10.5目录文件属主组

[root@web1 postgresql-10.5]# useradd postgres
[root@web1 postgresql-10.5]# chown -R postgres.postgres /usr/local/pgsql-10.5/
[root@web1 postgresql-10.5]# ll /usr/local/ |grep pgsql-10.5
drwxr-xr-x postgres postgres May : pgsql-10.5
[root@web1 postgresql-10.5]#

  11、给/usr/local/pgsql-10.5目录设置软连接(方便查看和管理吧....)

[root@web1 postgresql-10.5]# ln -s /usr/local/pgsql-10.5/ /usr/local/pgsql
[root@web1 postgresql-10.5]# ll /usr/local/pgsql
lrwxrwxrwx root root May : /usr/local/pgsql -> /usr/local/pgsql-10.5/
[root@web1 postgresql-10.5]#

  12、进入刚创建的postgres用户

[root@web1 postgresql-10.5]# su postgres
[postgres@web1 postgresql-10.5]$

  13、设置环境变量(注意路径)

[postgres@web1 ~]$ 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
export PATH=$PATH:/usr/local/pgsql-10.5/bin
PGDATA=/usr/local/pgsql-10.5/data
export PGDATA
export PATH

  14、当前生效

[postgres@web1 ~]$ source ~/.bash_profile
[postgres@web1 ~]$

  15、测试

[postgres@web1 ~]$ which psql
/usr/local/pgsql-10.5/bin/psql
[postgres@web1 ~]$ psql -V
psql (PostgreSQL) 10.5

  16、初始化数据库(initdb --help查看讲情),指定库文件路径

[postgres@web1 ~]$ initdb /usr/local/pgsql-10.5/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process. The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english". Data page checksums are disabled. creating directory /usr/local/pgsql-10.5/data ... ok
creating subdirectories ... ok
selecting default max_connections ...
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb. Success. You can now start the database server using: pg_ctl -D /usr/local/pgsql-10.5/data -l logfile start [postgres@web1 ~]$

***在此就已经部署成功了,现在要做的就是修改下配置文件,优化下***

  17、前往文件安装所在地,修改pg_hba.conf配置文件

[postgres@web1 data]$ cp pg_hba.conf pg_hba.conf.`date +%F`
[postgres@web1 data]$ vim pg_hba.conf
#######################################
# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
#host all all 127.0.0.1/ trust
host all all 0.0.0.0/ md5 #所有ip都可以通过密码连接
# IPv6 local connections:
host all all ::/ trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/ trust
######################################

  18、前往文件安装所在地,修改postgresql.conf配置文件

[postgres@web1 data]$ cd /usr/local/pgsql/data/
[postgres@web1 data]$ cp postgresql.conf postgresql.conf.`date +%F`
[postgres@web1 data]$ vim postgresql.conf
#########################################
# - Connection Settings - listen_addresses = '*' #为了方便,监听所有# what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
#port = # (change requires restart)
max_connections = # (change requires restart)
#superuser_reserved_connections = # (change requires restart)
#unix_socket_directories = '/tmp' # comma-separated list of directories
# (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = # begin with to use octal notation
#########################################

  19、创建log目录用于存放开机日志,及启动数据库

[postgres@web1 data]$ mkdir /usr/local/pgsql/log
[postgres@web1 data]$ pg_ctl start -l /usr/local/pgsql-10.5/log/pg_server.log
waiting for server to start.... done
server started
[postgres@web1 data]$

  20、检查是否启动,可以看日志

[postgres@web1 data]$ lsof -i:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres postgres 3u IPv4 0t0 TCP *:postgres (LISTEN)
postgres postgres 4u IPv6 0t0 TCP *:postgres (LISTEN)
[postgres@web1 data]$ netstat -lnutp|grep postgres
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0.0.0.0: 0.0.0.0:* LISTEN /postgres
tcp6 ::: :::* LISTEN /postgres
[postgres@web1 data]$ ps -ef|grep postgres
root : pts/ :: su postgres
postgres : pts/ :: bash
postgres : pts/ :: /usr/local/pgsql-10.5/bin/postgres
postgres : ? :: postgres: checkpointer process
postgres : ? :: postgres: writer process
postgres : ? :: postgres: wal writer process
postgres : ? :: postgres: autovacuum launcher process
postgres : ? :: postgres: stats collector process
postgres : ? :: postgres: bgworker: logical replication launcher
postgres : pts/ :: ps -ef
postgres : pts/ :: grep --color=auto postgres
[postgres@web1 data]$

  21、进入库的一些小操作

[postgres@web1 data]$ psql    #进入库
psql (10.5)
Type "help" for help. postgres=# \password #设置密码
Enter new password:
Enter it again:
postgres=# CREATE DATABASE name; #创建库
CREATE DATABASE
postgres=# \du #查看用户
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {} postgres=#
postgres=# \l #查看数据库列表
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
name | postgres | UTF8 | en_US.UTF- | en_US.UTF- |
postgres | postgres | UTF8 | en_US.UTF- | en_US.UTF- |
template0 | postgres | UTF8 | en_US.UTF- | en_US.UTF- | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF- | en_US.UTF- | =c/postgres +
| | | | | postgres=CTc/postgres
( rows) postgres=#
postgres=# create user test superuser password ''; #创建用户及密码
CREATE ROLE
postgres=#

*****到此就大致部署完了,如有什么问题以及不足之处,欢迎读客在线批评****

postgresql数据库部署的更多相关文章

  1. postGreSQL数据库部署及简单使用

    1,deployByRuiyIns rpm -ivh http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.no ...

  2. Postgresql数据库部署之:Postgresql本机启动和Postgresql注册成windows 服务

    1.初始化并创建数据库(一次即可)  initdb \data --locale=chs -U postgres -W  You can now start the database server u ...

  3. Linux下postgresql数据库部署与配置

    1.检查postgresql是否已经安装:rpm -qa | grep postgres 2.检查PostgreSQL 安装位置:rpm -qal | grep postgres 3.卸载Postgr ...

  4. PostgreSQL数据库部署之 :PostgreSQL pgadmin4 the application server could not be contacted

    遇到问题: 尝试了删除c:\Users\your_name\AppData\Roaming\pgAdmin 之内的删除所有文件和文件夹, 然后在C:\Program Files\PostgreSQL\ ...

  5. Postgresql数据库部署之:Postgresql 存在session 会话不能删除数据库

    SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='数据库名' AND pid<>pg_backen ...

  6. SpringBoot应用和PostgreSQL数据库部署到Kubernetes上的一个例子

    创建一个名为ads-app-service的服务: 上述Service的yaml文件里每个字段,在Kubernetes的API文档里有详细说明. https://kubernetes.io/docs/ ...

  7. Linux:获取Linux离线postgresql数据库安装包并部署

    获取离线安装包(方法一) 1. 进入官网:https://www.postgresql.org/ 2. 下载步骤 (1)点击Download (2) 选择安装的服务器的版本  (3)更新yum源 #更 ...

  8. 从运维的角度分析使用阿里云数据库RDS的必要性--你不应该在阿里云上使用自建的MySQL/SQL Server/Oracle/PostgreSQL数据库

    开宗明义,你不应该在阿里云上使用自建的MySQL or SQL Server数据库,对了,还有Oracle or PostgreSQL数据库. 云数据库 RDS(Relational Database ...

  9. 基于telegraf+influxdb+grafana进行postgresql数据库监控

    前言 随着公司postgresql数据库被广泛应用,尤其是最近多个项目在做性能测试的时候都是基于postgresql的数据库,为了确定性能瓶颈是否会出现在数据库中,数据库监控也被我推上了日程.在网上找 ...

随机推荐

  1. 5分钟Serverless实践 | 构建无服务器图片鉴黄Web应用

    Serverless是什么 Serverless中文译为“无服务器”,最早可以追溯到2012年Ken Fromm发表的<Why The Future Of Software And Apps I ...

  2. GTK经常使用控件之笔记本控件( GtkNotebook )

    笔记本控件,能够让用户标签式地切换多个界面. 当我们须要多窗体切换时,使用笔记本控件是一个明智的选择. 笔记本控件的创建: GtkWidget *gtk_notebook_new(void); 返回值 ...

  3. 调用线程必须为 STA,因为许多 UI 组件都需要

    WPF中,代码中准备控制控件内容时,有时会报错: 调用线程必须为 STA,因为许多 UI 组件都需要 我知道,在winform下面,使用多线程时,控件的值读取是可以的,但如果要更改,那么就必须进行一些 ...

  4. java 定位工具

    #查看JVM所有进程及启动类信息以及PID jps -mlvV #查看JVM运行各种状态信息,包括GC,类加载,堆内存信息,jit编译信息等jstat -gcutil <PID> (堆内存 ...

  5. Mysql的简单使用(二)

    接上文Mysql的简单使用(一) 字段参数以“(字段名1 数据类型1,字段名2 数据类型2,......)”的形式构建. 关于mysql常用的数据类型,一下是比较常用的几种,想查阅比较详细的资料可以自 ...

  6. 49.Ext.form.TextField()基本用法

    转自:https://blog.csdn.net/toudoulin/article/details/6719163 var textfieldName = new Ext.form.TextFiel ...

  7. PCB genesis Slot槽转钻孔(不用G85命令)实现方法

    PCB钻Slot槽一般都采用G85命令钻槽孔,而采用G85命令工程CAM无法准确的知道Slot槽钻多少个孔,并不能决定钻槽孔的顺序,因为采用G85命令钻孔密度与钻槽顺序由钻机本身决定的.在这里介绍一种 ...

  8. ural 1017. Staircases(dp)

    http://acm.timus.ru/problem.aspx?space=1&num=1017 题意:有n块砖,要求按照严格递增的个数摆放成楼梯,求楼梯的摆放种类数. 思路:状态转移方程: ...

  9. 解决微信H5页面软键盘弹起后页面下方留白的问题(iOS端)

    前言:微信H5项目,ios端出现了软键盘输完隐藏后页面不会回弹,下方会有一大块留白 最近微信和ios都有版本升级,不知道是哪边升级造成的,但是经过测试,软键盘收起后,再滚动一下页面,下面的留白就会消失 ...

  10. Eclipse 添加 YAML插件

    官网:https://github.com/oyse/yedit 离线版本:(链接: https://pan.baidu.com/s/1PJzkS1tI-VigZvfbYXUh9A 密码: gfep) ...