Subsections of Linux Related
Disable Service
Disable firewall、selinux、dnsmasq、swap service
systemctl disable --now firewalld
systemctl disable --now dnsmasq
systemctl disable --now NetworkManager
setenforce 0
sed -i 's#SELINUX=permissive#SELINUX=disabled#g' /etc/sysconfig/selinux
sed -i 's#SELINUX=permissive#SELINUX=disabled#g' /etc/selinux/config
reboot
getenforce
swapoff -a && sysctl -w vm.swappiness=0
sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab
Example Shell Script
Cleanup
- find first 10 biggest files
dnf install ncdu
# 找出当前目录下最大的10个文件/目录
du -ah . | sort -rh | head -n 10
# 找出家目录下大于100M的文件
find ~ -type f -size +100M -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
- clean cache
rm -rf ~/.cache/*
sudo rm -rf /tmp/*
sudo rm -rf /var/tmp/*
- clean images
# 删除所有停止的容器
podman container prune -y
# 删除所有未被任何容器引用的镜像(悬空镜像)
podman image prune
# 更激进的清理:删除所有未被运行的容器使用的镜像
podman image prune -a
# 清理构建缓存
podman builder prune
# 最彻底的清理:删除所有停止的容器、所有未被容器使用的网络、所有悬空镜像和构建缓存
podman system prune
podman system prune -a # 更加彻底,会删除所有未被使用的镜像,而不仅仅是悬空的
Example Shell Script
Init ES Backup Setting
create an ES backup setting in s3, and make an snapshot after creation
#!/bin/bash
ES_HOST="http://192.168.58.2:30910"
ES_BACKUP_REPO_NAME="s3_fs_repository"
S3_CLIENT="default"
ES_BACKUP_BUCKET_IN_S3="es-snapshot"
ES_SNAPSHOT_TAG="auto"
CHECK_RESPONSE=$(curl -s -k -X POST "$ES_HOST/_snapshot/$ES_BACKUP_REPO_NAME/_verify?pretty" )
CHECKED_NODES=$(echo "$CHECK_RESPONSE" | jq -r '.nodes')
if [ "$CHECKED_NODES" == null ]; then
echo "Doesn't exist an ES backup setting..."
echo "A default backup setting will be generated. (using '$S3_CLIENT' s3 client and all backup files will be saved in a bucket : '$ES_BACKUP_BUCKET_IN_S3'"
CREATE_RESPONSE=$(curl -s -k -X PUT "$ES_HOST/_snapshot/$ES_BACKUP_REPO_NAME?pretty" -H 'Content-Type: application/json' -d "{\"type\":\"s3\",\"settings\":{\"bucket\":\"$ES_BACKUP_BUCKET_IN_S3\",\"client\":\"$S3_CLIENT\"}}")
CREATE_ACKNOWLEDGED_FLAG=$(echo "$CREATE_RESPONSE" | jq -r '.acknowledged')
if [ "$CREATE_ACKNOWLEDGED_FLAG" == true ]; then
echo "Buckup setting '$ES_BACKUP_REPO_NAME' has been created successfully!"
else
echo "Failed to create backup setting '$ES_BACKUP_REPO_NAME', since $$CREATE_RESPONSE"
fi
else
echo "Already exist an ES backup setting '$ES_BACKUP_REPO_NAME'"
fi
CHECK_RESPONSE=$(curl -s -k -X POST "$ES_HOST/_snapshot/$ES_BACKUP_REPO_NAME/_verify?pretty" )
CHECKED_NODES=$(echo "$CHECK_RESPONSE" | jq -r '.nodes')
if [ "$CHECKED_NODES" != null ]; then
SNAPSHOT_NAME="meta-data-$ES_SNAPSHOT_TAG-snapshot-$(date +%s)"
SNAPSHOT_CREATION=$(curl -s -k -X PUT "$ES_HOST/_snapshot/$ES_BACKUP_REPO_NAME/$SNAPSHOT_NAME")
echo "Snapshot $SNAPSHOT_NAME has been created."
else
echo "Failed to create snapshot $SNAPSHOT_NAME ."
fi
Login Without Pwd
copy id_rsa
to other nodes
yum install sshpass -y
mkdir -p /extend/shell
cat >>/extend/shell/fenfa_pub.sh<< EOF
#!/bin/bash
ROOT_PASS=root123
ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
for ip in 101 102 103
do
sshpass -p\$ROOT_PASS ssh-copy-id -o StrictHostKeyChecking=no 192.168.29.\$ip
done
EOF
cd /extend/shell
chmod +x fenfa_pub.sh
./fenfa_pub.sh
Set Http Proxy
set http proxy
export https_proxy=http://localhost:20171