系统配置
关闭终端一直提示的
08;end=xxx;exit=xxxx;start=xxxxxx;machineid=xxxxx;user=xxx;hostname=xxxx;bootid=xxxx;pid=xxxxxx;type=xxxxx;cwd=xxxxx提示1
2
3
4
5mv /usr/lib/systemd/profile.d/80-systemd-osc-context.sh /usr/lib/systemd/profile.d/80-systemd-osc-context.sh.bak
ln -s /dev/null /etc/tmpfiles.d/20-systemd-osc-context.conf
重启
reboot修改主机名
1
hostnamectl set-hostname k8smaster01
修改服务器地址,配置文件
/etc/netplan/00-installer-config.yaml1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21cat /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
ens33:
addresses:
- 192.168.0.21/24
dhcp6: false
match:
macaddress: 00:0c:29:5a:12:3f
nameservers:
addresses:
- 223.5.5.5
- 223.6.6.6
search: []
routes:
- to: default
via: 192.168.0.1
set-name: ens33
version: 2MAC 地址必须要写,不然执行
netplan apply应用修改时会报错修改登录提示信息
1
cd /etc/update-motd.d && chmod -x * && chmod +x 00-header 50-landscape-sysinfo
修改 apt 源
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21# 备份文件
cp /etc/apt/sources.list{,.bak}
cp /etc/apt/sources.list.d/ubuntu.sources{,.bak}
# 修改源
cat > /etc/apt/sources.list.d/ubuntu.sources <<'EOF'
Types: deb
URIs: https://mirrors.aliyun.com/ubuntu/
Suites: resolute resolute-updates resolute-backports
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
Types: deb
URIs: https://mirrors.aliyun.com/ubuntu/
Suites: resolute-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF
# 更新缓存
apt clean && apt update && apt upgrade安装常用软件
1
apt install -y vim bash-completion net-tools network-manager lrzsz unzip
配置时间同步以及时区
1
2
3
4
5
6
7
8
9
10
11
12
13
14# 注释掉原有的时间池
sed -i '/^pool .* prefer$/s/^/# /' /etc/chrony/sources.d/ubuntu-ntp-pools.sources
# 新增时间池
echo 'pool ntp.aliyun.com iburst maxsources 1 nts prefer' >> /etc/chrony/sources.d/ubuntu-ntp-pools.sources
# 重启 chronyd 服务
systemctl restart chronyd
# 同步时间
chronyc sources -v
# 修改时区
timedatectl set-timezone Asia/Shanghai修改 PS1 显示
1
[ -z "$(grep ^PS1 ~/.bashrc)" ] && echo "PS1='\${debian_chroot:+(\$debian_chroot)}\\[\\e[1;32m\\]\\u@\\h\\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ '" >> ~/.bashrc
修改 HISTORY 配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14cat >> /etc/profile << 'EOF'
# 获取登录 IP
USER_IP=$(who -u am i 2>/dev/null | awk '{print $NF}' | sed -e 's/[()]//g')
if [ -z "$USER_IP" ]; then
USER_IP=$(hostname)
fi
# 历史格式:时间 IP 用户名
export HISTTIMEFORMAT="%F %T $USER_IP $(whoami) "
# 实时写入历史文件
export PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
EOF配置 sysctl 内核参数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19[ -z "$(grep 'fs.file-max' /etc/sysctl.conf)" ] && cat >> /etc/sysctl.conf << EOF
fs.file-max = 1000000
fs.inotify.max_user_instances = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.route.gc_timeout = 100
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_synack_retries = 1
net.core.somaxconn = 32768
net.core.netdev_max_backlog = 32768
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_max_orphans = 32768
EOF
sysctl -p修改服务器 limits 限制
1
2
3
4
5
6
7
8
9
10# 临时修改
ulimit -SHn 65535
# 永久生效
sed -i '/^# End/i\* soft nofile 655350' /etc/security/limits.conf
sed -i '/^# End/i\* hard nofile 131072' /etc/security/limits.conf
sed -i '/^# End/i\* soft nproc 655350' /etc/security/limits.conf
sed -i '/^# End/i\* hard nproc 655350' /etc/security/limits.conf
sed -i '/^# End/i\* soft memlock unlimited' /etc/security/limits.conf
sed -i '/^# End/i\* hard memlock unlimited' /etc/security/limits.conf卸载 cloud-init 以及自动更新工具
1
2
3
4
5# 删除云功能和自动升级功能
sudo apt remove -y unattended-upgrades cloud-init
# 清理相关依赖
sudo apt install -f && sudo apt autoremove关闭防火墙 ufw
1
systemctl disable --now ufw
修改 SSH 配置,允许 root 用户登录
1
2
3
4sed -i 's/#PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
systemctl restart ssh.service
systemctl restart ssh.socket
