m6米乐安卓版下载-米乐app官网下载
暂无图片
2
暂无图片
暂无图片
暂无图片

(二)postgresql学习:编译安装postgresql -m6米乐安卓版下载

原创 徐sir 2023-12-08
110

操作系统centos7.6

pg载地址:

下载路径:downloads–>source

选中你要下载的安装包,避开最新版本, 我这先选 15.5来进行安装。

下载最新的tar.gz安装包,(tar.bz2是解压需要系统安装bzip2软件包,与tar.gz包的区别就是压缩效率不一样这个更小)

tar.gz包的md5值为:

96175683748e68c7bb36ba0306adc8d7 postgresql-15.5.tar.gz

上传安装包至服务器,校验md5一致

2、修改主机名

hostnamectl set-hostname postgres

3、添加hosts文件

echo "192.168.100.101 `hostname`" >>/etc/hosts

4、配置本地yum源

rm -rf /etc/yum.repos.d/centos*
cat >/etc/yum.repos.d/local.repo<

这里需要把dvd挂载到/mnt

mount /dev/sr0 /mnt

如果你的环境里没有dvd光驱,可以准备个系统的iso文件dvd的,传到服务器上,执行如下挂载:

mount -o loop xxx.iso /mnt

挂载成功后显示如下

5、安装依赖环境包

uuid-devel-1.6.2-26.el7.x86_64.rpm需要单独下载,

在阿里镜像站

这个目录里下载 /centos-vault/7.6.1810/os/x86_64/packages/

yum -y install tcl tcl-devel uuid-devel perl-extutils-embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c   openssl-devel cmake gcc* readline-devel bison flex libicu-devel net-tools systemd-devel
yum install -y uuid-devel-1.6.2-26.el7.x86_64.rpm

6、创建用户,配置环境

这里没配置其它系统优化参数,以后再详细进行配置。

mkdir -p /u01/postgresql/data
useradd -u 1000 postgres
echo postgres | passwd --stdin postgres

–关闭selinux

sed -i "s/selinux=enforcing/selinux=disabled/g" /etc/selinux/config
setenforce 0

–配置postgre用户环境变量

cat >>/home/postgres/.bash_profile<

7、准备python

anaconda介绍

anaconda,中文大蟒蛇,是一个开源的python发行版本,其包含了conda、python等180多个科学包及其依赖项。其中,conda是一个开源的包、环境管理器,可以用于在同一个机器上安装不同版本的软件包及其依赖,并能够在不同的环境之间切换。

为什么要安装anaconda?

1、anaconda对于python初学者而言及其友好,相比单独安装python主程序,选择anaconda可以帮助省去很多麻烦,anaconda里添加了许多常用的功能包,如果单独安装python,这些功能包则需要一条一条自行安装,在anaconda中则不需要考虑这些,同时anaconda还附带捆绑了两个非常好用的交互式代码编辑器(spyder、jupyternotebook)。

2、如果我们不安装anaconda的话,我们安装第三方库就必须要用pip install xxx去安装,当我们安装的库多了,就会形成文件紊乱和繁杂问题。而且pip install方法会默认把库安装在同一个路径中,假如当你去做项目时,别人给你的程序用的库是低版本的,而你自己通过pip安装的是高版本的库,由于存在兼容问题,你的库不能运行该程序,而你也不可能为了这个而删去你的高版本的库去下载这个符合环境的低版本库吧,所以这及其繁琐和不方便。

软件下载地址:

下载完后,上传到服务器/root目录,使用root执行sh安装

sh anaconda3-2021.11-linux-x86_64.sh

需要执行如下操作

# 按enter
# 按空格
# 输入yes
# 输入 /export/anaconda3
# 输入yes
# 重启session

添加环境变量到/etc/profile

export anaconda_home=/export/anaconda3
export path=$path:$anaconda_home/bin

执行命令检查

conda info

配置环境,配置完,关闭终端,重新连接终端登录系统

[root@postgres postgresql-15.5\]# conda init no change /export/anaconda3/condabin/conda no change /export/anaconda3/bin/conda no change /export/anaconda3/bin/conda-env no change /export/anaconda3/bin/activate no change /export/anaconda3/bin/deactivate no change /export/anaconda3/etc/profile.d/conda.sh no change /export/anaconda3/etc/fish/conf.d/conda.fish no change /export/anaconda3/shell/condabin/conda.psm1 no change /export/anaconda3/shell/condabin/conda-hook.ps1 no change /export/anaconda3/lib/python3.9/site-packages/xontrib/conda.xsh no change /export/anaconda3/etc/profile.d/conda.csh modified /root/.bashrc ==> for changes to take effect, close and re-open your current shell. <== [root@postgres postgresql-15.5\]# conda create -n postgres python=3.9 collecting package metadata (current\_repodata.json): failed condahttperror: http 000 connection failed for url https://repo.anaconda.com/pkgs/main/linux-64/current\_repodata.json elapsed: - an http error occurred when trying to retrieve this url. http errors are often intermittent, and a simple retry will get you on your way. if your current network has https://www.anaconda.com blocked, please file a support request with your network engineering team. 'https://repo.anaconda.com/pkgs/main/linux-64'

8、检查make环境

官方要求postgresql 15编译安装要求

make version 3.81 or newer is required

这里说一下有的安装文档说是用gmake有的说是用make的,这里摘抄一下解释说明

gmake是gnu make的缩写。

linux系统环境下的make就是gnu make,之所以有gmake,是因为在别的平台上,make一般被占用,gnu make只好叫gmake了。

比如在安装二进制文件进行编译时要使用make命令,但如果在solaris或其他非gnu系统中运行,必须使用gnu make,而不是使用系统自带的make版本,这时要用gmake代替make进行编译。

solaris包含两种make工具:gcc (gnu compiler collection)工具套装包括一个 c 编译器和一个 c 编译器,solaris自身的 make 实用程序。

freebsd自带的make是bsd make。两者的不同在于makefile部分不兼容。即使是部分,有时候也不能完全把软件给make出来。

从下图也能看出来gmake指向的也是make,版本也是一致的,符合安装的基本要求。

9、开始安装

可以参考m6米乐安卓版下载官网的简易安装,我这里没用这个,要不后期有别的支持需要加入又得重新编译安装。

./configure make su make install adduser postgres mkdir -p /usr/local/pgsql/data chown postgres /usr/local/pgsql/data su - postgres /usr/local/pgsql/bin/initdb -d /usr/local/pgsql/data /usr/local/pgsql/bin/pg\_ctl -d /usr/local/pgsql/data -l logfile start /usr/local/pgsql/bin/createdb test /usr/local/pgsql/bin/psql test

我这里改动了下安装方式

解压安装包

tar -zxf postgresql-15.5.tar.gz

cd postgresql-15.5

进行配置、编译安

./configure --prefix=/u01/db/postgresql/ --with-openssl --with-pgport=5432 --with-tcl --with-perl --with-libxml --with-libxslt --with-uuid=ossp --with-pam --with-ldap --with-python --with-systemd

–配置完执行$?查看返回0表示完成,进行下一步安装

make world -j 8 && make install-world

其中-j 8是指多线程操作,加快编译速度;make world

make world 编译一切可以编译的东西,包括文档(html和手册)以及额外的模块(contrib)

这里说一下,编译的参数做个解释如下:

10、初始化数据库

chown -r postgres:postgres /u01/db

su - postgres

initdb -d $pgdata

返回结果

11、启动&停止数据库

–postgres用户执行,

pg_ctl -d /u01/postgresql/data -l logfile start

检查,会在当前目录下生成logfile文件

检查端口启动

查看数据库psql -l

停止数据库

pg_ctl -d /u01/db/postgresql/data -l logfile stop

12、配置系统服务

在源码的安装目录下/root/postgresql-15.5/contrib/start-scripts有个linux文件,里面为启动配置

脚本里需要修改的地方为

prefix=pg主目录

pgdata=" pgdata目录"

内容如下:

#! /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 
# contrib/start-scripts/linux
## edit from here
# installation prefix
prefix=/u01/db/postgresql
# data directory
pgdata="/u01/db/postgresql/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 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).  to do that, uncomment these
# three lines:
#pg_oom_adjust_file=/proc/self/oom_score_adj
#pg_master_oom_score_adj=-1000
#pg_child_oom_score_adj=0
# older linux kernels may not have /proc/self/oom_score_adj, but instead
# /proc/self/oom_adj, which works similarly except for having a different
# range of scores.  for such a system, uncomment these three lines instead:
#pg_oom_adjust_file=/proc/self/oom_adj
#pg_master_oom_score_adj=-17
#pg_child_oom_score_adj=0
## 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" here.)
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
}
# if we want to tell child processes to adjust their oom scores, set up the
# necessary environment variables.  can't just export them through the "su".
if [ -e "$pg_oom_adjust_file" -a -n "$pg_child_oom_score_adj" ]
then
    daemon_env="pg_oom_adjust_file=$pg_oom_adjust_file pg_oom_adjust_value=$pg_child_oom_score_adj"
fi
# parse command line parameters.
case $1 in
  start)
    echo -n "starting postgresql: "
    test -e "$pg_oom_adjust_file" && echo "$pg_master_oom_score_adj" > "$pg_oom_adjust_file"
    su - $pguser -c "$daemon_env $daemon -d '$pgdata' >>$pglog 2>&1 &"
    echo "ok"
    ;;
  stop)
    echo -n "stopping postgresql: "
    su - $pguser -c "$pgctl stop -d '$pgdata' -s"
    echo "ok"
    ;;
  restart)
    echo -n "restarting postgresql: "
    su - $pguser -c "$pgctl stop -d '$pgdata' -s"
    test -e "$pg_oom_adjust_file" && echo "$pg_master_oom_score_adj" > "$pg_oom_adjust_file"
    su - $pguser -c "$daemon_env $daemon -d '$pgdata' >>$pglog 2>&1 &"
    echo "ok"
    ;;
  reload)
    echo -n "reload postgresql: "
    su - $pguser -c "$pgctl reload -d '$pgdata' -s"
    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

修改完后,拷贝该文件到/etc/init.d目录下

cp linux /etc/init.d/postgresql

chmod x /etc/init.d/postgresql

之后可以通过

/etc/init.d/postgresql start 启动

/etc/init.d/postgresql stop 停止

/etc/init.d/postgresql status 查看状态

加到开机启动

chkconfig --add postgresql

chkconfig postgresql on

chkconfig --list

note: this output shows sysv services only and does not include native

systemd services. sysv configuration data might be overridden by native

systemd configuration.

if you want to list systemd services use ‘systemctl list-unit-files’.

to see services enabled on particular target use

‘systemctl list-dependencies [target]’.

netconsole 0:off1:off2:off3:off4:off5:off6:off

network 0:off1:off2:on3:on4:on5:on6:off

postgresql 0:off1:off2:on3:on4:on5:on6:off

重启查看是否开机自动启动,成功

问题

如不安装python高版本环境或anaconda ,使用系统自带的低版本python会报错

引用

教it的小强(博主) 

sqlboy-yuzhenc(博主) 

也欢迎关注我的公众号【徐sir的it之路】,一起学习!
————————————————————————————
公众号:徐sir的it之路
csdn :https://blog.csdn.net/xxddxhyz?type=blog
墨天轮:https://www.modb.pro/u/3605
pgfans:https://www.pgfans.cn/user/home?userid=5568
————————————————————————————


最后修改时间:2024-01-04 22:01:57
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论

网站地图