当前位置: 首页 > article >正文

flink on k8s

1.修改host文件

vi /etc/hosts

添加如下内容 这样搭集群的时候就不用记ip了

#::1	localhost	localhost.localdomain	localhost6	localhost6.localdomain6


127.0.0.1	localhost	localhost.localdomain	localhost4	localhost4.localdomain4
165.154.221.97 tlb-001 k8s01 k8s-master-01
165.154.187.67 tlb-002 k8s02 k8s-master-02
165.154.104.175 tlb-003 k8s03 k8s-node-01
123.58.199.75 tlb-004 k8s04 k8s-node-02
165.154.105.68 tlb-005 k8s05 k8s-vip

2.配置免密登录

每台机器上都执行 

ssh-keygen -t rsa

ssh-copy-id -i ~/.ssh/id_rsa.pub k8s01

ssh-copy-id -i ~/.ssh/id_rsa.pub k8s02

ssh-copy-id -i ~/.ssh/id_rsa.pub k8s03

ssh-copy-id -i ~/.ssh/id_rsa.pub k8s04

ssh-copy-id -i ~/.ssh/id_rsa.pub k8s05

3.多机器批量执行脚本编写并使用

#!/bin/bash

# 检查参数数量
if [ "$#" -ne 2 ]; then
    echo "用法: $0 '主机列表' '命令列表'"
    echo "示例: $0 'k8s01 k8s02 k8s03 k8s04 k8s05' 'cd /aaa/bbb;mkdir ccc'"
    exit 1
fi

# 获取参数
HOSTS=$1
COMMANDS=$2

# 将主机列表转换为数组
IFS=' ' read -r -a HOST_ARRAY <<< "$HOSTS"

# 创建日志目录
LOG_DIR="logs_$(date +%Y%m%d%H%M%S)"
mkdir "$LOG_DIR"

# 遍历主机并在每台机器上执行命令
for HOST in "${HOST_ARRAY[@]}"; do
    {
        echo "在 $HOST 上执行命令..."
        ssh "$HOST" "$COMMANDS"
        echo "$HOST: 命令执行完毕。"
    } | tee "$LOG_DIR/$HOST.log" &  # 将输出同时发送到日志文件和控制台
done

# 等待所有后台任务完成
wait

echo "所有命令执行完毕,日志保存在 $LOG_DIR 目录中。"
 

4 批量执行安装防火墙并关闭

/opt/juege/shell-scripts/batch-execute.sh 'k8s01 k8s02 k8s03 k8s04 k8s05' 'yum install firewalld -y;systemctl stop firewalld;systemctl disable firewalld;systemctl status firewalld'

5.安全策略级别设置

/opt/juege/shell-scripts/batch-execute.sh 'k8s01 k8s02 k8s03 k8s04 k8s05' '

getenforce;setenforce 0;getenforce'

6.批量文件传输脚本

#!/bin/bash

# 检查参数数量
if [ "$#" -ne 3 ]; then
    echo "用法: $0 '服务器列表' '要传输的文件路径' '远程目标目录'"
    echo "示例: $0 'k8s01 k8s02 k8s03 k8s04 k8s05' /path/to/file /remote/directory"
    exit 1
fi

# 获取参数
SERVERS=$1  # 服务器列表
SOURCE_FILE=$2  # 本地文件路径
REMOTE_DIR=$3  # 远程目录

# 将服务器列表转换为数组
IFS=' ' read -r -a SERVER_ARRAY <<< "$SERVERS"

# 遍历服务器并将文件传输到每个服务器的指定目录
for SERVER in "${SERVER_ARRAY[@]}"; do
    echo "正在将文件 $SOURCE_FILE 传输到 $SERVER:$REMOTE_DIR..."
    
    # 使用 scp 传输文件到远程服务器
    scp "$SOURCE_FILE" "$SERVER:$REMOTE_DIR"
    
    if [ $? -eq 0 ]; then
        echo "文件成功传输到 $SERVER:$REMOTE_DIR"
    else
        echo "文件传输到 $SERVER 失败!"
    fi
done

echo "所有传输任务完成。"
 

6.设置swap分区

设置swap分区、关闭大页面压缩(所有节点)——性能考虑

Linux中Swap分区(即:交换分区),类似于Windows的虚拟内存,就是当内存不足的时候,把一部分硬盘空间虚拟成内存使用,从而解决内存容量不足的情况。

在大数据应用中,使用Swap分区会降低性能,通常需要关闭掉

脚本如下

执行批量传输命令

./transfer_file.sh 'k8s02 k8s03 k8s04 k8s05' /opt/juege/shell-scripts/close-swap-and-transparent-page.sh /opt/juege/shell-scripts

#!/bin/bash

# 设置 swappiness 为 0
sysctl vm.swappiness=0
echo 'vm.swappiness=0' >> /etc/sysctl.conf
sysctl -p

# 关闭当前 swap 分区
swapoff -a
# 注释掉 /etc/fstab 中的 swap 行
sed -i '/swap/s/^/#/' /etc/fstab

# 禁用透明大页面
echo never > /sys/kernel/mm/transparent_hugepage/defrag
echo never > /sys/kernel/mm/transparent_hugepage/enabled

# 添加到 /etc/rc.local 以永久禁用透明大页面
echo 'echo never > /sys/kernel/mm/transparent_hugepage/defrag' >> /etc/rc.local
echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local

# 确保 /etc/rc.local 是可执行的
chmod +x /etc/rc.local

echo "Swap 分区已关闭,透明大页面已禁用,Swappiness 已设置为 0。"
 

7.ntp设置

/opt/juege/shell-scripts/batch-execute.sh 'k8s01 k8s02 k8s03 k8s04 k8s05' '

yum -y install ntp'

vi /etc/ntp.conf (k8s01执行)

driftfile /var/lib/ntp/drift
restrict 165.154.221.97 mask 255.255.255.0 nomodify notrap
server ntp.aliyun.com
fudge ntp.aliyun.com stratum 10
# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography. 
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor

其它节点执行

driftfile /var/lib/ntp/drift
server k8s01
# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography. 
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor

 /opt/juege/shell-scripts/batch-execute.sh 'k8s01 k8s02 k8s03 k8s04 k8s05' '

service ntpd restart;systemctl enable ntpd.service'

ntpdc -c loopinfo


http://www.kler.cn/news/314153.html

相关文章:

  • 79篇vs13篇!本周中国学者发文量远超外国学者| NHANES数据库周报(8.28~9.3)
  • 执行matlab后进行RTL功能仿真check
  • 基于开源鸿蒙(OpenHarmony)的【智能家居综合应用】系统
  • 代理模式---静态代理和动态代理
  • JVM内存学习
  • Lodash的特点和功能
  • WGAN算法
  • 信奥初赛解析:1-3-计算机软件系统
  • YOLOv5模型部署教程
  • 小阿轩yx-通过state模块定义主机状态
  • 【计网面试真题】If-Modified-Since和Etag有什么区别
  • WebServer
  • 6、等级保护政策内容
  • Go语言的垃圾回收(GC)机制的迭代和优化历史
  • Vision Based Navigation :针对航天领域的基于视觉导航机器学习应用生成训练数据集
  • Redis的AOF持久化、重写机制、RDB持久化、混合持久化
  • Springboot常见问题(bean找不到)
  • C#为任意组件开发登录功能的记录
  • android设置实现广告倒计时功能
  • [Python数据可视化]Plotly Express: 地图数据可视化的魅力
  • 第十九节:学习WebFlux与前端响应式-非阻塞-流式通讯(自学Spring boot 3.x的第四天)
  • Java操控Redis (面经之 使用Redis)
  • 【HTTP】构造HTTP请求和状态码
  • [译] Go语言的源起,发展和未来
  • Rust语言入门第七篇-控制流
  • Highcharts甘特图基本用法(highcharts-gantt.js)
  • 安装黑群晖系统,并使用NAS公网助手访问教程(好文)
  • 【系统架构设计师】虚拟机架构风格
  • 十五、差分输入运算放大电路
  • C++——模板初阶