Thứ Ba, 1 tháng 12, 2020

Quản lý tài nguyên trong solaris

  1. RAM

Tổng RAM:

/usr/sbin/prtconf | grep -i memory

RAM sử dụng cả máy chủ:

# vmstat 1 100 (cột free (KB))

Hoặc

# sar -r 1 100 (cột freemem(KB) * 8 do pagesize=8k)

Hoặc

# prstat -Z (cột RSS) (kết quả khác so với vmstat và sar do câu lệnh này chỉ tính memory cấp cho các process không có cache)

RAM sử dụng của từng process:

To determine the available RAM and swap space, enter the following command:

# sar -r -i n

 

From <https://docs.oracle.com/cd/E11882_01/install.112/e24351/toc.htm#BABHECFG>

 

 

# prstat -a (cột RSS)

Script chuẩn từ Oracle

oracle@billinggw2$ more mem.sh

#!/bin/ksh

PAGESZ="/usr/bin/pagesize"

BC="/bin/bc"

 

SCALE=2

WAIT=300

MAXCOUNT=3

 

 

NMUPM="$ORACLE_HOME/bin/nmupm osLoad"

 

 

echo "Calulates average memory (interval $WAIT (s)) usage on Solaris using nmupm"

 

PAGESIZE=`$PAGESZ`

result1=`$NMUPM | awk -F"|" '{print $14 }'`

REALMEM=`$NMUPM | awk -F"|" '{print $13 }'`

#echo $result1

 

X=0

while [ $X -le $MAXCOUNT ]

do

 

sleep $WAIT

 

result2=`$NMUPM | awk -F"|" '{print $14 }'`

#echo $result2

DIFF="($result2 - $result1) * $PAGESIZE / 1024 / $WAIT"

RESULT=$($BC << EOF

scale=$SCALE

(${DIFF})

EOF)

 

MEMREL="$RESULT / $REALMEM * 100"

MEMPCT=$($BC << EOF

scale=$SCALE

(${MEMREL})

EOF)

 

#echo $result1

echo "Memory $REALMEM [kB] Freemem $RESULT [kB] %Free $MEMPCT"

result1=$result2

 

X=$((X+1))

done

Check memory thực tế sử dụng (cho process, cache, kernel OS)

echo ::memstat | mdb -k

Page Summary           Pages                MB  %Tot

------------     ----------------  ----------------  ----

Kernel                    1095242              8556   13%  --> Kernel

ZFS File Data          362002              2828   4% --> cache ZFS

Anon                      6432459             50253  78%  --> Ứng Dụng/DB/Dịch vụ hệ thống

Exec and libs             34096               266 0%

Page cache                 47077               367   1%  --> cache

Free (cachelist)        129667              1013   2%

Free (freelist)           134675              1052   2%

 

Total                     8235218             64337

Physical                  8213541             64168

 

root@mobicard2 # echo ::memstat | mdb -k

Page Summary       Pages           MB   %Tot

------------ ----------------  ----------------  ----

Kernel                1014894           7928    5%     --> Kernel

Anon                 11853058         92602 64%      --> Ứng Dụng/DB/Dịch vụ hệ thống

Exec and libs           86908            678   0%

Page cache             255602         1996   1%      --> Cache

Free (cachelist)       324706        2536   2%

Free (freelist)       4989239       38978 27%

 

RAM giảm dần theo process

Prstat -s size

2. CPU

CPU của cả máy chủ:

prstat -Z

Chú ý %CPU

CPU của từng process

prstat -a

Chú ý những process chiếm tải cao (của user nào, chiếm bao nhiêu)

Tăng tải CPU

 

dd if=/dev/zero of=/dev/null&dd if=/dev/zero of=/dev/null

 

 

#!/bin/bash

 

/usr/bin/kstat -m cpu_info | egrep "chip_id|core_id|module: cpu_info" > /var/tmp/cpu_info.log

 

nproc=`(grep chip_id /var/tmp/cpu_info.log | awk '{ print $2 }' | sort -u | wc -l | tr -d ' ')`

ncore=`(grep core_id /var/tmp/cpu_info.log | awk '{ print $2 }' | sort -u | wc -l | tr -d ' ')`

vproc=`(grep 'module: cpu_info' /var/tmp/cpu_info.log | awk '{ print $4 }' | sort -u | wc -l | tr -d ' ')`

 

nstrandspercore=$(($vproc/$ncore))

ncoresperproc=$(($ncore/$nproc))

 

speedinmhz=`(/usr/bin/kstat -m cpu_info | grep clock_MHz | awk '{ print $2 }' | sort -u)`

speedinghz=`echo "scale=2; $speedinmhz/1000" | bc`

 

echo "Total number of physical processors: $nproc"

echo "Number of virtual processors: $vproc"

echo "Total number of cores: $ncore"

echo "Number of cores per physical processor: $ncoresperproc"

echo "Number of hardware threads (strands or vCPUs) per core: $nstrandspercore"

echo "Processor speed: $speedinmhz MHz ($speedinghz GHz)"

 

# now derive the vcpu-to-core mapping based on above information #

 

echo -e "\n** Socket-Core-vCPU mapping **"

let linenum=2

 

for ((i = 1; i <= ${nproc}; ++i ))

do

     chipid=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk '{ print $2 }'`

     echo -e "\nPhysical Processor $i (chip id: $chipid):"

 

     for ((j = 1; j <= ${ncoresperproc}; ++j ))

     do

             let linenum=($linenum + 1)

             coreid=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk '{ print $2 }'`

             echo -e "\tCore $j (core id: $coreid):"

 

             let linenum=($linenum - 2)

             vcpustart=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk '{ print $4 }'`

 

             let linenum=(3 * $nstrandspercore + $linenum - 3)

             vcpuend=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk '{ print $4 }'`

 

             echo -e "\t\tvCPU ids: $vcpustart - $vcpuend"

             let linenum=($linenum + 4)

     done

done

 

rm /var/tmp/cpu_info.log

3. Swap

Tổng dung lượng:

root@testcard1 # swap -s

total: 69180800k bytes allocated + 37439912k reserved = 106620712k used, 2873480k available

 

 

Dung lượng còn trống

To determine the available RAM and swap space, enter the following command:

# sar -r -i n

 

From <https://docs.oracle.com/cd/E11882_01/install.112/e24351/toc.htm#BABHECFG>

 

# swap -s

total: 69180800k bytes allocated + 37439912k reserved = 106620712k used, 2873480k available

# vmstat 5

 0 0 0 2862944 68012136 91 240 37 0 0 0  0  0  0  7  7 11162 16831 13314 2 1 97

 0 0 0 2871272 68013064 128 582 34 0 0 0 0  0  0  0  0 11257 11995 13354 2 1 97

 

# sar -r 1 100

(Cột Freeswap * 512 bytes)

Hoặc:


Thủ tục thêm swap bằng file:

--1
# swap -s
total: 44750504k bytes allocated + 3550360k reserved = 48300864k used, 143647648k available
--2
# swap -l
swapfile             dev  swaplo blocks   free
/dev/zvol/dsk/swappool/swap 256,1      16 268435440 211978800
--3
# df -k /
Filesystem                kbytes     used       avail       capacity  Mounted on
rpool/ROOT/10u9S_144534   70189056   11505600   22912949    34%       /
--4
# mkdir -p /usr/local/swap
# mkfile 20m /usr/local/swap/newswap
# swap -a /usr/local/swap/newswap
--Verify
# swap -l
# swap -s
--Remove
# swap -d /usr/local/swap/newswap 
# swap -l
# swap -s
Thêm swap bằng  physical disk:

Kiểm tra swap devices hiện tại:

bash-3.00# swap -l
swapfile dev swaplo blocks free
/dev/zvol/dsk/rpool/swap 181,1 8 1048568 1048568

Add c1t2d0 vào swap

bash-3.00# format
Searching for disks...done
AVAILABLE DISK SELECTIONS:
0. c1t0d0
/pci@0,0/pci15ad,1976@10/sd@0,0
1. c1t1d0
/pci@0,0/pci15ad,1976@10/sd@1,0
2. c1t2d0
/pci@0,0/pci15ad,1976@10/sd@2,0
Specify disk (enter its number):

bash-3.00# swap -a /dev/dsk/c1t2d0s2

Kiểm tra swap devices hiện tại:

bash-3.00# swap -l
swapfile dev swaplo blocks free
/dev/zvol/dsk/rpool/swap 181,1 8 1048568 1048568
/dev/dsk/c1t2d0s2 30,194 8 2091000 2091000
Add entry vào Vfstab:
# vi /etc/vfstab
/dev/zvol/dsk/rpool/swap - - swap - no -
/dev/dsk/c1t2d0s2 - - swap - no -

Để bỏ đĩa vừa add vào  

bash-3.00# swap -d /dev/dsk/c1t2d0s2
Add swap mới bằng zfs dataset
Tạo zfs dataset cho swap:
bash-3.00# zfs create -V 900M rpool/swap1

Liệt kê zfs filesystems:

bash-3.00# zfs list
NAME USED AVAIL REFER MOUNTPOINT
rpool 4.59G 3.22G 34.5K /rpool
rpool/ROOT 3.58G 3.22G 21K legacy
rpool/ROOT/new_stage3 126K 3.22G 3.58G /.alt.new_stage3
rpool/ROOT/sol_stage2 3.58G 3.22G 3.57G /
rpool/ROOT/sol_stage2@new_stage3 1.53M - 3.58G -
rpool/dump 512M 3.22G 512M -
rpool/swap 528M 3.74G 16K -
swappool 929M 47.3M 21K /swappool
rpool/swap1 929M 929M 16K -

Activate New swap:

bash-3.00# swap -a /dev/zvol/dsk/rpool/swap1
bash-3.00# swap -l
swapfile dev swaplo blocks free
/dev/zvol/dsk/rpool/swap 181,1 8 1048568 1048568
/dev/zvol/dsk/swappool/swap1 181,3 8 1843192 1843192

4. Iostat, vmstat với nhãn thời gian

vmstat 2 10000 |while read line; do echo "$line"  "`date +%T`" ;done

Iostat -xnd 2 10000 |while read line; do echo "$line"  "`date +%T`" ;done


KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH: 📧 Mail: binhoracle@gmail.com ☎️ Mobile: 0902912888 ⚡️ Skype: tranbinh48ca 👨 Facebook: https://www.facebook.com/BinhOracleMaster 👨 Inbox Messenger: https://m.me/101036604657441 (profile) 👨 Fanpage: https://www.facebook.com/tranvanbinh.vn 👨 Inbox Fanpage: https://m.me/tranvanbinh.vn 👨👩 Group FB: https://www.facebook.com/groups/OracleDBAVietNam 👨 Website: http://www.tranvanbinh.vn 👨 Blogger: https://tranvanbinhmaster.blogspot.com 🎬 Youtube: http://bit.ly/ytb_binhoraclemaster 👨 Tiktok: https://www.tiktok.com/@binhoraclemaster?lang=vi 👨 Linkin: https://www.linkedin.com/in/binhoracle 👨 Twitter: https://twitter.com/binhoracle 👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội #OracleTutorial #OracleDBA #OracleDatabaseAdministration #học oracle database #oca #ocp #oce #ocm

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master