新安装一台机器需要初始化的一些操作步骤
一、配置静态ip地址及dns
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens33
因为mini版没有vim,所以先用vi工具(大致和vim命令一样)
进入ifcfg-ens33之后:
修改
- BOOTPROTO= dhcp 改为 BOOTPROTO=static
- ONBOOT=no 改为 ONBOOT=yes
删除
- UUID=1d3ace7d-baf4-4ccb-a76e-e02231845e69
添加
- IPADDR=192.168.134.130
- NETWORK=255.255.255.0
- GATEWAY=192.168.134.1(注意VMware里有可能是.2)
- DNS1=223.5.5.5
- DNS2=144.144.144.144
参照↓ ↓ ↓
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
DEVICE=ens33
IPADDR=192.168.9.140
NETWORK=255.255.255.0
GATEWAY=192.168.9.1
DNS1=223.5.5.5
DNS2=114.114.114.114
ONBOOT=yes
都改为之后加一句重启命令
[root@localhost ~]# systemctl disable firewalld
二、关闭防火墙
[root@localhost ~]# systemctl stop firewalld #临时关闭
[root@localhost ~]# systemctl disable firewalld #永久关闭
临时关闭
[root@localhost ~]# setenforce 0
永久关闭
先进入[root@localhost ~]# vi /etc/selinux/config
再把SELINUX=enforcing改为SELINUX=disabled
三、安装阿里源
#备份
[root@localhost ~]# mkdir -p /etc/yum.repos.d/bak
[root@localhost ~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
# 下载阿里云 repo
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/epel-7.repo
# 清理并重建缓存
[root@localhost /]# yum clean all
[root@localhost /]# yum makecache
四、安装系统需要的基本命令及工具
[root@localhost /]# yum install -y vim wget curl git lsof net-tools bind-utils telnet htop iotop iftop nload ncdu jq yum-utils unzip zip supervisor lrzsz make gcc-c++ ntpdate
五、优化ssh
[root@localhost /]# vim /etc/ssh/sshd_config
#按/搜索#UseDNS yes复制一份把yes改为no,并把复制的那一行#删掉
#重启sshd服务
[root@localhost /]# systemctl restart sshd
六、记得拍摄虚拟机快照
七、如需克隆机器,克隆的机器拍摄快照之前记得修改ip地址
八、用户初始配置文件
| 文件 | 作用 | 生效时机 |
| ~/.bash_profile | 用户环境变量 | 登录时 |
| ~/.bashrc | 用户shell配置 | 每次开shell |
| ~/.bash_logout | 退出时执行 | 退出登录 |
| ~/.bash_history | 历史命令 | 退出时写入 |
#拿第一个~/.bash_profile举例子
[root@localhost ~]# vim ~/.bash_profile
#在~/.bash_profile中添加
echo "已完成初始化配置!!!欢迎访问!!!"
#然后退出