Linux Initialization
Universal:
- Disable Bell In the Terminal
sed -i '/bell-style none/c \set bell-style none' /etc/inputrc
Ubuntu:
- Setup Fountain
sed -i 's@http://.*.ubuntu.com@http://mirrors.aliyun.com@g' /etc/apt/sources.list OR sed -i -e 's/archive.ubuntu.com/mirrors.aliyun.com/g' -e 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
- Install Basic Software
apt install ca-certificates lsb-release software-properties-common tree apt-file net-tools info
-
Collocation Environ (Workstation)
printf "%-8s %-25s %-4s %s\n" @@@@@ ~/.profile '==>' Commence printf "%-8s %-25s %-4s %s\n" @@@@@ ~/.profile '==>' Closure printf "%-8s %-25s %-4s %s\n" @@@@@ ~/.bashrc '==>' Commence printf "%-8s %-25s %-4s %s\n" @@@@@ ~/.bashrc '==>' Closure printf "%-8s %-25s %-4s %s\n" @@@@@ /etc/profile '==>' Commence printf "%-8s %-25s %-4s %s\n" @@@@@ /etc/profile '==>' Closure printf "%-8s %-25s %-4s %s\n" @@@@@ /etc/bash.bashrc '==>' Commence printf "%-8s %-25s %-4s %s\n" @@@@@ /etc/bash.bashrc '==>' Closure printf "%-8s %-25s %-4s %s\n" @@@@@ /etc/profile.d/init.sh '==>' ^_^
-
locale
ll /usr/share/i18n dpkg -L locales dpkg-reconfigure locales update-locale ==> /etc/default/locale update-locale --reset update-locale LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8
-
Remove Redundant Kernel
uname -a dpkg --get-selections | grep linux dpkg --get-selections | grep -e 'linux.*36' -e 'linux.*43' | awk '{print $1}' | xargs dpkg --purge
-
Clear Caches i.e. Firefox ( Workstation )
rm -rf /home/flail/.mozilla/firefox/*.default/Cache
-
Clear APT Caches
apt-get autoclean apt-get clean # /var/cache/apt/archives/ exclude archives/lock archives/partial rm -f /var/cache/apt/*.bin # pkgcache.bin srcpkgcache.bin rm -rf /var/lib/apt/lists/* dpkg -l | grep '^rc' | awk '{print $2}' | xargs dpkg --purge # 清除残余配置文件
- Disable Auto-upgrade
dpkg-reconfigure unattended-upgrades
/etc/apt/apt.conf.d/20auto-upgrades
-
[Time] NTP=time.windows.com ntp1.aliyun.com FallbackNTP=ntp2.aliyun.com ntp3.aliyun.com RootDistanceMaxSec=5 PollIntervalMinSec=32 PollIntervalMaxSec=2048
timedatectl set-ntp true systemctl --now enable systemd-timesyncd timedatectl show | status
RHEL:
- /etc/profile.d/init.sh 初始化脚本
echo 'source /etc/init.d/init' >> ~/.bashrc
#--------------------------------------------------------------------- # History #--------------------------------------------------------------------- export HISTCONTROL=ignoredups export HISTFILE=$HOME/.bash_history export HISTFILESIZE=2000 export HISTSIZE=1000 shopt -s histappend if unset "${HISTTIMEFORMAT}" 2>/dev/null; then export HISTTIMEFORMAT="$(echo -e "\e[7m$(whoami)\e[0m") %F %T>> " typeset -r HISTTIMEFORMAT fi #--------------------------------------------------------------------- # Fedora Default Editor #--------------------------------------------------------------------- if grep -iq 'Fedora' /etc/os-release; then export EDITOR=/usr/bin/vim fi #--------------------------------------------------------------------- # Trap #--------------------------------------------------------------------- trap 'echo -e "\U26A1 \e[30;46mCommand >>$BASH_COMMAND<< failed with error code $?\e[0m \U1F300"' ERR trap 'echo $BASH_COMMAND > /dev/null' DEBUG #--------------------------------------------------------------------- # PS1 #--------------------------------------------------------------------- case $(awk '/^ID/' /etc/os-release | awk -F= '{print tolower($2)}' | tr -d \") in centos | fedora) source /usr/share/git-core/contrib/completion/git-prompt.sh esac function lampooner() { if git rev-parse --git-dir >&/dev/null; then message='' # git_dir if [[ $(git rev-parse --is-inside-git-dir 2>/dev/null) == true ]]; then PS1="\[\e[1;31m\]\u\[\e[0m\]@\[\e[1;32m\]\h\[\e[0m\][\[\e[1;33m\]\t\[\e[0m\]]:\[\e[36m\](GIT_DIR)\[\e[0m\]\[\e[1;34m\]\w\[\e[0m\]\\$ " return 0 fi # cherry-pick if git status 2>/dev/null | grep -q 'cherry-pick'; then message='|Cherry-pick' fi # rebase if git status 2>/dev/null | grep -q 'rebase'; then message+='|Rebase' fi # merge case $(git status --short | head -1 | cut --characters 1-2) in DD | AU | UD | UA | DU | AA | UU) message+='|Merging' ;; *) : ;; esac if git status | grep -qi conclude; then message+='|Resolved' fi # branch branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) if [ "$branch" != "" ]; then if [ "$branch" == HEAD ]; then branch=$(git rev-parse --short HEAD 2>/dev/null) if [ $? != 0 ]; then branch=Lank fi fi fi PS1="\[\e[1;31m\]\u\[\e[0m\]@\[\e[1;32m\]\h\[\e[0m\][\[\e[1;33m\]\t\[\e[0m\]]:\[\e[36m\](${branch}${message})\[\e[0m\]\[\e[1;34m\]\w\[\e[0m\]\\$ " else PS1="\[\e[1;31m\]\u\[\e[0m\]@\[\e[1;32m\]\h\[\e[0m\][\[\e[1;33m\]\t\[\e[0m\]]:\[\e[1;34m\]\w\[\e[0m\]\\$ " fi } function languor() { if git rev-parse --git-dir >&/dev/null; then local msg msg=$(__git_ps1) msg=${msg:1} PS1="${VENV}${CONDA_PROMPT_MODIFIER}\[\e[1;31m\]\u\[\e[0m\]@\[\e[1;32m\]\h\[\e[0m\][\[\e[1;33m\]\t\[\e[0m\]]:\[\e[36m\]${msg}\[\e[0m\]\[\e[1;34m\]\w\[\e[0m\]\\$ " else PS1="${VENV}${CONDA_PROMPT_MODIFIER}\[\e[1;31m\]\u\[\e[0m\]@\[\e[1;32m\]\h\[\e[0m\][\[\e[1;33m\]\t\[\e[0m\]]:\[\e[1;34m\]\w\[\e[0m\]\\$ " fi } declare -x PROMPT_COMMAND=languor #--------------------------------------------------------------------- # User #--------------------------------------------------------------------- # if [[ $(id -u) -eq 0 ]]; then # echo -e "\U1F308\U2744\U1F319 \e[34;47mWelcome Root\e[0m \U1F31F\U1F320\U231B" # else # echo "\U1F31B\U1F31F Welcome Ordinary" # fi #--------------------------------------------------------------------- # Completion #--------------------------------------------------------------------- if command -v kubectl >&/dev/null; then source <(kubectl completion bash) fi #--------------------------------------------------------------------- # Distro #--------------------------------------------------------------------- DISTRO=$(tr "[:upper:]" "[:lower:]" </etc/os-release | grep -Poi '(debian|ubuntu|red hat|centos|fedora)' | sort | uniq) if [ -z "$DISTRO" ]; then DISTRO=unknow fi
- 配置centos-7源
# delete obsolete antique rm -rf /etc/yum.repos.d/* # epel curl -so /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo # base updates extras contrib centosplus curl -so /etc/yum.repos.d/base.repo https://mirrors.aliyun.com/repo/Centos-7.repo sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/base.repo # docker-ce yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo # kubernetes cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF yum clean all -v yum makecache
- 禁用 firewalld NetworkManager selinux
systemctl mask --now firewalld systemctl mask --now dnsmasq systemctl mask --now NetworkManager setenforce 0 sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config #关闭swap分区 swapoff -a && sysctl -w vm.swappiness=0 sed -r -i '/^[^#]*swap/ s@^@#@' /etc/fstab echo 'vm.swappiness = 0' >> /etc/kubernetes.conf
- 安装基本软件
yum -y install wget net-tools tree sysstat vim telnet yum-utils rsync chrony info
- 初始化分区
UEFI - 更新内核, 移除旧内核
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
yum-config-manager --disable elrepo yum-config-manager --enable elrepo-kernel
需先卸载原内核kernel-tools-libs kernel-tools
检查内核yum check-update kernel*
修改默认内核
第一种方式只保留一个内核
移除旧内核相关文件
一个内核的相关文件rpm -qa kernel* | grep -v `uname -r` # 查看当前没有使用的内核包 grub2-editenv list # 查看默认内核 grub2-set-default 0 grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg yum -y update --exclude=kernel\* # 升级软件包(排除内核) grubby --update-kernel="$(grubby --default-kernel)" --args="user_namespace.enable=1" # 为当前内核添加参数 grubby --info="(grubby --default-kernel)" # 查看默认内核
-
时间同步
采用ntpdate + crondyum -y install ntpdate echo "*/5 * * * * `which ntpdate` time.windows.com" >> /var/spool/cron/root systemctl restart crond ln -svfn /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
VMware 虚拟环境: 9台试验机
-
密钥
ssh-keygen -t ed25519 -P '' -C ram -f ~/.ssh/id_ed25519 cat ~/.ssh/id_ed25519.pub > ~/.ssh/authorized_keys for i in `seq 1 1 9`;do echo ram$i,192.168.8.1$i $(< /etc/ssh/ssh_host_ecdsa_key.pub) >> ~/.ssh/known_hosts;done
- /etc/hosts
echo -e '\n\n# ratiocination' >> /etc/hosts for i in {1..9};do echo 192.168.8.1$i ram$i >> /etc/hosts;done
- clone前, 清理 garbage
yum clean all rm -rf /tmp/* > ~/.bash_history
history -c - 每台clone虚拟机 修改主机名, IP
- /etc/issue
123\S (Terminal: \l)
Kernel: \r == Platform: \m == Hostname: \n
Date: \d \t
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2020-06-18 nmcli nmtui NetworkManager
2020-06-18 linux RHEL系 网卡配置
2020-06-18 集群部署脚本
2020-06-18 vasp