设为首页 收藏本站
查看: 1371|回复: 1

[经验分享] Centos源码编译安装postgresql

[复制链接]

尚未签到

发表于 2018-4-27 11:57:48 | 显示全部楼层 |阅读模式
  系统平台:CentOS release 6.5 (Final)
  PostgreSQL 版本:PostgreSQL 9.4.3
  防火墙已关闭/iptables: Firewall is not running.
  SELINUX=disabled
  三、源码安装
  1. 下载PostgreSQL 源码包
  # wget http://ftp.postgresql.org/pub/source/v9.4.3/postgresql-9.4.3.tar.bz2
  2. 解压源码包
  # tar xjf postgresql-9.4.3.tar.bz2
  3. 进入解压后的目录
  # cd postgresql-9.4.3
  4.安装依赖包
  yum -y install gcc*
  yum -y install readline-devel
  5.增加用户设置密码
[root@postgresql ~]# adduser postgres

[root@postgresql ~]# passwd postgres

  Changing password for user postgres.
  New password:
  BAD PASSWORD: it is too simplistic/systematic
  BAD PASSWORD: is too simple
  Retype new password:
  passwd: all authentication tokens updated successfully.
  6.开始编译安装PostgreSQL 数据库。
[root@postgresql ~]# cd postgresql-9.4.3

[root@postgresql postgresql-9.4.3]# ./configure --prefix=/home/postgres/pgsql

[root@postgresql postgresql-9.4.3]# gmake

[root@postgresql postgresql-9.4.3]# gmake install

  7.设置环境变量
[root@postgresql ~]# cd /home/postgres/

[root@postgresql postgres]# ls

  pgsql
[root@postgresql postgres]# vi .bash_profile

  把 PATH=$PATH:$HOME/bin
  改成 PATH=$PATH:$HOME/bin:/home/postgres/pgsql/bin
  保存退出。
  让环境变量生效:
  在设置
[root@postgresql ~]# vi .bash_profile

  把 PATH=$PATH:$HOME/bin
  改成 PATH=$PATH:$HOME/bin:/home/postgres/pgsql/bin
  保存退出。
  让环境变量生效:
[root@postgresql ~]# source .bash_profile

  8.初始化数据库
  8.1新建数据目录
[root@postgresql ~]# mkdir /home/postgres/pgsql/data

  8.2更改权限
[root@postgresql ~]# chown postgres:postgres /home/postgres/pgsql/data

  8.3切换到postgres用户
[root@postgresql ~]# su - postgres

  8.4 init db
[postgres@postgresql ~]$ /home/postgres/pgsql/bin/initdb -D /home/postgres/pgsql/data

  到这里数据的初始化就完成
  9.系统服务
  9.1回到root用户
[postgres@postgresql ~]$ exit

  9.2复制安装目录下的linux文件到/etc/init.d/
  进入postgresql 的安装目录(即刚刚使用tar命令解压的目录)
[root@postgresql ~]# cd postgresql-9.4.3

[root@postgresql postgresql-9.4.3]# cp contrib/start-scripts/linux /etc/init.d/postgresql

  9.3修改/etc/init.d/postgresql  注意:上面创建的目录对应到下面的相关目录
[root@postgresql postgresql-9.4.3]# vi /etc/init.d/postgresql

  #! /bin/sh
  # chkconfig: 2345 98 02
  # description: PostgreSQL RDBMS
  # This is an example of a start/stop script for SysV-style init, such
  # as is used on Linux systems.  You should edit some of the variables
  # and maybe the 'echo' commands.
  #
  # Place this file at /etc/init.d/postgresql (or
  # /etc/rc.d/init.d/postgresql) and make symlinks to
  #  /etc/rc.d/rc0.d/K02postgresql
  #  /etc/rc.d/rc1.d/K02postgresql
  #  /etc/rc.d/rc2.d/K02postgresql
  #  /etc/rc.d/rc3.d/S98postgresql
  #  /etc/rc.d/rc4.d/S98postgresql
  #  /etc/rc.d/rc5.d/S98postgresql
  # Or, if you have chkconfig, simply:
  # chkconfig --add postgresql
  #
  # Proper init scripts on Linux systems normally require setting lock
  # and pid files under /var/run as well as reacting to network
  # settings, so you should treat this with care.
  # Original author:  Ryan Kirkpatrick <pgsql@rkirkpat.net>
  # contrib/start-scripts/linux
  ## EDIT FROM HERE
  # Installation prefix
  prefix=/home/postgres /pgsql
  # Data directory
  PGDATA="/home/postgres/pgsql/data"
  # Who to run the postmaster as, usually "postgres".  (NOT "root")
  PGUSER=postgres
  # Where to keep a log file
  PGLOG="$PGDATA/serverlog"

  # It's often a good>  # OOM killer (which will tend to preferentially kill the postmaster because
  # of the way it accounts for shared memory).  Setting the OOM_SCORE_ADJ value

  # to -1000 will disable OOM kill>  # want to compile PostgreSQL with "-DLINUX_OOM_SCORE_ADJ=0", so that
  # individual backends can still be killed by the OOM killer.
  #OOM_SCORE_ADJ=-1000
  # Older Linux kernels may not have /proc/self/oom_score_adj, but instead
  # /proc/self/oom_adj, which works similarly except the disable value is -17.
  # For such a system, enable this and compile with "-DLINUX_OOM_ADJ=0".
  #OOM_ADJ=-17
  ## STOP EDITING HERE
  # The path that is to be used for the script
  PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  # What to use to start up the postmaster.  (If you want the script to wait
  # until the server has started, you could use "pg_ctl start -w" here.
  # But without -w, pg_ctl adds no value.)
  DAEMON="$prefix/bin/postmaster"
  # What to use to shut down the postmaster
  PGCTL="$prefix/bin/pg_ctl"
  set -e
  # Only start if we can find the postmaster.
  test -x $DAEMON ||
  {
  echo "$DAEMON not found"
  if [ "$1" = "stop" ]
  then exit 0
  else exit 5
  fi
  }
  # Parse command line parameters.
  case $1 in
  start)
  echo -n "Starting PostgreSQL: "
  test x"$OOM_SCORE_ADJ" != x && echo "$OOM_SCORE_ADJ" > /proc/self/oom_score_adj
  test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
  su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
  echo "ok"
  ;;
  stop)
  echo -n "Stopping PostgreSQL: "
  su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast"
  echo "ok"
  ;;
  restart)
  echo -n "Restarting PostgreSQL: "
  su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
  test x"$OOM_SCORE_ADJ" != x && echo "$OOM_SCORE_ADJ" > /proc/self/oom_score_adj
  test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
  su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
  echo "ok"
  ;;

  >  echo -n "Reload PostgreSQL: "

  su - $PGUSER -c "$PGCTL>  echo "ok"
  ;;
  status)
  su - $PGUSER -c "$PGCTL status -D '$PGDATA'"
  ;;
  *)
  # Print help
  echo "Usage: $0 {start|stop|restart|reload|status}" 1>&2
  exit 1
  ;;
  esac
  exit 0
  9.4添加执行权限
[root@postgresql postgresql-9.4.3]# chmod +x /etc/init.d/postgresql

  9.5启动数据库
[root@postgresql postgresql-9.4.3]# /etc/init.d/postgresql start

  Starting PostgreSQL: ok
  9.6让数据库开机启动
[root@postgresql postgresql-9.4.3]# chkconfig --add postgresql

[root@postgresql postgresql-9.4.3]# chkconfig postgresql on

  9.7创建数据库操作历史记录文件
[root@postgresql postgresql-9.4.3]# touch /home/postgres/pgsql/.pgsql_history

[root@postgresql postgresql-9.4.3]# chown postgres:postgres /home/postgres/pgsql/.pgsql_history

  开启远程连接
  $ cd /mnt/data/pgsql/
  $ vi pg_hba.conf
  # IPv4 local connections:
  host    all             all             0.0.0.0/0               trust
  这是开放权限的模式,也就是没有认证的,如果是需要账号密码的认证,请使用md5的模式
  $ vi postgresql.conf
  listen_addresses = '*',允许所有的网络主机连接
  10.测试使用
[root@postgresql postgresql-9.4.3]# su - postgres

[postgres@postgresql ~]$ createdb test

[postgres@postgresql ~]$ psql test

  psql (9.4.3)
  Type "help" for help.
  test=#
  源码编译安装成功。
  如果有防火墙的话,请做如下配置
  配置防火墙
  $ su - root
  # vi /etc/sysconfig/iptables
  -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT(此是web服务的配置,请忽略)
  -A INPUT -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT
  # service iptables restart

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-452713-1-1.html 上篇帖子: centos6.5 cobbler 安装部署 下篇帖子: centos 7的yum安装及rhel 7的yum源替换为centos 7的yum源
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表