PostgreSQL 9.6.1 for CentOS 6.8 安装--优化编译

前端之家收集整理的这篇文章主要介绍了PostgreSQL 9.6.1 for CentOS 6.8 安装--优化编译前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
# Postgresql 9.6.1 for CentOS 6.8 优化编译安装
#作者:老农民
#QQ: 46715422
#Email: flyingercn@wo.cn
#微信: ericliu_77

# 此处借用了之前德哥的编译建议,另外关于参数设置等,请自行参考德哥的建议,这里将使用最新gcc 和 python2.7,至于本脚本编译安装过程,就不注释了,基础知识自行恶补吧。

# 安装 GCC6.3 最新版
yum -y install glibc-devel.i686 glibc-devel ncurses ncurses-devel zlib-devel bzip2-devel openssl-devel readline-devel sqlite-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel texinfo bison flex

tar xf gcc-6.3.0.tar.bz2
cd gcc-6.3.0/
./contrib/download_prerequisites
mkdir gcc-build-6.3.0
cd gcc-build-6.3.0
../configure --prefix=/usr/local/gcc6 --enable-checking=release --enable-languages=c,c++ --enable-threads=posix --disable-multilib --disable-libunwind-exceptions --enable-bootstrap --with-system-zlib --with-arch=i686 --build=i686-redhat-linux
make -j8
make install
cd ../../

echo "/usr/local/lib" > /etc/ld.so.conf.d/local.conf
echo "/usr/local/gcc6/lib" > /etc/ld.so.conf.d/gcc6.conf
/sbin/ldconfig

# 安装 Python 2.7.13 最新版
yum -y install zlib-devel bzip2-devel openssl-devel readline-devel ncurses-devel sqlite-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

xz -d Python-2.7.13.tar.xz
tar xf Python-2.7.13.tar
cd Python-2.7.13/
export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/gcc6/lib:/usr/local/python27/lib:/lib:/usr/lib:/lib64:/usr/lib64:/usr/local/lib64:$LD_LIBRARY_PATH
export PATH=/usr/local/bin:/usr/local/gcc6/bin:/usr/local/python27/bin:$PATH:.
CC="/usr/local/gcc6/bin/gcc" ./configure --prefix=/usr/local/python27 --enable-shared
CC="/usr/local/gcc6/bin/gcc" make -j `grep processor /proc/cpuinfo | wc -l`
CC="/usr/local/gcc6/bin/gcc" make install
cd ../

vi ~/env.sh
alias cc=/usr/local/gcc6/bin/gcc
alias gcc=/usr/local/gcc6/bin/gcc
alias c++=/usr/local/gcc6/bin/c++
alias g++=/usr/local/gcc6/bin/g++
alias cpp=/usr/local/gcc6/bin/cpp
export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/gcc6/lib:/usr/local/python27/lib:/lib:/usr/lib:/lib64:/usr/lib64:/usr/local/lib64:$LD_LIBRARY_PATH
export PATH=/usr/local/bin:/usr/local/gcc6/bin:/usr/local/python27/bin:$PATH:.

echo "/usr/local/python27/lib" > /etc/ld.so.conf.d/python27.conf
/sbin/ldconfig


# 安装Postgresql 9.6.1 
#添加可能需要个包
yum -y install autoconf libjpeg libjpeg-devel libpng libpng-devel libtool-ltdl libtool-ltdl-devel
yum -y install freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel
yum -y install bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel
yum -y install libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers openldap-devel
yum -y install libtiff libtiff-devel gettext gettext-devel libc-client libc-client-devel readline readline-devel pam pam-devel perl-ExtUtils-Embed uuid uuid-devel tcl-devel
yum -y install coreutils glib2 lrzsz mpstat dstat sysstat e4fsprogs xfsprogs ntp readline-devel zlib-devel openssl-devel pam-devel libxml2-devel libxslt-devel python-devel tcl-devel gcc make smartmontools flex bison perl-devel perl-ExtUtils* openldap-devel

# 使用最新环境编译
. ~/env.sh

#创建Postgresql用户和组
/usr/sbin/groupadd postgres
/usr/sbin/useradd -r -g postgres -s /bin/false -M postgres
mkdir /home/postgres

mkdir -p /home/postgresdata
chmod +w /home/postgresdata
chown -R postgres:postgres /home/postgresdata

tar xf postgresql-9.6.1.tar.bz2
cd postgresql-9.6.1/
export USE_NAMED_POSIX_SEMAPHORES=1
LIBS=-lpthread CC="/usr/local/gcc6/bin/gcc" CFLAGS="-O3 -flto" ./configure --prefix=/home/pgsql  --enable-nls="zh_CN zh_TW" --with-perl --with-python --with-tcl --with-uuid=ossp --with-gssapi --with-pam --with-ldap --with-openssl --with-libxml --enable-thread-safety --with-zlib --without-selinux --with-readline --with-pgport=5432
LIBS=-lpthread CC="/usr/local/gcc6/bin/gcc" CFLAGS="-O3 -flto" make world -j `grep processor /proc/cpuinfo | wc -l`
LIBS=-lpthread CC="/usr/local/gcc6/bin/gcc" CFLAGS="-O3 -flto" make install-world
cd contrib/
LIBS=-lpthread CC="/usr/local/gcc6/bin/gcc" CFLAGS="-O3 -flto" make install clean
cd ../
cp -r contrib/ /home/pgsql/contrib
ln -s  /home/postgresdata /home/pgsql/data
chown -R postgres:postgres /home/pgsql/data
chown -R postgres:postgres /home/postgres
su -l postgres -s /bin/bash -c "/home/pgsql/bin/initdb --locale=C -E UTF8 -D /home/pgsql/data/"

sed -i "s#\#listen_addresses = 'localhost'#listen_addresses = '*'#" /home/pgsql/data/postgresql.conf
sed -i 's#\#port = 5432#port = 5432#' /home/pgsql/data/postgresql.conf
cp contrib/start-scripts/linux /home/pgsql/bin/postgresql
ln -s /home/pgsql/lib/libpq.so.5 /usr/lib/libpq.so.5

sed -i 's#su - $PGUSER -c#su -l $PGUSER -s /bin/bash -c#' /home/pgsql/bin/postgresql
sed -i 's#/usr/local/pgsql#/home/pgsql#' /home/pgsql/bin/postgresql

ln -s /home/pgsql/bin/postgresql  /etc/init.d/postgresql
chmod +x /etc/init.d/postgresql
chkconfig --add postgresql
service postgresql start

#修改 postgres 密码为 postgres
su -l postgres -s /bin/bash -c "/home/pgsql/bin/psql"
postgres=# alter user postgres with password 'postgres';

echo "/home/pgsql/lib/" > /etc/ld.so.conf.d/pgsql.conf
/sbin/ldconfig

要买正宗新疆特产,微信扫下面二维码,加老农民咨询购买:

原文链接:https://www.f2er.com/postgresql/194161.html

猜你在找的Postgre SQL相关文章