设为首页 收藏本站
查看: 1042|回复: 0

[经验分享] Debian6.04 Postgresql

[复制链接]

尚未签到

发表于 2018-5-15 09:37:56 | 显示全部楼层 |阅读模式
  前言:本人机器:AMD64x2 4400++ 1G 内存
                           
第一阶段-编译安装:
1,从postgresql官网下载postgresql-9.1.3.tar.bz2这个我想大家都知道的
2,把源代码复制到/usr/src/postgresql-9.1.3.tar.bz2 且 cd /usr/src
3,解压: tar xjvf postgresql-9.1.3.tar.bz2
4,进入源码目录: cd postgresql-9.1.3
5,建立pgsql安装目录。这里我选择 :mkdir /usr/pgsql-9.1.3
6,安装必须的工具执行:aptitude install build-essential zlib1g-dev libpam0g-dev libssl-dev libperl-dev kernel-package libncurses5-dev flex bison gawk chkconfig系统会自动安装所以来的软件
7,在源码目录里面执行下面命令:
./configure   CFLAGS='-DLINUX_OOM_ADJ=0 -O2 -pipe -march=athlon64 -fomit-frame-pointer -fstack-protector' --prefix=/usr/pgsql-9.1.3 --with-perl --with-openssl --with-pam --enable-nls --disable-debug
8,开始编译 :make -j 4
9,变成成功后,执行 make install 安装
10,建立postgresql数据库专用普通权限用户 :adduser psqlroot
11,切换到安装目录: cd /usr/pgsql-9.1.3建立初始化数据库集群文件夹:mkdir date
12,改变date所有权限 chown psqlroot:psqlroot date
13,执行数据库初始化(必须使用psqlroot用户):su - psqlroot -c './initdb /usr/pgsql-9.1.3/date'
14,好了,进入date目录可以看到初始化后的文件,比如conf配置文件等等。
  第二阶段-制作启动脚本:
1,从源代码目录里面复制出原始的开机脚本:
cp /usr/src/postgresql-9.1.3/contrib/start-scripts/linux    /etc/init.d/postgresql
2,给予执行权限:chmod 700 /etc/init.d/postgresql
3,建立s 2 3 4 5 6各个级别启动连接在(/etc/rcS.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d)
   使用:chkconfig /etc/init.d/postgresql自动建立 呵呵很方便哦!
4,修改/etc/init.d/postgresql文件,这个文件是用/bin/sh基础的,改成/bin/bash的:
  #! /bin/bash
  # 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=/usr/pgsql-9.1.3
  # Data directory
PGDATA=$PREFIX/date
  # Who to run the postmaster as, usually &quot;postgres&quot;.  (NOT &quot;root&quot;)
PGUSER=psqlroot
  # Where to keep a log file
PGLOG=/var/log/serverlog
  # It's often a good idea to protect the postmaster from being killed by the
# OOM killer (which will tend to preferentially kill the postmaster because
# of the way it accounts for shared memory).  Setting the OOM_ADJ value to
# -17 will disable OOM kill altogether.  If you enable this, you probably want
# to compile PostgreSQL with &quot;-DLINUX_OOM_ADJ=0&quot;, so that individual backends
# can still be killed by the OOM killer.
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 &quot;pg_ctl start -w&quot; here.
# But without -w, pg_ctl adds no value.)
DAEMON=&quot;$PREFIX/bin/postmaster&quot;
  # What to use to shut down the postmaster
PGCTL=&quot;$PREFIX/bin/pg_ctl&quot;
  set -e
  # Only start if we can find the postmaster.
test -x $DAEMON ||
{
echo &quot;$DAEMON not found&quot;
if [ &quot;$1&quot; = &quot;stop&quot; ]
then exit 0
else exit 5
fi
}
  
# Parse command line parameters.
case $1 in
  start)
echo -n &quot;Starting PostgreSQL: &quot;
test x&quot;$OOM_ADJ&quot; != x && echo &quot;$OOM_ADJ&quot; > /proc/self/oom_adj
su - $PGUSER -c &quot;$DAEMON -D $PGDATA &&quot; >>$PGLOG 2>&1
echo &quot;ok&quot;
;;
  stop)
echo -n &quot;Stopping PostgreSQL: &quot;
su - $PGUSER -c &quot;$PGCTL stop -D '$PGDATA' -s -m fast&quot;
echo &quot;ok&quot;
;;
  restart)
echo -n &quot;Restarting PostgreSQL: &quot;
su - $PGUSER -c &quot;$PGCTL stop -D '$PGDATA' -s -m fast -w&quot;
test x&quot;$OOM_ADJ&quot; != x && echo &quot;$OOM_ADJ&quot; > /proc/self/oom_adj
su - $PGUSER -c &quot;$DAEMON -D '$PGDATA' &&quot; >>$PGLOG 2>&1
echo &quot;ok&quot;
;;
  reload)
        echo -n &quot;Reload PostgreSQL: &quot;
        su - $PGUSER -c &quot;$PGCTL reload -D '$PGDATA' -s&quot;
        echo &quot;ok&quot;
        ;;
  status)
su - $PGUSER -c &quot;$PGCTL status -D '$PGDATA'&quot;
;;
  *)
# Print help
echo &quot;Usage: $0 {start|stop|restart|reload|status}&quot; 1>&2
exit 1
;;
esac
  exit 0
  5,注意上文提到的OOM_ADJ=-17 是为了逃避OOM自动封杀,OK!执行/etc/init.d/postgresql start stop restart 等等命令试试,大工告成!!
6,把安装目录中的conf配置文件复制到/etc/postgresql下面去,方便以后更改配置
  mkdir /etc/postgresql
  mv /usr/pgsql-9.1.3/date/*conf /etc/postgresql/
  cd /usr/pgsql-9.1.3/date
  su - psqlroot -c 'ln -s /etc/postgresql/pg_hba.conf pg_hba.conf'
  su - psqlroot -c 'ln -s /etc/postgresql/pg_ident.conf pg_ident.conf'
  su - psqlroot -c 'ln -s /etc/postgresql/postgresql.conf postgresql.conf'
  第三阶段-优化:-----下回分解

运维网声明 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-460326-1-1.html 上篇帖子: Debian安装JDK 下篇帖子: debian6安装后中文乱码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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