Greenplum学习实践-【安装部署】-2、 5.10集群部署
-
Greenplum學(xué)習(xí)實(shí)踐-【安裝部署】-2、 5.10集群部署
?
?
第 1 章** 環(huán)境說(shuō)明
1.1 官方文檔
Greenplum官方安裝說(shuō)明:
https://gpdb.docs.pivotal.io/5160/install_guide/install_extensions.html
?
?
?
1.2 系統(tǒng)要求
?
| File Systems | ? xfs required for data storage on SUSE Linux and Red Hat (ext3 supported for root file system) |
| Minimum CPU | Pentium Pro compatible (P3/Athlon and above) |
?
| Disk Requirements | ? 150MB per host for Greenplum installation ? Approximately 300MB per segment instance for meta data ? Appropriate free space for data with disks at no more than 70% capacity ? High-speed, local storage |
| Network Requirements | 10 Gigabit Ethernet within the array Dedicated, non-blocking switch NIC bonding is recommended when multiple interfaces are present |
| Software and Utilities | zlib compression libraries bash shell GNU tars GNU zip GNU sed (used by Greenplum Database gpinitsystem) perl secure shell |
*Important**:* SSL is supported only on the Greenplum Database master host system.
?
1.3 搭建環(huán)境介紹
?
操作系統(tǒng):CentOS Linux release 7.4.1708 (Core)
?
| CPU | Intel(R) Xeon(R) CPU E3-1220 v5 @ 3.00GHz *4物理核心(16cores) |
| 內(nèi)存 | 16G |
| 磁盤 | 4T |
| Swap | 32G |
?
?
?
?
第 2 章 安裝架構(gòu)
2.1 安裝大致步驟
Perform the following tasks in order: *1.* Make sure your systems meet the System Requirements *2.* Setting the Greenplum Recommended OS Parameters *3.* (master only) Creating the Greenplum Database Administrative User Account *4.* (master only) Installing the Greenplum Database Software *5.* Installing and Configuring Greenplum on all Hosts *6.* (Optional) Installing Oracle Compatibility Functions *7.* (Optional) Installing Optional Modules *8.* (Optional) Installing Greenplum Database Extensions *9.* (Optional) Installing and Configuring the Greenplum Platform Extension Framework (PXF) *10.*Creating the Data Storage Areas *11.*Synchronizing System Clocks *12.*Next Steps
?
2.2 軟件信息
greenplum-db-5.10.2-rhel6-x86_64.zip是mpp軟件,
greenplum-cc-web-4.3.1-LINUX-x86_64.zip是web監(jiān)控平臺(tái)
?
2.3 架構(gòu)說(shuō)明
準(zhǔn)備 4 臺(tái)服務(wù)器, 1 臺(tái)做 master, 3臺(tái)都做存儲(chǔ)共部署 6 個(gè)segment 及其鏡像
| 10.102.254.24 | sdw1 | 16 | 16 | 4*segment |
| 10.102.254.25 | sdw2 | 16 | 16 | 4*segment |
| 10.102.254.26 | sdw3 | 16 | 16 | 4*segment |
| 10.102.254.27 | mdw1 | 16 | 16 | master |
?
=架構(gòu)目標(biāo)==
?
| master | seg0p seg1p seg5m seg4m | seg2p seg3p seg0m seg1m | seg4p seg5p seg2m seg3m smdw |
?
第 3 章 安裝架構(gòu)
3.1 關(guān)閉防火墻和selinux-所有節(jié)點(diǎn)
?systemctl stop firewalld.service ?systemctl disable firewalld.service ?iptables -F ?vi /etc/selinux/config SELINUX=DISABLED?# sestatus SELinuxstatus: disabled ? ???
3.2 修改host文件 -所有節(jié)點(diǎn)
?
?
?
?
?
3.2 修改主機(jī)名
?
?hostnamectl set-hostname sdw1?hostnamectl status 狀態(tài)?/etc/sysconfig/network???
3.3 系統(tǒng)內(nèi)核參數(shù)優(yōu)化
?
???vi /etc/sysctl.conf?kernel.shmmax = 500000000?kernel.shmmni = 4096?kernel.shmall = 4000000000?kernel.sem = 250 512000 100 2048?kernel.sysrq = 1?kernel.core_uses_pid = 1?kernel.msgmnb = 65536?kernel.msgmax = 65536?kernel.msgmni = 2048?net.ipv4.tcp_syncookies = 1?net.ipv4.ip_forward = 0?net.ipv4.conf.default.accept_source_route = 0?net.ipv4.tcp_tw_recycle = 1?net.ipv4.tcp_max_syn_backlog = 4096?net.ipv4.conf.all.arp_filter = 1?net.ipv4.ip_local_port_range = 1025 65535?net.core.netdev_max_backlog = 10000?net.core.rmem_max = 2097152?net.core.wmem_max = 2097152?vm.overcommit_memory = 2 ??sysctl -p???cat > /etc/sysctl.conf << EOF?\# sysctl settings are defined through files in?\# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.?\#?\# Vendors settings live in /usr/lib/sysctl.d/.?\# To override a whole file, create a new file with the same in?\# /etc/sysctl.d/ and put new settings there. To override?\# only specific settings, add a file with a lexically later?\# name in /etc/sysctl.d/ and put new settings there.?\#?\# For more information, see sysctl.conf(5) and sysctl.d(5).??kernel.shmmax = 500000000?kernel.shmmni = 4096?kernel.shmall = 4000000000?kernel.sem = 500 1024000 200 4096?kernel.sysrq = 1?kernel.core_uses_pid = 1?kernel.msgmnb = 65536?kernel.msgmax = 65536?kernel.msgmni = 2048?net.ipv4.tcp_syncookies = 1?net.ipv4.ip_forward = 0?net.ipv4.conf.default.accept_source_route = 0?net.ipv4.tcp_tw_recycle = 1?net.ipv4.tcp_max_syn_backlog = 4096?net.ipv4.conf.all.arp_filter = 1?net.ipv4.ip_local_port_range = 1025 65535?net.core.netdev_max_backlog = 10000?net.core.rmem_max = 2097152?net.core.wmem_max = 2097152?vm.overcommit_memory = 2?vm.swappiness = 1?kernel.pid_max = 655350?EOF??sysctl -p?
3.4 修改Linux最大限制
?
?cat /etc/security/limits.conf??vi /etc/security/limits.conf??* soft nofile 65536?* hard nofile 65536?* soft nproc 131072?* hard nproc 131072??cat > /etc/security/limits.conf << EOF?* soft nofile 65536?* hard nofile 65536?* soft nproc 131072?* hard nproc 131072?EOF?
如何是rhel 6.x 請(qǐng)注意 /etc/security/limits.d/90-nproc.conf,詳細(xì)情況請(qǐng)見文檔
?
3.5 設(shè)備與IO-文件系統(tǒng)
設(shè)置XFS文件系統(tǒng)并掛載
EXT4是第四代擴(kuò)展文件系統(tǒng)(英語(yǔ):Fourth EXtended filesystem,縮寫為ext4)是Linux系統(tǒng)下的日志文件系統(tǒng),是ext3文件系統(tǒng)的后繼版本。
Ext4的文件系統(tǒng)容量達(dá)到1EB,而文件容量則達(dá)到16TB,這是一個(gè)非常大的數(shù)字了。對(duì)一般的臺(tái)式機(jī)和服務(wù)器而言,這可能并不重要,但對(duì)于大型磁盤陣列的用戶而言,這就非常重要了。
XFS是一個(gè)64位文件系統(tǒng),最大支持8EB減1字節(jié)的單個(gè)文件系統(tǒng),實(shí)際部署時(shí)取決于宿主操作系統(tǒng)的最大塊限制。對(duì)于一個(gè)32位Linux系統(tǒng),文件和文件系統(tǒng)的大小會(huì)被限制在16TB。
?
二者各有特點(diǎn),而性能表現(xiàn)基本上是差不多的。例如,谷歌公司就考慮將EXT2系統(tǒng)升級(jí),最終確定為EXT4系統(tǒng)。谷歌公司表示,他們還考慮過XFS和JFS。結(jié)果顯示,EXT4和XFS的表現(xiàn)類似,不過從EXT2升級(jí)到EXT4比升級(jí)到XFS容易。
?
例子:
cat >> /etc/fstab << EOF
/dev/sdb1 /greenplum xfs rw,nodev,noatime,inode64,allocsize=16m 0 0
EOF
rw,nodev,noatime,nobarrier,inode64
?
cat /etc/fstab
?
?
?
3.6 磁盤訪問策略
Linux磁盤I/O調(diào)度器對(duì)磁盤的訪問支持不同的策略,默認(rèn)的為CFQ,GP建議設(shè)置為deadline
?
查看磁盤的I/O調(diào)度策略,看到默認(rèn)的為[cfq]
?
The deadline scheduler option is recommended. To specify a scheduler until the next system reboot,
run the following:
# echo schedulername > /sys/block/devname/queue/scheduler
?
echo deadline > /sys/block/sda/queue/scheduler
?
linux 7
# grubby --update-kernel=ALL --args="elevator=deadline"
grubby --info=ALL
?
?
3.7 調(diào)整磁盤預(yù)讀扇區(qū)數(shù)
?
fdisk -l
?
檢查
/sbin/blockdev --getra /dev/sda
設(shè)置
/sbin/blockdev --setra 16384 /dev/sda
?
?
在參數(shù)文件 /etc/rc.d/rc.local 中增加
DELL : blockdev --setra 16384 /dev/sd* (紅色部分為硬盤設(shè)備標(biāo)識(shí)) HP:blockdev --setra 16384 /dev/cciss/c?d?*
?
?
3.8 禁用THP
On systems that use grub2 such as RHEL 7.x or CentOS 7.x, use the system utility grubby. This
command adds the parameter when run as root.
# grubby --update-kernel=ALL --args="transparent_hugepage=never"
After adding the parameter, reboot the system.
This cat command checks the state of THP. The output indicates that THP is disabled.
$ cat /sys/kernel/mm/*transparent_hugepage/enabled
always [never]
?
服務(wù)方式注冊(cè)
# 創(chuàng)建 init.d 腳本
echo '#!/bin/sh
case $1 in
start)
if [ -d /sys/kernel/mm/transparent_hugepage ]; then
thp_path=/sys/kernel/mm/transparent_hugepage
elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
thp_path=/sys/kernel/mm/redhat_transparent_hugepage
else
exit 0
fi
?
echo never > ${thp_path}/enabled
echo never > ${thp_path}/defrag
?
unset thp_path
;;
esac' > /etc/init.d/disable-transparent-hugepages
?
# 注冊(cè)systemd文件
echo '[Unit]
Description=Disable Transparent Hugepages
After=multi-user.target
?
[Service]
ExecStart=/etc/init.d/disable-transparent-hugepages start
Type=simple
?
[Install]
WantedBy=multi-user.target' > /etc/systemd/system/disable-thp.service
?
# 磁盤預(yù)讀扇區(qū)數(shù)
/sbin/blockdev --getra /dev/sdb1 # 查看大小
/sbin/blockdev --setra 65535 /dev/sdb1 # 設(shè)置大小
?
# 創(chuàng)建 init.d 腳本
echo '#!/bin/sh
device_name=/dev/sdb1
case $1 in
start)
if mount | grep "^${device_name}" > /dev/null;then
/sbin/blockdev --setra 65535 ${device_name}
else
exit 0
fi
?
unset device_name
;;
esac' > /etc/init.d/blockdev-setra-sdb
?
# 注冊(cè)systemd文件
echo '[Unit]
Description=Blocdev --setra N
After=multi-user.target
?
[Service]
ExecStart=/etc/init.d/blockdev-setra-sdb start
Type=simple
?
[Install]
WantedBy=multi-user.target' > /etc/systemd/system/blockdev-setra-sdb.service
?
# 授權(quán)并設(shè)置開機(jī)啟動(dòng)
chmod 755 /etc/init.d/disable-transparent-hugepages
chmod 755 /etc/init.d/blockdev-setra-sdb
chmod 755 /etc/systemd/system/disable-thp.service
chmod 755 /etc/systemd/system/blockdev-setra-sdb.service
systemctl enable disable-thp blockdev-setra-sdb
?
?
?
3.9 Disable IPC object removal for RHEL 7 or CentOS 7
?
Set this parameter in /etc/systemd/logind.conf on the Greenplum
Database host systems.
RemoveIPC=no
The setting takes effect after restarting the systemd-login service or rebooting the system. To
restart the service, run this command as the root user.
service systemd-logind restart
?
cat /etc/systemd/logind.conf
?
3.10 時(shí)間同步
?
/etc/chrony.conf
?
systemctl status chronyd.service --查看狀態(tài)
systemctl start chronyd.service --啟動(dòng)
systemctl enable chronyd.service --使其開機(jī)自啟
systemctl status chronyd.service
server 10.1.3.1 prefer
?
查看時(shí)間同步源
chronyc sources -v
chronyc sourcestats -v
?
3.11 控制ssh連接數(shù)
/etc/ssh/sshd_config
MaxStartups 10:30:200
?
systemctl restart sshd.service
?
?
?
3.12 系統(tǒng)依賴包
yum -y install epel-release
yum -y install wget cmake3 git gcc gcc-c++ bison flex libedit-devel zlib zlib-devel perl-devel perl-ExtUtils-Embed python-devel libevent libevent-devel libxml2 libxml2-devel libcurl libcurl-devel bzip2 bzip2-devel net-tools libffi-devel openssl-devel
?
第 4章 安裝軟件
4.1 創(chuàng)建用戶和組
master only
?# groupadd gpadmin?# useradd gpadmin -g gpadmin?# passwd gpadmin?New password: <changeme>?Retype new password: <changeme>???echo gpadmin | passwd gpadmin --stdin?
?
?
4.2 root用戶解壓縮和安裝
?
?./greenplum-db-5.10.2-rhel6-x86_64.bin???I HAVE READ AND AGREE TO THE TERMS OF THE ABOVE PIVOTAL SOFTWARE?LICENSE AGREEMENT.?????********************************************************************************?Do you accept the Pivotal Database license agreement? [yes|no]?********************************************************************************???yes???********************************************************************************?Provide the installation path for Greenplum Database or press ENTER to?accept the default installation path: /usr/local/greenplum-db-5.10.2?********************************************************************************???????********************************************************************************?Install Greenplum Database into /usr/local/greenplum-db-5.10.2? [yes|no]?********************************************************************************???yes???********************************************************************************?/usr/local/greenplum-db-5.10.2 does not exist.?Create /usr/local/greenplum-db-5.10.2 ? [yes|no]?(Selecting no will exit the installer)?********************************************************************************???????安裝完成后授權(quán)?????\# chown -R gpadmin /usr/local/greenplum*(在創(chuàng)建gpadmin后執(zhí)行)???\# chgrp -R gpadmin /usr/local/greenplum*(在創(chuàng)建gpadmin后執(zhí)行)?
?
4.3 編輯環(huán)境變量
?
?cat >> .bashrc << EOF?export MASTER_DATA_DIRECTORY=/greenplum/gpdata/master/gpseg-1?source /usr/local/greenplum-db/greenplum_path.sh?EOF?source .bashrc?????cat >> /home/gpadmin/.bash_profile <<EOF ??export MASTER_DATA_DIRECTORY=/greenplum/gpdata/master/gpseg-1?source /usr/local/greenplum-db/greenplum_path.sh?export PGPORT=5432?export PGDATABASE=archdata?EOF???source /home/gpadmin/.bash_profile?
?
?
4.4 進(jìn)行文件配置
?
切換root
?
source /usr/local/greenplum-db/greenplum_path.sh
?
?
?
------只在mdw,smdw執(zhí)行
mkdir /home/gpadmin/gpconfig
chown -R gpadmin:gpadmin /home/gpadmin/gpconfig
?
------只在mdw,smdw執(zhí)行
cat >> /home/gpadmin/gpconfig/all_host <<EOF
mdw
sdw1
sdw2
sdw3
EOF
?
------只在mdw,smdw執(zhí)行
cat >> /home/gpadmin/gpconfig/all_segment <<EOF
sdw1
sdw2
sdw3
EOF
?
chown -R gpadmin:gpadmin /home/gpadmin/gpconfig/all_host
chown -R gpadmin:gpadmin /home/gpadmin/gpconfig/all_segment
?
4.5 設(shè)置主機(jī)免密碼登陸 -
?
source /usr/local/greenplum-db/greenplum_path.sh
?
/usr/local/greenplum-db/bin/gpssh-exkeys -f /home/gpadmin/gpconfig/all_host
?
4.6 確認(rèn)檢查主機(jī)連接狀態(tài)
?
gpssh -f /home/gpadmin/gpconfig/all_host -e "ls -l"
?
?
4.7 批量創(chuàng)建其他節(jié)點(diǎn)的用戶
?
gpssh -f /home/gpadmin/gpconfig/all_segment
?
groupadd gpadmin
useradd gpadmin -g gpadmin
passwd gpadmin
echo gpadmin | passwd gpadmin --stdin
?
?
4.8 gpadmin用戶-互信
?
source /usr/local/greenplum-db/greenplum_path.sh
?
/usr/local/greenplum-db/bin/gpssh-exkeys -f /home/gpadmin/gpconfig/all_host
?
gpssh -f /home/gpadmin/gpconfig/all_host -e "ls -l"
?
4.9 檢查時(shí)間同步
gpssh -f /home/gpadmin/gpconfig/all_host -e "date"
?
4.10 分發(fā)所有seg節(jié)點(diǎn)軟件
?
root執(zhí)行
?
source /usr/local/greenplum-db/greenplum_path.sh
?
gpseginstall -f /home/gpadmin/gpconfig/all_host -u gpadmin -p gpadmin
?
?
4.11 檢查安裝情況
?
o Log in as the gpadmin user and source
? source /usr/local/greenplum-db/greenplum_path.sh
o Use the gpssh utility to see if you can login to all hosts without a password prompt
?
?
4.12 創(chuàng)建相關(guān)目錄(root用戶)
?
mkdir -p /greenplum/gpdata/master
chown gpadmin:gpadmin /greenplum/gpdata/master
?
gpssh -f /home/gpadmin/gpconfig/all_segment -e 'mkdir -p /greenplum/gpdata/primary1'
gpssh -f /home/gpadmin/gpconfig/all_segment -e 'mkdir -p /greenplum/gpdata/primary2'
gpssh -f /home/gpadmin/gpconfig/all_segment -e 'chown -R gpadmin:gpadmin /greenplum/gpdata'
?
?
gpssh -f /home/gpadmin/gpconfig/all_segment -e 'mkdir -p /greenplum/gpdata/mirror1'
gpssh -f /home/gpadmin/gpconfig/all_segment -e 'mkdir -p /greenplum/gpdata/mirror2'
gpssh -f /home/gpadmin/gpconfig/all_segment -e 'chown -R gpadmin:gpadmin /greenplum/gpdata'
?
or 批量創(chuàng)建
gpssh -f /home/gpadmin/gpconfig/all_segment -e 'mkdir -p /greenplum/gpdata/primary{1..2}'
gpssh -f /home/gpadmin/gpconfig/all_segment -e 'chown -R gpadmin:gpadmin /greenplum/gpdata'
?
4.13 驗(yàn)證系統(tǒng)
?
檢查系統(tǒng)參數(shù)和測(cè)試性能
檢查命令:gpcheck -f host_file -m mdw -ssmdw
Validating Hardware Performance
o gpcheckperf can be used to identify hardware and system-level issues on the machines in your Greenplum
Database array.
o Network Performance (gpnetbench*)
? gpcheckperf -f hostfile_gpchecknet_ic1 -r N -d /tmp > subnet1.out
o Disk I/O Performance (dd test) & Memory Bandwidth (stream test)
? gpcheckperf -f hostfile_gpcheckperf -r ds -D -d /data/primary -d /data/mirror
?
?
4.14 驗(yàn)證OS配置
?
source /usr/local/greenplum-db/greenplum_path.sh
gpcheck -f /home/gpadmin/gpconfig/all_host -m mdw
?
?
驗(yàn)證硬件性能--這個(gè)需要確認(rèn)(網(wǎng)絡(luò)和IO)
?
? gpcheckperf -f /home/gpadmin/gpconfig/all_host -r N -d /tmp > checknetwork.out?[root@mdw greenplum-db]# cat checknetwork.out?/usr/local/greenplum-db/./bin/gpcheckperf -f /home/gpadmin/gpconfig/all_host -r N -d /tmp???\-------------------?-- NETPERF TEST?\-------------------???====================?== RESULT?====================?Netperf bisection bandwidth test?mdw -> sdw1 = 112.340000?sdw2 -> sdw3 = 112.340000?sdw1 -> mdw = 112.330000?sdw3 -> sdw2 = 112.330000???Summary:?sum = 449.34 MB/sec?min = 112.33 MB/sec?max = 112.34 MB/sec?avg = 112.33 MB/sec?median = 112.34 MB/sec???gpcheckperf -f /home/gpadmin/gpconfig/all_host -r ds -D -d /greenplum/gpdata/primary1 -d /greenplum/gpdata/mirror1 > checkDISKIO.out?[root@mdw greenplum-db]# gpcheckperf -f /home/gpadmin/gpconfig/all_host -r ds -D -d /greenplum/gpdata/primary1 -d /greenplum/gpdata/mirror1?/usr/local/greenplum-db/./bin/gpcheckperf -f /home/gpadmin/gpconfig/all_host -r ds -D -d /greenplum/gpdata/primary1 -d /greenplum/gpdata/mirror1???\--------------------?-- DISK WRITE TEST?\--------------------???\--------------------?-- DISK READ TEST?\--------------------???\--------------------?-- STREAM TEST?\--------------------???====================?== RESULT?====================???disk write avg time (sec): 20.88?disk write tot bytes: 132920115200?disk write tot bandwidth (MB/s): 6074.65?disk write min bandwidth (MB/s): 1476.04 [ mdw]?disk write max bandwidth (MB/s): 1551.18 [sdw3]?-- per host bandwidth --?disk write bandwidth (MB/s): 1476.04 [ mdw]?disk write bandwidth (MB/s): 1537.63 [sdw1]?disk write bandwidth (MB/s): 1509.80 [sdw2]?disk write bandwidth (MB/s): 1551.18 [sdw3]?????disk read avg time (sec): 59.80?disk read tot bytes: 132920115200?disk read tot bandwidth (MB/s): 2175.57?disk read min bandwidth (MB/s): 454.54 [sdw2]?disk read max bandwidth (MB/s): 700.04 [sdw1]?-- per host bandwidth --?disk read bandwidth (MB/s): 520.03 [ mdw]?disk read bandwidth (MB/s): 700.04 [sdw1]?disk read bandwidth (MB/s): 454.54 [sdw2]?disk read bandwidth (MB/s): 500.96 [sdw3]?????stream tot bandwidth (MB/s): 49348.52?stream min bandwidth (MB/s): 12297.76 [ mdw]?stream max bandwidth (MB/s): 12388.57 [sdw2]?-- per host bandwidth --?stream bandwidth (MB/s): 12297.76 [ mdw]?stream bandwidth (MB/s): 12321.47 [sdw1]?stream bandwidth (MB/s): 12388.57 [sdw2]?stream bandwidth (MB/s): 12340.73 [sdw3]?
第 5 章 初始化database
copy配置文件
?
設(shè)置初始化系統(tǒng)文件列表
?
調(diào)整參數(shù)
?
?
初始化database
?
?
gpadmin用戶
?
?gpinitsystem -c /home/gpadmin/gpconfig/gpinitsystem_config -h /home/gpadmin/gpconfig/hostfile_gpinitsystem???如何添加master standby和修改mirror分布策略spread mirror?gpinitsystem -c gpconfigs/gpinitsystem_config -h gpconfigs/hostfile_gpinitsystem -s?standby_master_hostname -S (with a standby master and a spread mirror configuration)?
檢查環(huán)境變量
?
???MASTER_DATA_DIRECTORY=/data/master/gpseg-1???GPHOME=/usr/local/greenplum-db???PGDATABASE=gpadmin???[gpadmin@mdw ~]$ cat .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 MASTER_DATA_DIRECTORY=/greenplum/gpdata/master/gpseg-1?source /usr/local/greenplum-db/greenplum_path.sh?export PGPORT=5432?export PGDATABASE=archdata???
第 6 章 連接測(cè)試
?
?
6.1設(shè)置gpadmin遠(yuǎn)程訪問密碼
psql postgres gpadmin
alter user gpadmin encrypted password 'gpadmin';
\q
?
6.2查詢測(cè)試
psql -hmdw -p 5432 -d postgres -U gpadmin -c 'select dfhostname, dfspace,dfdevice from gp_toolkit.gp_disk_free order by dfhostname;'
?
[gpadmin@mdw ~]$ psql -hmdw -p 5432 -d postgres -U gpadmin -c 'select dfhostname, dfspace,dfdevice from gp_toolkit.gp_disk_free order by dfhostname;'
dfhostname | dfspace | dfdevice
------------+----------+----------------------------
sdw1 | 98708120 | /dev/mapper/VolGroup-root
sdw1 | 98708120 | /dev/mapper/VolGroup-root
sdw2 | 98705600 | /dev/mapper/VolGroup-root
sdw2 | 98705600 | /dev/mapper/VolGroup-root
sdw3 | 98705144 | /dev/mapper/VolGroup-root
sdw3 | 98705144 | /dev/mapper/VolGroup-root
(6 rows)
?
psql -h hmdw -p 5432 -d postgres -U gpadmin -c '\l+'
[gpadmin@mdw ~]$ psql -h mdw -p 5432 -d postgres -U gpadmin -c '\l+'
List of databases
Name | Owner | Encoding | Access privileges | Size | Tablespace | Description
-----------+---------+----------+---------------------+-------+------------+---------------------------
postgres | gpadmin | UTF8 | | 73 MB | pg_default |
template0 | gpadmin | UTF8 | =c/gpadmin | 72 MB | pg_default |
: gpadmin=CTc/gpadmin
template1 | gpadmin | UTF8 | =c/gpadmin | 73 MB | pg_default | default template database
: gpadmin=CTc/gpadmin
(3 rows)
?
[gpadmin@mdw ~]$
?
第 7 章 常用命令
?
數(shù)據(jù)庫(kù)啟動(dòng):gpstart 常用可參數(shù): -a : 直接啟動(dòng),不提示終端用戶輸入確認(rèn) -m:只啟動(dòng)master 實(shí)例,主要在故障處理時(shí)使用
數(shù)據(jù)庫(kù)停止:gpstop: 常用可參數(shù):-a:直接停止,不提示終端用戶輸入確認(rèn) -m:只停止master 實(shí)例,與gpstart –m 對(duì)應(yīng)使用 -M fast:停止數(shù)據(jù)庫(kù),中斷所有數(shù)據(jù)庫(kù)連接,回滾正在運(yùn) 行的事務(wù) -u:不停止數(shù)據(jù)庫(kù),只加載pg_hba.conf 和postgresql.conf中運(yùn)行時(shí)參數(shù),當(dāng)改動(dòng)參數(shù)配置時(shí)候使用。 評(píng):-a用在shell里,最多用的還是-M fast。
查看實(shí)例配置和狀態(tài) select * from gp_configuration order by 1 ; 主要字段說(shuō)明: Content:該字段相等的兩個(gè)實(shí)例,是一對(duì)P(primary instance)和M(mirror Instance) Isprimary:實(shí)例是否作為primary instance 運(yùn)行 Valid:實(shí)例是否有效,如處于false 狀態(tài),則說(shuō)明該實(shí)例已經(jīng)down 掉。 Port:實(shí)例運(yùn)行的端口 Datadir:實(shí)例對(duì)應(yīng)的數(shù)據(jù)目錄
gpstate :顯示Greenplum數(shù)據(jù)庫(kù)運(yùn)行狀態(tài),詳細(xì)配置等信息 常用可參數(shù):-c:primary instance 和 mirror instance 的對(duì)應(yīng)關(guān)系 -m:只列出mirror 實(shí)例的狀態(tài)和配置信息 -f:顯示standby master 的詳細(xì)信息 -Q:顯示狀態(tài)綜合信息 該命令默認(rèn)列出數(shù)據(jù)庫(kù)運(yùn)行狀態(tài)匯總信息,常用于日常巡檢。 評(píng):最開始由于網(wǎng)卡驅(qū)動(dòng)的問題,做了mirror后,segment經(jīng)常down掉,用-Q參數(shù)查詢綜合信息還是比較有用的。
查看用戶會(huì)話和提交的查詢等信息 select * from pg_stat_activity 該表能查看到當(dāng)前數(shù)據(jù)庫(kù)連接的IP 地址,用戶名,提交的查詢等。另外也可以在master 主機(jī)上查看進(jìn)程,對(duì)每個(gè)客戶端連接,master 都會(huì)創(chuàng)建一個(gè)進(jìn)程。ps -ef |grep -i postgres |grep -i con 評(píng):常用的命令,我經(jīng)常用這個(gè)查看數(shù)據(jù)庫(kù)死在那個(gè)sql上了。
查看數(shù)據(jù)庫(kù)、表占用空間 select pg_size_pretty(pg_relation_size('schema.tablename')); select pg_size_pretty(pg_database_size('databasename')); 必須在數(shù)據(jù)庫(kù)所對(duì)應(yīng)的存儲(chǔ)系統(tǒng)里,至少保留30%的自由空間,日常巡檢,要檢查存儲(chǔ)空間的剩余容量。 評(píng):可以查看任何數(shù)據(jù)庫(kù)對(duì)象的占用空間,pg_size_pretty可以顯示如mb之類的易讀數(shù)據(jù),另外,可以與pg_tables,pg_indexes之類的系統(tǒng)表鏈接,統(tǒng)計(jì)出各類關(guān)于數(shù)據(jù)庫(kù)對(duì)象的空間信息。
收集統(tǒng)計(jì)信息,回收空間 定期使用Vacuum analyze tablename 回收垃圾和收集統(tǒng)計(jì)信息,尤其在大數(shù)據(jù)量刪除,導(dǎo)入以后,非常重要 評(píng):這個(gè)說(shuō)的不全面,vacuum分兩種,一種是analize,優(yōu)化查詢計(jì)劃的,還有一種是清理垃圾數(shù)據(jù),postres刪除工作,并不是真正刪除數(shù)據(jù),而是在被刪除的數(shù)據(jù)上,坐一個(gè)標(biāo)記,只有執(zhí)行vacuum時(shí),才會(huì)真正的物理刪除,這個(gè)非常重用,有些經(jīng)常更新的表,各種查詢、更新效率會(huì)越來(lái)越慢,這個(gè)多是因?yàn)闆]有做vacuum的原因。
查看數(shù)據(jù)分布情況 兩種方式: l Select gp_segment_id,count(*) from tablename group by 1 ; l 在命令運(yùn)行:gpskew -t public.ate -a postgres 如數(shù)據(jù)分布不均勻,將發(fā)揮不了并行計(jì)算的優(yōu)勢(shì),嚴(yán)重影響性能。 評(píng):非常用,gp要保障數(shù)據(jù)分布均勻。
實(shí)例恢復(fù):gprecoverseg 通過gpstate 或gp_configuration 發(fā)現(xiàn)有實(shí)例down 掉以后,使用該命令進(jìn)行回復(fù)。
查看鎖信息: SELECT locktype, database, c.relname, l.relation, l.transactionid, l.transaction, l.pid, l.mode, l.granted, a.current_query FROM pg_locks l, pg_class c, pg_stat_activity a WHERE l.relation=c.oid AND l.pid=a.procpid ORDER BY c.relname; 主要字段說(shuō)明: relname: 表名 locktype、mode 標(biāo)識(shí)了鎖的類型
explain:在提交大的查詢之前,使用explain分析執(zhí)行計(jì)劃、發(fā)現(xiàn)潛在優(yōu)化機(jī)會(huì),避免將系統(tǒng)資源熬盡。 評(píng):少寫了個(gè)analyze,如果只是explain,統(tǒng)計(jì)出來(lái)的執(zhí)行時(shí)間,是非常坑爹的,如果希望獲得準(zhǔn)確的執(zhí)行時(shí)間,必須加上analyze。
數(shù)據(jù)庫(kù)備份 gp_dump 常用參數(shù):-s: 只導(dǎo)出對(duì)象定義(表結(jié)構(gòu),函數(shù)等) -n: 只導(dǎo)出某個(gè)schema gp_dump 默認(rèn)在master 的data 目錄上產(chǎn)生這些文件: gp_catalog_1__ :關(guān)于數(shù)據(jù)庫(kù)系統(tǒng)配置的備份文件 gp_cdatabase_1:數(shù)據(jù)庫(kù)創(chuàng)建語(yǔ)句的備份文件 gp_dump_1:數(shù)據(jù)庫(kù)對(duì)象ddl語(yǔ)句 gp_dump_status_1:備份操作的日志 在每個(gè)segment instance 上的data目錄上產(chǎn)生的文件: gp_dump_0:用戶數(shù)據(jù)備份文件 gp_dump_status_0:備份日志
數(shù)據(jù)庫(kù)恢復(fù) gp_restore 必參數(shù):--gp-k=key :key 為gp_dump 導(dǎo)出來(lái)的文件的后綴時(shí)間戳 -d dbname :將備份文件恢復(fù)到dbname
登陸與退出Greenplum #正常登陸 psql gpdb psql -d gpdb -h gphostm -p 5432 -U gpadmin #使用utility方式 PGOPTIONS="-c gp_session_role=utility" psql -h -d dbname hostname -p port #退出 在psql命令行執(zhí)行\(zhòng)q
參數(shù)查詢 psql -c 'SHOW ALL;' -d gpdb gpconfig --show max_connections 評(píng):這個(gè)用,可以管道給grep。
創(chuàng)建數(shù)據(jù)庫(kù) createdb -h localhost -p 5432 dhdw
創(chuàng)建GP文件系統(tǒng) # 文件系統(tǒng)名 gpfsdw # 子節(jié)點(diǎn),視segment數(shù)創(chuàng)建目錄 mkdir -p /gpfsdw/seg1 mkdir -p /gpfsdw/seg2 chown -R gpadmin:gpadmin /gpfsdw # 主節(jié)點(diǎn) mkdir -p /gpfsdw/master chown -R gpadmin:gpadmin /gpfsdw gpfilespace -o gpfilespace_config gpfilespace -c gpfilespace_config
創(chuàng)建GP表空間 psql gpdb create tablespace TBS_DW_DATA filespace gpfsdw; SET default_tablespace = TBS_DW_DATA;
刪除GP數(shù)據(jù)庫(kù) gpdeletesystem -d /gpmaster/gpseg-1 -f
查看segment配置 select * from gp_segment_configuration;
文件系統(tǒng) select * from pg_filespace_entry;
磁盤、數(shù)據(jù)庫(kù)空間 SELECT * FROM gp_toolkit.gp_disk_free ORDER BY dfsegment; SELECT * FROM gp_toolkit.gp_size_of_database ORDER BY sodddatname; 日志 SELECT * FROM gp_toolkit.gp_log_master_ext; SELECT * FROM gp_toolkit.gp_log_segment_ext;
表數(shù)據(jù)分布 SELECT gp_segment_id, count(*) FROM GROUP BY gp_segment_id;
表占用空間 SELECT relname as name, sotdsize/1024/1024 as size_MB, sotdtoastsize as toast, sotdadditionalsize as other FROM gp_toolkit.gp_size_of_table_disk as sotd, pg_class WHERE sotd.sotdoid = pg_class.oid ORDER BY relname;
索引占用空間 SELECT soisize/1024/1024 as size_MB, relname as indexname FROM pg_class, gp_toolkit.gp_size_of_index WHERE pg_class.oid = gp_size_of_index.soioid AND pg_class.relkind='i';
OBJECT的操作統(tǒng)計(jì) SELECT schemaname as schema, objname as table, usename as role, actionname as action, subtype as type, statime as time FROM pg_stat_operations WHERE objname = '';
鎖 SELECT locktype, database, c.relname, l.relation, l.transactionid, l.transaction, l.pid, l.mode, l.granted, a.current_query FROM pg_locks l, pg_class c, pg_stat_activity a WHERE l.relation=c.oid AND l.pid=a.procpid ORDER BY c.relname;
隊(duì)列 SELECT * FROM pg_resqueue_status;
gpfdist外部表 # 啟動(dòng)服務(wù) gpfdist -d /share/txt -p 8081 –l /share/txt/gpfdist.log & # 創(chuàng)建外部表,分隔符為’/t’ drop EXTERNAL TABLE TD_APP_LOG_BUYER; CREATE EXTERNAL TABLE TD_APP_LOG_BUYER ( IP text, ACCESSTIME text, REQMETHOD text, URL text, STATUSCODE int, REF text, name text, VID text) LOCATION ('gpfdist://gphostm:8081/xxx.txt') FORMAT 'TEXT' (DELIMITER E'/t' FILL MISSING FIELDS) SEGMENT REJECT LIMIT 1 percent;
創(chuàng)建普通表 create table test select * from TD_APP_LOG_BUYER; # 索引 # CREATE INDEX idx_test ON test USING bitmap (ip); # 查詢數(shù)據(jù) select ip , count() from test group by ip order by count(); gpload # 創(chuàng)建控制文件 # 加載數(shù)據(jù) gpload -f my_load.yml copy COPY country FROM '/data/gpdb/country_data' WITH DELIMITER '|' LOG ERRORS INTO err_country SEGMENT REJECT LIMIT 10 ROWS;
gpfdist外部表 創(chuàng)建可寫外部表 CREATE WRITABLE EXTERNAL TABLE unload_expenses ( LIKE expenses ) LOCATION ('gpfdist://etlhost-1:8081/expenses1.out', 'gpfdist://etlhost-2:8081/expenses2.out') FORMAT 'TEXT' (DELIMITER ',') DISTRIBUTED BY (exp_id); # 寫權(quán)限 GRANT INSERT ON writable_ext_table TO ; # 寫數(shù)據(jù) INSERT INTO writable_ext_table SELECT * FROM regular_table; copy COPY (SELECT * FROM country WHERE country_name LIKE 'A%') TO '/home/gpadmin/a_list_countries.out'; 執(zhí)行sql文件 psql gpdbname –f yoursqlfile.sql 或者psql登陸后執(zhí)行 \i yoursqlfile.sql
總結(jié)
以上是生活随笔為你收集整理的Greenplum学习实践-【安装部署】-2、 5.10集群部署的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win10修改远程桌面3389端口
- 下一篇: 因为热爱,所以坚持;因为坚持,得以突破!