C7系统环境优化
系统优化必备环境
目录
1.虚拟机准备
1) 创建虚拟机(2块网卡)
2 模板机系统软件配置
1) 关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
检查防火墙selinux
2) yum源
#修改base源 为阿里云
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
#增加epel源
curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/Centos-7.repo
3) 安装常用工具
yum install -y vim tree wget bash-completion bashcompletion-extras lrzsz net-tools sysstat iotop iftop htop unzip nc nmap telnet bc psmisc httpd-tools bindutils nethogs expect
4) 优化ssh连接速度
sed -i '/^GSSAPIAuthentication/s@^@#@g' /etc/ssh/sshd_config
cat >> /etc/ssh/sshd_config<<EOF
UseDNS no
GSSAPIAuthentication no
EOF
systemctl restart sshd
#检查
egrep '^(GSSAPIAuthentication|UseDNS)' /etc/ssh/sshd_config
5) 时间同步
yum install -y ntpdate
crontab -l
#1. sync time
*/2 * * * * /sbin/ntpdate ntp1.aliyun.com &>/dev/null
6) 命令行颜色
#把下面内容写入到/etc/profile中即可.
export PS1='[\[\e[34;1m\]\u@\[\e[0m\]\[\e[32;1m\]\H\[\e[0m\]\[\e[31;1m\] \w\[\e[0m\]]\$ '
7) 书写修改ip和主机名的脚本
克隆完成虚拟机,修改主机名和ip
脚本用法
sh /server/scripts/change.sh 主机名 10.0.0.7
[root@oldboy-muban ~]# cat /server/scripts/change.sh
#!/bin/bash
ip=`hostname -I |awk '{print $1}' | sed 's#.*\.##g'`
ip_new=`echo $2 | sed 's#.*\.##g'`
hostname=$1
sed -i -r "/^IPADDR/s&[0-9]+$&$ip_new&g" /etc/sysconfig/network-scripts/ifcfg-eth[01]
systemctl restart network
hostnamectl set-hostname $hostname
8) NetworkManager 关闭
#如果没有影响远程连接.
systemctl stop NetworkManager
systemctl disable NetworkManager
systemctl restart network
9) hosts解析
cat >> /etc/hosts <<EOF
自己添加
EOF