centos 6.8 + postgresql 9.6 + make

os 調整

# vi /etc/rc.local
#禁用透明大頁
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
   echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
   echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
#修改 io scheduler爲deadline
echo deadline > /sys/block/sda/queue/scheduler

修改後添加執行權限 chmod u+x /etc/rc.d/rc.local
或者修改grubhtml

# vi /etc/grub.conf
elevator=deadline numa=off transparent_hugepage=never

os 關閉selinux

永久修改
# vi /etc/sysconfig/selinux
SELINUX=DISABLED
或者  
# vi /etc/selinux/config
SELINUX=DISABLED

os 資源限制

修改文件句柄打開數和用戶最大進程數:
修改limit和max user processes
open files (-n) 40960
max user processes (-u) 7776 python

# vi /etc/security/limits.conf

root soft nofile  655360 # The maximum number of open file descriptors
root hard nofile  655360
postgres soft nofile  655360
postgres hard nofile  655360

root soft nproc   655360 # The maximum number of processes available to a single user
root hard nproc   655360
postgres soft nproc   655360 
postgres hard nproc   655360

* soft memlock unlimited # The maximum size that may be locked into memory
* hard memlock unlimited
* soft core    unlimited
* hard core    unlimited
* soft stack   unlimited  
* hard stack   unlimited

os 修改內核參數

# vi /etc/sysctl.conf
#kernel.shmall = 4294967296
#kernel.shmmax = 4398046511104
kernel.shmmni = 4096
#kernel.sem = 250 32000 100 128
kernel.sem = 50100 64128000 50100 1280 
fs.file-max = 6815744
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576

vm.overcommit_memory = 2
vm.overcommit_ratio = 90 
vm.swappiness = 1
vm.nr_hugepages = 500

存盤退出後運行 sysctl -p 當即生效linux

os 關閉沒用的服務

chkconfig  autofs off
chkconfig  acpid off
chkconfig  sendmail off
chkconfig  cups-config-daemon off
chkconfig  cpus off
chkconfig  lm_sensors off
chkconfig  gpm off
chkconfig  openibd off
chkconfig  iiim off
chkconfig  pcmcia off
chkconfig  cpuspeed off
chkconfig  nfslock off
chkconfig  ip6tables off
chkconfig  rpcidmapd off
chkconfig  apmd off
chkconfig  sendmail off
chkconfig  arptables_jf off
chkconifg  microcode_ctl off
chkconfig  rpcgssd off
chkconfig  iptables off

啓動服務檢查:c++

chkconfig  --list |grep 3:on

確保如下服務正常
crond
sshd
network
sysstatgit

禁止ipv6:web

vi /etc/modprobe.d/dist.conf

alias net-pf-10 off
alias ipv6 offsql

vi /etc/sysconfig/network NETWORKING_IPV6=no

os yum安裝依賴包

配置好cdrom yum源數據庫

# vi /etc/yum.conf

[base]
name=pyb yum
baseurl=file:///mnt/cdrombak/
gpgkey=file:///mnt/cdrombak/RPM-GPG-KEY-CentOS-6

安裝依賴包api

# yum install git tree sysstat wget make cmake gcc gcc-c++ lrzsz flex bison unixODBC

# yum install smartmontools coreutils glib2 perl perl-devel perl-ExtUtils-Embed zlib zlib-devel openldap openldap-devel flex readline readline-devel systemtap systemtap-sdt-devel python python-devel tcl tcl-devel sgml-common docbook* stylesheets openjade sgml-tools libxslt libxslt-devel libxml2 libxml2-devel openssl openssl-devel pam pam-devel libicu libicu-devel uuid uuid-devel

os 建立用戶目錄

make 時須要事先建立 postgres 用戶及相關的目錄ruby

# groupadd -g 10000 postgres

# useradd -g postgres -u 10000 postgres
# usermod -g postgres postgres

# mkdir -p /usr/pgsql-9.6
# mkdir -p /var/lib/pgsql/9.6/data
# mkdir -p /tmp/pgsoftware

# chown -R postgres:postgres /usr/pgsql-9.6
# chown -R postgres:postgres /var/lib/pgsql

修改 postgres 的環境變量

# vi /home/postgres/.bash_profile

export PGHOME=/usr/pgsql-9.6
export PGDATA=/var/lib/pgsql/9.6/data

export MANPATH=$PGHOME/share/man:$MANPATH
export LD_LIBRARY_PATH=$PGHOME/lib
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/lib:/usr/lib:/usr/local/lib
export PATH=$PGHOME/bin:$PATH

export TEMP=/tmp
export TMPDIR=/tmp

export PS1="\[\e[32;1m\][\u@\h \W]$>\[\e[0m\]"

os 重啓生效

# reboot

下載源碼包,並解壓,編譯,安裝

下載地址 https://www.postgresql.org 

Files

postgresql-9.6.3.tar.bz2 postgresql-9.6.3.tar.bz2              2017-05-08 21:30:12 18.6 MB
postgresql-9.6.3.tar.bz2.md5 postgresql-9.6.3.tar.bz2.md5      2017-05-08 21:30:12    59 bytes
postgresql-9.6.3.tar.bz2.sha256 postgresql-9.6.3.tar.bz2.sha256  2017-05-08 21:30:12    91 bytes

postgresql-9.6.3.tar.gz postgresql-9.6.3.tar.gz                2017-05-08 21:30:1224.4 MB
postgresql-9.6.3.tar.gz.md5 postgresql-9.6.3.tar.gz.md5        2017-05-08 21:30:12    58 bytes
postgresql-9.6.3.tar.gz.sha256 postgresql-9.6.3.tar.gz.sha256       2017-05-08 21:30:12    90 bytes
# cd /tmp/pgsoftware

# ls -l
total 24940
-rw-r--r-- 1 root  25536998 May 22 17:43 postgresql-9.6.3.tar.gz  

$ tar -zxvf ./postgresql-9.6.3.tar.gz

開始編譯安裝三把斧

$ ./configure --help
`configure' configures PostgreSQL 9.6.9 to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help display this help and exit       --help=short display options specific to this package       --help=recursive display the short help of all the included packages   -V, --version display version information and exit   -q, --quiet, --silent do not print `checking ...' messages       --cache-file=FILE cache test results in FILE [disabled]   -C, --config-cache alias for `--cache-file=config.cache'   -n, --no-create do not create output files       --srcdir=DIR find the sources in DIR [configure dir or `..'] 
Installation directories:
  --prefix=PREFIX install architecture-independent files in PREFIX                           [/usr/local/pgsql]
  --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX                           [PREFIX]

By default, `make install' will install all the files in
`/usr/local/pgsql/bin', `/usr/local/pgsql/lib' etc.  You can specify
an installation prefix other than `/usr/local/pgsql' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR user executables [EPREFIX/bin]   --sbindir=DIR system admin executables [EPREFIX/sbin]   --libexecdir=DIR program executables [EPREFIX/libexec]   --sysconfdir=DIR read-only single-machine data [PREFIX/etc]   --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]   --localstatedir=DIR modifiable single-machine data [PREFIX/var]   --libdir=DIR object code libraries [EPREFIX/lib]   --includedir=DIR C header files [PREFIX/include]   --oldincludedir=DIR C header files for non-gcc [/usr/include]   --datarootdir=DIR read-only arch.-independent data root [PREFIX/share]   --datadir=DIR read-only architecture-independent data [DATAROOTDIR]   --infodir=DIR info documentation [DATAROOTDIR/info]   --localedir=DIR locale-dependent data [DATAROOTDIR/locale]   --mandir=DIR man documentation [DATAROOTDIR/man]   --docdir=DIR documentation root [DATAROOTDIR/doc/postgresql]   --htmldir=DIR html documentation [DOCDIR]   --dvidir=DIR dvi documentation [DOCDIR]   --pdfdir=DIR pdf documentation [DOCDIR]   --psdir=DIR ps documentation [DOCDIR] 
System types:
  --build=BUILD configure for building on BUILD [guessed]   --host=HOST cross-compile to build programs to run on HOST [BUILD] 
Optional Features:
  --disable-option-checking ignore unrecognized --enable/--with options   --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)   --enable-FEATURE[=ARG] include FEATURE [ARG=yes]   --disable-integer-datetimes                           disable 64-bit integer date/time support
  --enable-nls[=LANGUAGES]                           enable Native Language Support
  --disable-rpath do not embed shared library search path in                           executables
  --disable-spinlocks do not use spinlocks   --disable-atomics do not use atomic operations   --enable-debug build with debugging symbols (-g)   --enable-profiling build with profiling enabled   --enable-coverage build with coverage testing instrumentation   --enable-dtrace build with DTrace support   --enable-tap-tests enable TAP tests (requires Perl and IPC::Run)   --enable-depend turn on automatic dependency tracking   --enable-cassert enable assertion checks (for debugging)   --disable-thread-safety disable thread-safety in client libraries   --disable-largefile omit support for large files   --disable-float4-byval disable float4 passed by value   --disable-float8-byval disable float8 passed by value 
Optional Packages:
  --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]   --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)   --with-extra-version=STRING                           append STRING to version
  --with-template=NAME override operating system template   --with-includes=DIRS look for additional header files in DIRS   --with-libraries=DIRS look for additional libraries in DIRS   --with-libs=DIRS alternative spelling of --with-libraries   --with-pgport=PORTNUM set default port number [5432]   --with-blocksize=BLOCKSIZE                           set table block size in kB [8]
  --with-segsize=SEGSIZE set table segment size in GB [1]   --with-wal-blocksize=BLOCKSIZE                           set WAL block size in kB [8]
  --with-wal-segsize=SEGSIZE                           set WAL segment size in MB [16]
  --with-CC=CMD set compiler (deprecated)   --with-tcl build Tcl modules (PL/Tcl)   --with-tclconfig=DIR tclConfig.sh is in DIR   --with-perl build Perl modules (PL/Perl)   --with-python build Python modules (PL/Python)   --with-gssapi build with GSSAPI support   --with-krb-srvnam=NAME default service principal name in Kerberos (GSSAPI)                           [postgres]
  --with-pam build with PAM support   --with-bsd-auth build with BSD Authentication support   --with-ldap build with LDAP support   --with-bonjour build with Bonjour support   --with-openssl build with OpenSSL support   --with-selinux build with SELinux support   --with-systemd build with systemd support   --without-readline do not use GNU Readline nor BSD Libedit for editing   --with-libedit-preferred                           prefer BSD Libedit over GNU Readline
  --with-uuid=LIB build contrib/uuid-ossp using LIB (bsd,e2fs,ossp)   --with-ossp-uuid obsolete spelling of --with-uuid=ossp   --with-libxml build with XML support   --with-libxslt use XSLT support when building contrib/xml2   --with-system-tzdata=DIR                           use system time zone data in DIR
  --without-zlib do not use Zlib   --with-gnu-ld assume the C compiler uses GNU ld [default=no] 
Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor
  LDFLAGS_EX  extra linker flags for linking executables only
  LDFLAGS_SL  extra linker flags for linking shared libraries only
  DOCBOOKSTYLE
              location of DocBook stylesheets

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to <pgsql-bugs@postgresql.org>.

在一次postgresql 大會上,平安科技的汪洋大神分享了他們在實際中添加的一個必要的參數,你們參考下。

--with-segsize
單個文件大小,建議10G以上,避免文件數太多
--with-wal-segsize
單個WAL文件大小,默認時 16MB
--with-libedit-preferred
--with-python
--with-uuid

就是 configure 時,添加以下參數:

--with-libedit-preferred --with-python --with-uuid=ossp --with-segsize=10 --with-blocksize=16 --with-wal-segsize=64 --with-wal-blocksize=16

下面是本地的操做

# cd /tmp/pgsoftware/postgresql-9.6.3

# ./configure --prefix=/usr/pgsql-9.6 --with-perl --with-tcl --with-python --with-openssl --with-pam --without-ldap --with-libxml --with-libxslt --enable-thread-safety --enable-dtrace --enable-debug --with-libedit-preferred --with-uuid=ossp --with-segsize=10 --with-blocksize=16 --with-wal-segsize=64 --with-wal-blocksize=16 

# make world
# make install-world

# su - postgres
$ cd /usr/pgsql-9.6
$ ls -l
total 16
drwxrwxr-x 2 root root 4096 May 22 17:59 bin
drwxrwxr-x 6 root root 4096 May 22 17:59 include
drwxrwxr-x 4 root root 4096 May 22 17:59 lib
drwxrwxr-x 6 root root 4096 May 22 17:59 share

一旦軟件構建完成並安裝好,你能夠經過pg_config命令得到一份PostgreSQL系統的配置:

$ pg_config --bindir 
$ pg_config --includedir
$ pg_config --libdir
$ pg_config --configure
$ pg_config --version

運行 initdb 工具,建立數據庫

$ /usr/pgsql-9.6/bin/initdb -D /var/lib/pgsql/9.6/data


~~~~~~腳本最後輸出以下
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:


    /usr/pgsql-9.6/bin/pg_ctl -D /var/lib/pgsql/9.6/data -l logfile start


啓動 postgresql 服務
/usr/pgsql-9.6/bin/pg_ctl -D /var/lib/pgsql/9.6/data  start

嘗試下是否工做
/usr/pgsql-9.6/bin/createdb test
/usr/pgsql-9.6/bin/psql test

參考 /u01/software/postgresql-9.6.3/INSTALL 的Short Version 部分
參考,參考

__________________________________________________________________

                                Short Version

./configure
make
su
make install

adduser postgres
mkdir /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/postgres -D /usr/local/pgsql/data >logfile 2>&1 &
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test

   The long version is the rest of this document.

配置 pg_hba.conf

$ vi /var/lib/pgsql/9.6/data/pg_hba.conf
#peiyb add
host    all             all             192.168.56.0/24                password

配置 postgresql.auto.conf

alter system set listen_addresses = '*';
alter system set port = '5432';

alter system set shared_buffers = '1024MB';
alter system set huge_pages = 'try';
alter system set work_mem = '10MB' ;
alter system set maintenance_work_mem = '256MB';
alter system set effective_cache_size = '2GB';

alter system set track_activity_query_size = 4096;
alter system set checkpoint_completion_target = 0.5;

alter system set superuser_reserved_connections = '10';
alter system set max_connections=600;

alter system set max_wal_size = '32GB';
alter system set min_wal_size = '2GB';

alter system set log_destination = 'csvlog';
alter system set logging_collector = on;
alter system set log_line_prefix = '%t ';
alter system set log_directory = '/var/log/postgresql';
alter system set log_filename = 'postgresql-%Y-%m-%d.log';
alter system set log_file_mode = '0600';
alter system set log_truncate_on_rotation = 'off';
alter system set log_rotation_age = '1d';
alter system set log_rotation_size = 0;
alter system set log_min_messages = notice;
alter system set log_min_error_statement = notice;
alter system set log_min_duration_statement = 5000;

alter system set log_connections = 'on';
alter system set log_disconnections = 'on';
alter system set log_checkpoints = 'on';
alter system set log_duration = 'on';
alter system set log_hostname = 'on';
alter system set log_lock_waits = 'on';
alter system set log_statement = 'none';
alter system set log_timezone = 'PRC';

alter system set lc_messages = 'C';

會話級別修改部分參數
set work_mem = ‘6MB’;
set work_mem to ‘6MB’;

show work_mem;
reset work_mem;

啓動 pgsql

$ pg_ctl start
$ pg_ctl start -D $PGDATA
$ pg_ctl start -D $PGDATA -o "-c config_file=/etc/postgresql/9.6/main/postgresql.conf"

$ pg_ctl stop -m smart -D $PGDATA
$ pg_ctl stop -m fast -D $PGDATA
$ pg_ctl stop -m immediate -D $PGDATA
$ pg_ctl stop

$ pg_ctl restart

查看 pgsql 進程

# ps -ef|grep 20174
postgres 20174          1  0 18:11 ?        00:00:00 /usr/pgsql-9.6/bin/postgres -D /var/lib/pgsql/9.6/data
postgres 20176 20174  0 18:11 ?        00:00:00 postgres: checkpointer process          
postgres 20177 20174  0 18:11 ?        00:00:00 postgres: writer process                
postgres 20178 20174  0 18:11 ?        00:00:00 postgres: wal writer process            
postgres 20179 20174  0 18:11 ?        00:00:00 postgres: autovacuum launcher process   
postgres 20180 20174  0 18:11 ?        00:00:00 postgres: stats collector process
相關文章
相關標籤/搜索