Linux 新机初始化 Centos8.x
1. 配置系统时区
#!/bin/bash echo 'ZONE="Asia/Shanghai"'>/etc/sysconfig/clock \cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime echo 'TZ="Asia/Shanghai"; export TZ' >> /etc/profile source /etc/profile
如果出现报错:
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): 没有那个文件或目录
请添加修改:
vim /etc/sysconfig/i18n
LANG="en_US.UTF-8" LC_CTYPE="en_US.UTF-8" SYSFONT="latarcyrheb-sun16"
参考: https://www.updateweb.cn/zwfec/item-236.html
2. 系统默认配置 高效使用
yum install git -y yum install nss -y ldconfig yum install curl -y yum install tmux -y yum install zsh -y yum install lrzsz -y yum install dstat -y yum update -y nss curl libcurl sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" git clone git://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions sed -i "s/fg=8/fg=cyan/g" ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh cat <<EOF >> ~/.zshrc source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh export EDITOR=/usr/bin/vim HISTSIZE=9000000 SAVEHIST=9000000 alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' alias grep='grep --color=auto' alias tmuxls='tmux ls' alias tmuxa='tmux attach-session -t ' alias dstat='dstat -cdlmnpsy' alias vime='vim -c "colorscheme evening" ' EOF source ~/.zshrc cat <<EOF >> ~/.vimrc colorscheme desert set ts=4 set expandtab set encoding=utf-8 set fileencodings=ucs-bom,utf-8,cp936 set fileencoding=gb2312 set termencoding=utf-8 set number set paste EOF cat <<EOF >> ~/.tmux.conf set-window-option -g mode-mouse on EOF
如果报如下错误: 说明你的网络无法正常访问 github
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
curl: (7) Failed to connect to ::: Cannot assign requested address
如果出现如下错误:
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
curl: (7) Failed to connect to raw.github.com port 443: Connection refused
使用:
sh -c "$(curl -fsSL https://gitee.com/shmhlsy/oh-my-zsh-install.sh/raw/master/install.sh)"
如果出现: name lookup timeout 的情况
请执行:
yum update ca-certificates
根据自己的实际情况修改:
vim ~/.oh-my-zsh/themes/robbyrussell.zsh-theme
写入:
local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )" local pwd="%{$fg[yellow]%}%~%{$reset_color%}" local user="%(!.%{$fg[cyan]%}.%{$fg[cyan]%})%n%{$reset_color%}" ZSH_THEME_IP=`ifconfig -a|grep -o -e 'inet [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}'|grep -v "127.0.0"|awk '{print $2}'` PROMPT='%{$fg[yellow]%}[$ZSH_THEME_IP] ${user} ${ret_status} ${pwd} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)' ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗" ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
对于 git 提交次数比较的git库 zsh切换时会很慢:
解决方法是在 git 的目录下 执行以下:
git config --add oh-my-zsh.hide-dirty 1 git config --add oh-my-zsh.hide-status 1
3. 格式化并挂载硬盘
fdisk /dev/xvdb mkfs.ext4 /dev/xvdb1 mount /dev/xvdb1 /srv/ vi /etc/fstab 添加类似: 根据实际情况而定 /dev/xvdb1 /srv/ ext4 defaults 0 0
4. 系统打开的文件数优化:
cat <<EOF >> /etc/security/limits.conf * soft nofile 65532 * hard nofile 65532 EOF