Linux下瀚高数据库的安装步骤(HGDB4.7.6)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Auspicious_air/article/details/89707203

Linux下瀚高数据库的安装步骤(HGDB4.7.6)

一、安装检查
1、检查磁盘空间和内存大小:(注意保存日志)

df -h
free -h
grep MemTotal /proc/meminfo
grep SwapTotal /proc/meminfo

强烈建议内存大于等于8G
内存建议值参照表:

MemTotal    SwapTotal
8G    2~4G
8~16G    4~8G
16~64G    8~32G
>=64G     32G

2、检查内核参数

cat /proc/sys/kernel/shmmax 
cat /proc/sys/kernel/shmall
cat /proc/sys/kernel/shmmni   这个参数(系统共享内存段的最大数量)数据库自动修改

参数建议值:

MemTotal    shmall    shmmax
8G    7~8G    4G
8~64G    M*50%    M*90~95%
>=64G    32G    M*90%~95%

N*1024*1024*1024

3、关于RHEL、Centos防止进程被杀

Set RemoveIPC=no in /etc/systemd/logind.conf
echo "RemoveIPC=no" >> /etc/systemd/logind.conf
Reboot the server or restart systemd-logind as follows:
    # systemctl daemon-reload
    # systemctl restart systemd-logind

二、安装准备
(1)关闭防火墙和NetworkManager

6.X
service iptables stop
chkconfig iptables off
service iptables status
service NetworkManager stop 
chkconfig NetworkManager off
service NetworkManager status
7.X
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl status firewalld.service
systemctl stop  NetworkManager.service
systemctl disable NetworkManager.service
systemctl status  NetworkManager.service

(2)关闭SELINUX

sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
cat /etc/selinux/config | grep SELINUX=disabled
getenforce 

(3)检查主机名

[highgo@hgdb ~]$ hostnamectl status
   Static hostname: hgdb
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 5c7b0775b96044209a3858d9773a5b83
           Boot ID: a379f124abc746c190aca4932ee34fe1
    Virtualization: vmware
  Operating System: Red Hat Enterprise Linux Server 7.3 (Maipo)
       CPE OS Name: cpe:/o:redhat:enterprise_linux:7.3:GA:server
            Kernel: Linux 3.10.0-514.el7.x86_64
      Architecture: x86-64

若需要修改主机名:(不用重启)

echo mdw>/proc/sys/kernel/hostname
echo mdw>/etc/hostname
hostnamectl set-hostname mdw

(4)检查时间和时区

[highgo@hgdb ~]$ timedatectl
      Local time: Fri 2018-10-19 18:52:17 CST
  Universal time: Fri 2018-10-19 10:52:17 UTC
        RTC time: Fri 2018-10-19 10:52:18
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

修改时区,例如将时区修改为Asia/Shanghai

[root@hgdb ~]# timedatectl list-timezones 
[root@hgdb ~]# timedatectl set-timezone Asia/Shanghai

修改时间

[root@hgdb ~]# date -s "20170622 10:26:00"

(5)安装系统软件包

[root@hgdb ~]# cat /etc/yum.repos.d/highgo.repo
[Server]
name=Red Hat Enterprise Linux $releasever Beta - $basearch - Source
baseurl=file:///media/cdrom
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

或者

[rhel]
name=rhel
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
[root@hgdb ~]# mkdir /media/cdrom
[root@hgdb ~]# mount /dev/cdrom /media/cdrom

(该步骤请根据实际情况挂载镜像,直接挂载.ios文件请使用-loop参数)

mount: /dev/sr0 is write-protected, mounting read-only

[root@hgdb ~]# yum clean all
[root@hgdb ~]# yum list

[root@hgdb ~]# yum install vim wget readline readline-devel zlib zlib-devel openssl openssl-devel pam-devel libxml2-devel libxslt-devel python-devel tcl-devel gcc gcc-c++ -y

(6)hosts文件配置

[root@hgdb ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.80.10 hgdb 
[root@hgdb ~]# ping hgdb
PING hgdb (192.168.80.10) 56(84) bytes of data.
64 bytes from hgdb (192.168.80.10): icmp_seq=1 ttl=64 time=0.058 ms
64 bytes from hgdb (192.168.80.10): icmp_seq=2 ttl=64 time=0.133 ms
64 bytes from hgdb (192.168.80.10): icmp_seq=3 ttl=64 time=0.118 ms
64 bytes from hgdb (192.168.80.10): icmp_seq=4 ttl=64 time=0.198 ms
……

(7)创建highgo用户

groupadd -g 5866 highgo
useradd -u 5866 -g highgo highgo; echo highgo | passwd -f --stdin highgo

提示如下信息证明创建成功

Changing password for user highgo.
passwd: all authentication tokens updated successfully. 

(8)创建数据库安装目录
数据库安装目录要使用单独的磁盘或者lv,建议不要和 / 根目录放在一起,即df -h看到的目录必须是独立的一行,例如下面/data目录。

[root@hgdb ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   28G  3.3G   25G  12% /
devtmpfs               977M     0  977M   0% /dev
tmpfs                  993M  148K  993M   1% /dev/shm
tmpfs                  993M  9.5M  983M   1% /run
tmpfs                  993M     0  993M   0% /sys/fs/cgroup
/dev/mapper/rhel-data   20G   33M   20G   1% /data
/dev/sda1              197M  133M   64M  68% /boot
tmpfs                  199M   28K  199M   1% /run/user/1000
tmpfs                  199M     0  199M   0% /run/user/0
/dev/sr0               3.6G  3.6G     0 100% /media/cdrom
[root@hgdb ~]# mkdir -p /data/highgo/4.7.6 
[root@hgdb ~]# chown -R highgo:highgo /data
[root@hgdb ~]# mkdir /hgdbbak/archive -p
[root@hgdb ~]# chown -R highgo:highgo /hgdbbak/

(9)配置操作系统内核参数
注意:给出的值都是最小值,因此如果系统使用更大的值,则不要更改。

[root@hgdb ~]# vi /etc/sysctl.conf
#for highgo db 4.7.6
net.core.wmem_default=262144
fs.file-max=76724600
vm.mmap_min_addr=65536
net.core.somaxconn=4096
net.core.wmem_max=4194304
net.core.netdev_max_backlog=10000
kernel.sem=4096 2147483647 2147483646 512000
net.core.rmem_max=4194304
net.ipv4.tcp_tw_reuse=1
net.core.rmem_default=262144
net.ipv4.ip_local_port_range=40000 65535
net.netfilter.nf_conntrack_max=1200000
net.ipv4.tcp_rmem=8192 87380 16777216
net.ipv4.tcp_max_syn_backlog=4096
fs.nr_open=20480000
net.ipv4.tcp_wmem=8192 87380 16777216
vm.dirty_writeback_centisecs=100
vm.dirty_ratio=95
kernel.shmmni=819200
vm.swappiness=0
net.ipv4.tcp_mem=8388608 12582912 16777216
vm.dirty_background_bytes=409600000
net.nf_conntrack_max=1200000
net.ipv4.tcp_max_tw_buckets=262144
vm.overcommit_memory = 2  
vm.overcommit_ratio=90
vm.min_free_kbytes=524288 

root用户运行如下命令是参数立即生效。

[root@hgdb ~]# sysctl -p

(10)配置操作系统limits

[root@hgdb ~]# vi /etc/security/limits.conf
#for highgo db 4.7.6
highgo soft  core unlimited
highgo hard  nproc unlimited
highgo soft  nproc unlimited
highgo hard  memlock unlimited
highgo hard  nofile 1024000
highgo soft  memlock unlimited
highgo soft  nofile 1024000
highgo hard  stack  65536
highgo soft  stack  65536

修改使以上参数生效:

[root@hgdb01 ~]# vi /etc/pam.d/login
session    required     pam_limits.so
nproc参数的生效并不是在/etc/security/limits.conf里生效,是需要在 /etc/security/limits.d/20-nproc.conf文件中设置
[root@hgdb01 ~]# vi /etc/security/limits.d/90-nproc.conf
*                soft    nproc           131072
*                hard    nproc           131072

nproc值表示该用户下的最大进程数max user processes如果业务进程较多,则可能因为进程达到上限而使得操作系统用户无法登陆。
(11)设置highgo用户环境变量

[root@hgdb ~]# vi /home/highgo/.bash_profile
[root@hgdb ~]# cat /home/highgo/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
export LANG=C  or   en_US.UTF-8
export PGHOME=/data/highgo/4.7.6
export PGUSER=highgo
export PGPORT=5866
export PGDATA=$PGHOME/data
export PATH=$PGHOME/bin:$PATH:$HOME/bin
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH

(12)上传并解压HGDB安装包

[root@hgdb upload]# tar -zxvf hgdb4.7.6_installer_redhat7.x_Enterprise_64.tar.gz 
[root@hgdb upload]# chown -R highgo:highgo hgdb_install4.7.6_redhat7.x_Enterprise_64/ 
[root@hgdb upload]# ll
drwxr-xr-x. 4 highgo highgo        50 Jul  7 17:49 hgdb_install4.7.6_redhat7.x_Enterprise_64 

三、安装步骤
图形化安装
1、    首先应确保可以开启图形化界面

检查当前操作系统是否存在图形化界面,如果不存在yum安装图形化界面

[root@hgdb ~]# yum -y groupinstall "Server with GUI"

设置操作系统启动时默认运行级别为图形化

[root@hgdb ~]# systemctl get-default      //查看默认运行级别
multi-user.target
[root@hgdb ~]# cat /etc/inittab
# inittab is no longer used when using systemd.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
#
# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
#
# multi-user.target: analogous to runlevel 3    字符界面
# graphical.target: analogous to runlevel 5     图形化界面
#
# To view current default target, run:
# systemctl get-default
#
# To set a default target, run:
# systemctl set-default TARGET.target
#
//设置默认图形化运行级别
[root@hgdb ~]# systemctl set-default graphical.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.
//查看默认运行级别
[root@hgdb ~]# systemctl get-default
graphical.target
//重启操作系统
[root@hgdb ~]# init 6

2、    建议在highgo用户下执行启动程序
如果使用VNC连接的话,需要安装相关包

[root@hgdb 4.1.1]# yum install tiger*  -y

root用户下执行,请按照如下步骤:

root:    xhost +
access control disabled, clients can connect from any host
su – highgo
highgo:  export DISPLAY=:0.0
highgo:   ./runinstall

安装界面的中英文取决于系统环境当前的语言环境

此图中的两个问题是由于关闭防火墙导致找不到参数,可以直接忽略。其他问题通过脚本修复。

执行脚本完成安装

[root@hgdb uplaod]# /data/highgo/4.7.6/hginstall.sh

Starting HighGo Database Server:

waiting for server to start.... done

server started

HighGo Database Server started successfully

非图形化安装
 

[highgo@hgdb hgdb_enterprise_4.7.6_redhat7.x_x86-64_install_20180919]$ ./runinstall 
Welcome to the installation of HighGo Database 4.7.6 Enterprise Edition !
press 1 to continue, 2 to quit, 3 to redisplay
1
HIGHGO DATABASE END-USER SOFTWARE LICENSE AGREEMENT
THANKS FOR YOUR SELECTION OF HIGHGO DATABASE.
Copyright (c) 2017, HighGo Co., Ltd. 
All Rights Reserved.
IMPORTANT: THIS SOFTWARE END USER LICENSE AGREEMENT("EULA") IS A LEGAL AGREEMENT BETWEEN YOU AND HighGo Co., Ltd. READ IT CAREFULLY BEFORE COMPLETING THE INSTALLATION PROCESS AND USING THE SOFTWARE. IT PROVIDES A LICENSE TO USE THE SOFTWARE AND CONTAINS WARRANTY INFORMATION AND LIABILITY DISCLAIMERS. BY INSTALLING AND USING THE SOFTWARE, YOU ARE CONFIRMING YOUR ACCEPTANCE OF THE SOFTWARE AND AGREEING TO BECOME BOUND BY THE TERMS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO BE BOUND BY THESE TERMS, PLEASE DO NOT INSTALL OR USE THE SOFTWARE. YOU MUST ASSUME THE ENTIRE RISK OF USING THIS PROGRAM. ANY LIABILITY OF HighGo WILL BE LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT OR REFUND OF PURCHASE PRICE BEFORE FIRST INSTALLATION.
Definitions 
 1. "the Software" means "HighGo DataBase". 
 2.  "HighGo" is responsible for HighGo Co., Ltd.
License Grants
 1. You may use the Software for free for non-commercial use under the License Restrictions. 
 2. You may use the Software for commercial use after purchasing the commercial license. Moreover, according to the license you purchased you may get specified term, manner and content of technical support from HighGo. 
License Restrictions 
 1. You may not use the Software for commercial use or profit use, unless you have been licensed to. To purchase the license , please visit http://www.highgo.com for more information.
 2. You may not rent, lease, sublicense, sell, assign, pledge the Software and its services. 
 3. You may not modify the Software to create derivative works for redistribution based upon the Software. 
 4. In the event that you fail to comply with this agreement, your license will be terminated.
  
LIMITED WARRANTY AND DISCLAIMER
 1. THE SOFTWARE AND THE ACCOMPANYING FILES ARE SOLD "AS IS" AND WITHOUT WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR ANY OTHER WARRANTIED WHETHER EXPRESSED OR IMPLIED. 
 2. You must assume the entire risk of using the Software. ANY LIABILITY OF HIGHGO WILL BE LIMITED EXCLUSIVELY TO PRODUCT REPLACEMENT, REFUND OF PURCHASE PRICE BEFORE YOUR FIRST INSTALLATION.
press 1 to accept, 2 to reject, 3 to redisplay
1
Select target path [/data/hgdb/4.7.5] 
/data/highgo/4.7.6
press 1 to continue, 2 to quit, 3 to redisplay
1

TreePacksPanel

[JDK_JRE] [required]
[hgdb.dbserverPack] [Already Selected]
[hgdb.userInterfacePack] [Already Selected]
    psql [Already Selected]
    hgdbAdmin [Already Selected]
[hgdb.developmentPack] [Already Selected]
[hgdb.installPack] [Already Selected]
    init and configure database [Already Selected]
    uninstalldata [required]
[tempExecutableFiles] [required]
...pack selection done.
press 1 to continue, 2 to quit, 3 to redisplay
1
To check the dependent packs.
press 1 to check, 2 to skip, 3 to exit
1
    Checks                              Status    Fixable   
    net.netfilter.nf_conntrack_max      Failed    Yes       
    net.nf_conntrack_max                Failed    Yes       
Use the root user to execute the following script to modify the system parameters.
/tmp/hgdb_2050248256/kernelParameterSets.sh
检测是否需要执行修复脚本,如果只剩此处两个则可直接忽略,其它情况则执行修复脚本
press 1 to ignore, 2 to reject, 3 to recheck
1
Data directory   [/data/highgo/4.7.6/data] 


Port number   [5866] 


Superuser name   [highgo] 


Password   [] 
第一次输入密码,必须超出六位且包含数字字母,不可含有特殊字符-@*&…%¥#()
Password(again)   [] 


  [x] Whether to start automatically.
input 1 to select, 0 to deselect:

datatype
0  [x] OLTP
1  [ ] OLAP
2  [ ] HTAP
3  [ ] Web
4  [ ] Desktop
input selection:

Total Memory (GB) [2] 


connectionNumber [300] 

Locale 
0  [ ] aa_DJ
1  [ ] aa_DJ.iso88591
2  [ ] aa_DJ.utf8
3  [ ] aa_ER
4  [ ] aa_ER@saaho
……
环境语言根据客户要求选择,通常选择C或者zh_CN.utf8
773  [ ] zh_CN.gbk
774  [x] zh_CN.utf8
775  [ ] zh_HK
776  [ ] zh_HK.big5hkscs
777  [ ] zh_HK.utf8
778  [ ] zh_SG
779  [ ] zh_SG.gb2312
780  [ ] zh_SG.gbk
781  [ ] zh_SG.utf8
782  [ ] zh_TW
783  [ ] zh_TW.big5
784  [ ] zh_TW.euctw
785  [ ] zh_TW.utf8
786  [ ] zu_ZA
787  [ ] zu_ZA.iso88591
788  [ ] zu_ZA.utf8
input selection:


Encoding  
0  [ ] EUC_JP
1  [ ] EUC_KR
2  [ ] ISO_8859_5
3  [ ] ISO_8859_6
4  [ ] ISO_8859_7
5  [ ] ISO_8859_8
6  [ ] JOHAB
7  [ ] KOI8-R
8  [ ] LATIN1
9  [ ] LATIN2
10  [ ] LATIN3
11  [ ] LATIN4
12  [ ] LATIN5
13  [ ] LATIN9
14  [ ] MULE_INTERNAL
15  [ ] SQL_ASCII
16  [ ] WIN866
17  [ ] WIN874
18  [ ] WIN1250
19  [ ] WIN1251
20  [ ] WIN1252
21  [ ] WIN1256
22  [ ] WIN1258
23  [x] UTF8
input selection:
默认为非加密模式
  [ ] Whether encrypted storage.
input 1 to select, 0 to deselect:

press 1 to continue, 2 to quit, 3 to redisplay
1
Installation path: /data/highgo/4.7.6.

Data directory: /data/highgo/4.7.6/data.

Database port: 5866.

Database Locale: zh_CN.utf8.

Server Encoding: UTF8.

Super User: highgo.

Database Type: oltp

Total Memory: 2

Connections: 300
press 1 to continue, 2 to quit, 3 to redisplay
1
[ Starting to unpack ]
[ Processing package: Jre (1/8) ]
[ Processing package: Database Server (2/8) ]
[ Processing package: User interfaces (3/8) ]
[ Processing package: psql (4/8) ]
[ Processing package: hgdbAdmin (5/8) ]
[ Processing package: Development (6/8) ]
[ Processing package: Install database (7/8) ]
[ Processing package: Initial the database (8/8) ]
To finish the database install, please follow the below steps:
      1. execute following script with root user to complete the database self-starting configuration
          /data/highgo/4.7.6/hginstall.sh 
     2. Press enter to continue, after hginstall.sh execute successfully .

[Press enter to continue!]
另开新窗口root用户执行
[root@hgdb highgo]#  /data/highgo/4.7.6/hginstall.sh 
Starting HighGo Database Server:
waiting for server to start.... done
server started
HighGo Database Server started successfully

重新回到刚才的窗口:
[Press enter to continue!]

[ Unpacking finished ]
Begin create shorcut:
 [x]Create additional shortcuts on the desktop
input 1 to select, 0 to deselect:

 [x]Create shortcuts in the StartMenu
input 1 to select, 0 to deselect:

Select which user the program will create shortcut for:
0 [ ] current user
1 [x] all users
input selection:

Name of programgroup [HighgoDB V4.7.6]

press 1 to continue, 2 to quit, 3 to redisplay
1
Install was successful
application installed on /data/highgo/4.7.6
[ Console installation done ]

安装完成

四、后期处理
数据库参数修改

alter system set listen_addresses = '*';
alter system set max_connections = 2000;         ##连接数
alter system set shared_buffers = '512MB';       ##total_memory*25%
alter system set checkpoint_completion_target = 0.8;
##日志参数----------
alter system set log_destination = 'csvlog';
alter system set logging_collector = on;
alter system set log_directory = 'hgdb_log';
alter system set log_filename = 'highgodb-%a.log';
alter system set log_rotation_age = '1d';  ##每天生成一个新的日志文件
alter system set log_rotation_size = 0;     ##不限制单个日志文件大小
alter system set log_truncate_on_rotation = on;  ##覆盖同名文件
##只保留7天日志,循环覆盖
alter system set log_hostname = on;
alter system set log_line_prefix = '%m';
alter system set log_statement = 'ddl';
## WAL和归档参数----------
alter system set wal_level = archive;
alter system set archive_mode = on;
alter system set archive_directory = '/hgdbbak/archive';
此处/hgdbbak/archive建议将归档日志放到数据库的定时备份的路径内,便于数据库异机恢复时最大可能的恢复数据。

修改pg_hba.conf文件:
添加类似的访问许可:

# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
host    all             all             0.0.0.0/0            md5

参数修改完成后重新启动数据库

[highgo@hgdb archive]$ pg_ctl stop -m f
[highgo@hgdb archive]$ pg_ctl start

数据库启动时会显示剩余时间:

[highgo@hgdb ~]$ 日志:  00000: This is a trial edition, validate until 2018-11-21 21:58:57, database will not be able to start up after that time,please apply an official license by that time.

上传license并复制到data目录修改名称为hgdb.lic

[root@hgdb uplaod]# cp hgdb_476_3m.lic /data/highgo/4.7.6/data/hgdb.lic
[root@hgdb uplaod]# chown highgo:highgo -R /data/highgo/4.7.6/data/hgdb.lic
[root@hgdb uplaod]# ls -l /data/highgo/4.7.6/data/hgdb.lic
-rw-r--r-- 1 highgo highgo 239 Oct 22 22:21 /data/highgo/4.7.6/data/hgdb.lic

激活

[highgo@hgdb data]$ pg_ctl reload
server signaled
日志:  00000: 接收到 SIGHUP, 重载配置文件
日志:  00000: 注意 :检测到授权文件已更改,该license为试用版授权,有效期截止到2019-01-20 21:58:57

检查license

[highgo@hgdb data]$ check_lic -D $PGDATA

############## HIGHGODB LICENSE ###################
License status:Normal
License validity:2019-1-21
Database Version:Highgo Database 4.7.6 Trail Edition
###################################################

安装插件

pg_stat_statements
注意:HGDB中已经将此插件编译完毕,仅需要直接安装

highgo=# create extension pg_stat_statements;
CREATE EXTENSION
可以通过查看扩展工具检查是否安装
highgo=# \dx
                                          List of installed extensions
        Name        | Version |   Schema   |                             Description                             
--------------------+---------+------------+---------------------------------------------------------------------
 pg_stat_statements | 1.3     | public     | track execution statistics of all SQL statements executed
 plpgsql            | 1.0     | pg_catalog | PL/pgSQL procedural language
 postgis            | 2.4.4   | public     | PostGIS geometry, geography, and raster spatial types and functions
重启数据库
alter system set shared_preload_libraries = 'pg_stat_statements';   ##分配额外的共享内存
alter system set pg_stat_statements.max = 5000;   ##最大跟踪数
alter system set pg_stat_statements.track = 'all';    ##统计等级  top/all/none
alter system set pg_stat_statements.track_utility = on;  ##是否跟踪公共程序命令

HGWatcher部署
收集当前运行数据的信息 
解压HGWatcher_V1.0.0.tar.gz,进入HGWatcher目录,首先执行getDBlist.sh,获取当前服务器中运行的数据库的信息。 
执行过程如下:

[root@pgha3 HGWatcher]# sh getDBlist.sh 
The current environment has a set of 3 databases.
To monitor all databases, you need to write all database information to the file dblist.cfg, and then use the -dblist option.
You can also read the database information through the current script and then modify it according to the actual situation.
Do you want to generate a database information list [Y/N]?y

Database benchmarksql did not install extended pg_stat_statements!

Database highgo did not install extended pg_stat_statements!

Database highgo did not install extended pg_stat_statements!

##########################################################################################

# The output file is /HGWatcher/data/dblist.cfg

##########################################################################################

采集数据库信息需要使用插件pg_stat_statements,需要提前在数据库中配置插件pg_stat_statements。 
执行结果放在HGWatcher目录下的data,名称为getDBlist.sh,内容如下:

[DATABASE1]

#psql的路径
PSQL=/usr/pgsql-10/bin/psql            

#PostgreSQL的安装路径
PGDATAPATH=/var/lib/pgsql/10/data      

#PostgreSQL使用的端口
PGPORT=5432                            

#当前数据库的IP,默认使用127.0.0.1,需要设置psql -h 127.0.0.1可以直接登录数据库
PGHOST=127.0.0.1 

#登录数据库的用户,需要使用数据库的超级用户                   
PGUSER=postgres

#数据库软件的安装或管理用户,如有误,需要手动修改。
OSUSER=postgres

#当前所有创建的数据库,如果获取到的数据库不需要监控,可以直接删除
PGDATABASE=postgres,benchmarksql

#数据库是否可以不使用密码直接登录,1表示可以,0表示不可以,需要配置数据库,使其在本地可以不使用密码直接登录
DirectAccess=1

[ENDDATABASE1]

定时收集系统信息 
确认dblist.cfg文件中信息与当前运行数据库信息相符后,执行HGWatcher.sh开始收集信息。HGWatcher.sh有以下几个选项:

-dblist:指定使用自定义的dblist.cfg
-OSsnapshot:指定采集操作系统信息的快照时间,单位秒,默认时间30秒
-DBsnapshot:指定采集数据库信息的快照时间,单位分钟,默认时间60分钟
-archtime :指定归档存放时间,单位小时,默认时间168小时(一周)
-archpath :指定归档存放的路径,默认路径HGWatcher/archive/
-help :获取帮助信息

示例:

./HGWatcher.sh -OSsnapshot 20 -DBsnapshot 11 -archtime 4 -archpath /tmp/archive
假如每20秒采集一次操作系统信息,每11分钟采集一次数据库信息,归档保存时间4小时,归档存放目录/tmp/archive。参数设置如下:

[root@pgha3 HGWatcher]# ./HGWatcher.sh -OSsnapshot 20 -DBsnapshot 11 -archtime 4 -archpath /tmp/archive

Testing for discovery of OS Utilities...

2018-09-29 09:07:59 VMSTAT found on your system.

2018-09-29 09:08:01 IOSTAT found on your system.

2018-09-29 09:08:01 IFCONFIG found on your system.

2018-09-29 09:08:03 MPSTAT found on your system.

2018-09-29 09:08:04 NETSTAT found on your system.

2018-09-29 09:08:04 Discovery of CPU CORE COUNT

2018-09-29 09:08:04 CPU CORE COUNT will be used by HGWatcher to automatically look for cpu problems

2018-09-29 09:08:04 CPU CORE COUNT =

2018-09-29 09:08:04 VCPUS/THREADS =

2018-09-29 09:08:04 Discovery completed.

2018-09-29 09:08:09 Starting HGWatcher v1.0.0

With OSsnapshotInterval = 20 #操作系统快照时间  

With DBSnapshotInterval = 11m #数据库快照时间

With ArchiveInterval = 4h #归档保留时间

With ArchivePath = /tmp/archive #归档保存位置

HGWatcher - Written by zb,

Highgo Corporation

2018-09-29 09:08:14 Data is stored in directory: /tmp/archive

2018-09-29 09:08:14 Starting Data Collection...

收集归档文件 
进入到HGWatcher目录下,执行./getarch.sh,将停止当前运行的HGWatcher,重新运行一次HGWatcher,然后将7天内的数据库日志及日志归档目录一并打包压缩到当前目录。数据库日志会将保存到归档目录下的pg_log文件夹中,并建立以端口号命名的文件夹,例如某数据库使用端口为5866,将在pg_log下建立5866的文件夹,并将对应的数据库日志复制到5866文件夹下。

部署数据库备份脚本

注:备份脚本可在当前文档的附件中下载

1、将备份脚本上传至服务器,修改备份脚本内容,修改内容如下

#数据库的端口
PORT=5866
#保留几个备份
num=2
#归档文件路径
archdir=/hgdbbak/archive/
#数据文件路径
master_db_cluster=/data/highgo/4.7.6/data
#备份路径
backup_db_cluster=/hgdbbak
#数据库名称
defdb=highgo

修改脚本权限
[root@hgdb opt]# cd /home/highgo/scripts/
[root@hgdb scripts]# ll
总用量 8
-rw-r--r--. 1 root root 4819 9月  14 11:14 Demo_hgdb_backup_for_linux.sh
[root@hgdb scripts]# chown highgo:highgo Demo_hgdb_backup_for_linux.sh
[root@hgdb scripts]# mv Demo_hgdb_backup_for_linux.sh hgdb_backup_for_linux.sh
[root@hgdb scripts]# chmod +x hgdb_backup_for_linux.sh
[root@hgdb scripts]# ll
总用量 8
-rwxr-xr-x. 1 highgo highgo 4819 9月  14 11:14 hgdb_backup_for_linux.sh

2、添加crontab定时任务

[highgo@hgdb hgdbbak]$ crontab -l
no crontab for highgo
[highgo@hgdb hgdbbak]$ crontab -e
no crontab for highgo - using an empty one
crontab: installing new crontab
[highgo@hgdb hgdbbak]$ crontab -l

00 23 * * * /home/highgo/scripts/hgdb_backup_for_linux.sh


 3、测试备份脚本

[highgo@hgdb scripts]$ ./hgdb_backup_for_linux.sh
NOTICE:  00000: pg_stop_backup complete, all required WAL segments have been archived
 pg_stop_backup
----------------
 0/30000C0
(1 row)


[highgo@hgdb scripts]$ ./hgdb_backup_for_linux.sh
NOTICE:  00000: pg_stop_backup complete, all required WAL segments have been archived
 pg_stop_backup
----------------
 0/40000C0
(1 row)


[highgo@hgdb scripts]$ ./hgdb_backup_for_linux.sh

NOTICE:  00000: pg_stop_backup complete, all required WAL segments have been archived
 pg_stop_backup
----------------
 0/50000C0
(1 row)


4、查看备份文件

[highgo@hgdb scripts]$ cd /home/highgo/hgdbbak/
[highgo@hgdb hgdbbak]$ ll
total 20
drwx------. 20 highgo highgo 4096 Sep 14 11:18 2
drwx------. 20 highgo highgo 4096 Sep 14 11:19 3
drwxr-xr-x.  2 highgo highgo 4096 Sep 14 11:19 archive
-rw-rw-r--.  1 highgo highgo 2115 Sep 14 11:19 backuplog_20180914.log
-rw-rw-r--.  1 highgo highgo   88 Sep 14 11:19 fn.history 
手动生成三次备份,但备份策略是保存最近两次的备份,因此只保留第二次和第三次的备份(数字2和3的文件夹)。

附:获取更多资料请登录  https://support.highgo.com

猜你喜欢

转载自blog.csdn.net/Auspicious_air/article/details/89707203