物理服务器配置后优化(个人笔记)

76 阅读1分钟

Yum源

curl -k -o Replace_yum_centos7.sh http://oss.xiaozhuhome.site/Linux%E8%84%9A%E6%9C%AC/centos%E6%8D%A2yum%E6%BA%90/Replace_yum_centos7.sh
chmod +x Replace_yum_centos7.sh  
./Replace_yum_centos7.sh



yum -y install wget vim


vim yum.sh

#bash

# 进入yum源配置文件目录
cd /etc/yum.repos.d/

# 创建文件夹
mkdir bak

# 将/etc/yum.repos.d/目录下所有的.repo的文件移动到bak目录下
# mv *.repo bak

# 下载aliyun的yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

##  在wget中,-O:选项用于指定要将下载的内容保存为的文件名。

# 安装扩展源epel.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

# 清理缓存
yum clean all

# 确定元数据缓存
yum makecache

# vim、net-tools、bash-completion、coreutils、iproute
yum -y install net-tools bash-completion coreutils iproute 

chmod 777 yum.sh 
./yum.sh 

yum update -y

安装常用命令

cd 
vim .bashrc
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

export PS1='[\033[01m][[\033[01;32m]\u[\033[00m][\033[01m]@[\033[01;35m]\h[\033[01;31m] [\033[01;36m]\w[\033[0m]] $ '
export HISTTIMEFORMAT=" %F %T "

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=10000
HISTFILESIZE=2000


source .bashrc

修改历史命令时间戳、最大值

vim .bashrc
# 添加
export HISTTIMEFORMAT=" %F %T "

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=10000
HISTFILESIZE=2000


source .bashrc 重新加载 .bashrc文件

修改字符集颜色

vim .bashrc
# 添加
export PS1='[\033[01m][[\033[01;32m]\u[\033[00m][\033[01m]@[\033[01;35m]\h[\033[01;31m] [\033[01;36m]\w[\033[0m]] $ '

source .bashrc 重新加载 .bashrc文件

Tab自动补齐命令

vim .bashrc
# 添加  (注:需要安装bash-completion插件)
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

source .bashrc 重新加载 .bashrc文件

配置sudo用户

adduser ceshi
passwd ceshi

groupadd sudo
usermod -aG sudo ceshi

vim  /etc/sudoers  
# 添加
%sudo   ALL=(ALL:ALL) NOPASSWD:ALL

%suanfa   ALL=(ALL) NOPASSWD:ALL

SeLinux说明

临时法
setenforce 0

永久关闭
vim /etc/selinux/config

# 修改SELINUX=enforcing为 SELINUX=disabled

然后重启服务器即可,配合上面的临时法可以暂时不用重启,反正下次重启后就生效了。