Linux 新机初始化 Centos7.x

分类:Linux |

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. 系统默认配置 高效使用

注: 请使用git2.0+  

yum install git -y 这个命令 如果安装的是1.7版本的 git, 而ohmyzsh不支持git 1.7, 所以请使用 git1.8+

本站下载地址: https://www.updateweb.cn/softwares/git-2.9.5-1.el6.x86_64.rpm


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 https://github.com/zsh-users/zsh-autosuggestions.git ~/.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


如果出现: name lookup timeout 的情况

image.png

请执行: 

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]%})"


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