Linux 新机初始化 Centos6.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, 所以请使用 git2.0+

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


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


如果出现: name lookup timeout 的情况

image.png

请执行: 

yum update ca-certificates
vim ~/.oh-my-zsh/themes/robbyrussell.zsh-theme


写入:

function git_prompt_info() {
  local ref
  if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then
    ref=$(command git symbolic-ref HEAD 2> /dev/null) || \
    ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
    echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$ZSH_THEME_GIT_PROMPT_DIRTY "
  fi
}
local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
local pwd="%{$fg[yellow]%}%~%{$reset_color%}"
local host="%{$fg[cyan]%}@$HOST%{$fg[cyan]%}%{$reset_color%}"
local user="%(!.%{$fg[cyan]%}.%{$fg[cyan]%})%n%{$reset_color%}"
#ZSH_THEME_CURRENT_DATE=`date +%Y-%m-%d`
ZSH_THEME_IP=`ifconfig|grep 'inet addr'|cut -d ":" -f2|cut -d " " -f1|grep -v "127.0.0"`

PROMPT='%{$fg[yellow]%}[$ZSH_THEME_IP]${user}${host} ${ret_status} ${pwd} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)%{$reset_color%}'

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

效果图:

image.png


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