docker-compose

sudo pip install -U docker-compose

编写

version: '3.2'
services:
  db:
    image: mysql:5.7.21
    container_name: mysql
    hostname: mysql-test-1
    restart: always
    ports:
      - 3306:3306
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=YES
    volumes:
      - ./tmp:/var/lib/mysql

  broker:
    image: redis:3.0-alpine
    command: redis-server 
    container_name: broker
    hostname: broker-test-1
    restart: always
    ports:
      - 6379:6379
    volumes:
      - ./tmp:/var/lib/redis

拉起 docker

docker-compose up -d

关闭 swap 操作

检查:

free -m # 应该 Swap 显示全是 0

备份 /etc/fstab

cp /etc/fstab /tmp/fstab.`date +%F`

删除 /etc/fstab 中 swap 挂载项

vim /etc/fstab

关闭所有 swap

swapoff -a

观察进程使用 swap 和 swapoff -a 之后回收情况,对于不能回收 swap 的进程需要安排时间重启


free -m
for file in /proc/*/status ; do cat $file | awk '/Name|^Pid|VmSwap/{printf $2 " " $3 $4}END{ print ""}' | grep kB | grep -v '0 kB' ; done | sort -k 3 -n