CDH operation and maintenance swap processing
When using the CDH 6.2 big data platform, bloggers found that CDH was running for a long time, and Cloudera Manager management page often displayed a large number of component memory swap warnings when running Spark tasks. The previous bloggers directly ignored it. After all, it is not a big problem. If the yellow warning is not processed for a long time, it will mislead the page to view the cluster status, and the disk space occupied by the swap space will be larger and larger, and the warning will become more and more. Later, there will be abnormalities from yellow to red, and then enter the management interface It was found that when CDH was installed, the Linux operating system selected the swap space address to be used when the CDH memory was insufficient. The test found that manual release would solve the problem. The management interface warned the problem (yellow warning, uncomfortable to look at).
table of Contents
- The role of swap
- CDH warning
- solution
- Open and close swap
The role of swap in Linux
We know that reading and writing data directly from the physical memory is much faster than reading and writing data from the hard disk (hard disk track addressing). Therefore, we hope that all data reading and writing are done in the memory, and the memory size is limited Yes, and the price of memory is higher than that of hard disks, which leads to the concept of physical memory and virtual memory.
Physical memory is the size of memory provided by the system hardware. It is real memory and can be viewed relative to physical memory (free -h).
Virtual memory also has a concept of virtual memory under Linux. Virtual memory is a strategy proposed to meet the shortage of physical memory. It is a piece of logical memory virtualized by disk space. The disk space used as virtual memory is called swap. Space, called Swap Space, (swapon -s) can be viewed.
CDH warning
CDH cluster warning
CDH cluster single machine warning
Swap space
solution
One-time solution
-
Set the swappiness value to 0, which means that swap memory is not used as much as possible
Temporary setting scheme, the setting will not take effect after restart
(Console input) sysctl vm.swappiness=0
View the modified value
# 控制台输入如下语句 cat /proc/sys/vm/swappiness
Set the scheme permanently, the setting will still take effect after restart
# 在/etc/sysctl.conf 文件里添加如下参数 sudo vi /etc/sysctl.conf vm.swappiness=0 # 或者追加模式, 直接在控制台执行如下语句 echo 'vm.swappiness=0' >> /etc/sysctl.conf
-
Close swap completely
First of all, we must ensure that the remaining memory is greater than or equal to the swap usage, otherwise it will crash! According to the memory mechanism, once the swap partition is released, all files stored in the swap partition will be dumped to physical memory. The swap is usually released by remounting the swap partition.
Use free -h to view the remaining memory
free -h
Check the mounting status of swap space
swapon -s
Close the swap space of the mounted partition
# 关闭挂载分区 swapoff /dev/dm-1 # 开启挂载分区 # swapon /dev/dm-1
As shown in the command below,
after the swapoff command is executed, the swap will gradually decrease
Regular cleaning plan
Edit the script /root/cron/cron_clear_swap.sh
#!/bin/bash
#关闭所有交换空间
swapoff -a
#开启所有交换空间
swapon -a
#输出
echo "释放完毕"
Edit a scheduled task
# 执行
crontab -e
# 编辑调度,并保存
00 23 * * * /root/cron/cron_clear_swap.sh
Reference blog
CDH swap memory warning solution
https://blog.csdn.net/lingbo229/article/details/81912248
CDH big data platform memory swap, warning problem
https://blog.csdn.net/weixin_38822045/article/details/107695935