现在无论工作还是个人学习,貌似基本上已经告别 CentOS6 的节奏了,因此这篇文章默认的也都是针对 CentOS7 而言的。
1,关闭 networkmanager
systemctl stop NetworkManager
systemctl disable NetworkManager
遇到坑:没关闭之前,更改网卡配置文件,重启网络服务,总是报错。
2,关闭 selinux
当前有效
setenforce 0
getenforce #查看
永久生效
sed -i '7s/enforcing/disabled/g' /etc/selinux/config
3,添加 dns 配置
/etc/resolv.con
nameserver 202.101.172.35
DNS 地址可查找自己地区可用的或者公司自己配置的 ip 既可。
4,修改网卡配置
vim /etc/sysconfig/network-scripts/ifcfg-eth0
HWADDR="D8:CB:8A:FE:6C:8E"
TYPE="Ethernet"
BOOTPROTO="none"
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_FAILURE_FATAL="no"
NAME="eth0"
UUID="abea3956-bd72-480e-ae98-3d7c266da74d"
ONBOOT="yes"
IPADDR="192.168.1.2"
NETMASK="255.255.255.0"
GATEWAY="192.168.1.1"
5,添加 yum 源
vim /etc/yum.repos.d/CentOS-Base.repo
[epel]
name=fedal_epel
baseurl=http://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0
enable=1
6,修改主机名
hostnamectl set-hostname node1
exec bash
7,关闭 firewall
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
8,安装防火墙
这个根据公司需求来进行配置。
yum install iptables-services
systemctl start iptables
chkconfig iptables on
9,修改 ssh 配置
vim /etc/ssh/sshd_config
Port 32223 #修改ssh登陆端口
PermitRootLogin no #禁止root远程ssh登陆,根据实际需求进行配置
10,添加个人命令别名
vim .bashrc
alias grep='grep --color=auto'
11,修改时区
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
timedatectl set-timezone Asia/Shanghai
12,配置时间同步
yum -y install ntp && ntpdate -u cn.pool.ntp.org
13,加一条命令提示符颜色显示的变量
在 .bashrc最下边添加
export PS1='\e[1;32m\][\e[1m\]\e[3;35m\]\u\e[0;34m\]@\e[1;33m\]\H\e[1;32m\]][\e[1;34m\]\t\e[1;32m\]][$([[ $? != 0 ]] && echo -ne "\e[31mFAIL\e[0m" || echo -ne "\e[34mOK\e[0m")\e[1;32m\]] \e[1m\]\e[3;30m\]\w\e[0m\]\n\$ '
14,安装常用软件
yum -y install lrzsz vim net-tools gunzip wget curl unzip