1.基本操作一:主机名
# centos7有一个新的修改主机名的命令hostnamectl
hostnamectl set-hostname --static www.node1.com
# 有些命令的参数可以自动补全,如果不能补全,则安装下面的命令
yum -y install bash-completion
2.基本操作二:关闭iptables
# 查看firewalld服务的状态,active是启动状态,inactive是关闭状态
systemctl status firewalld.service
systemctl stop firewalld.service
systemctl list-unit-files |grep firewalld # 查看firewalld是否开机自动启动
systemctl disable firewalld.service # 类似以前的chkconfig xxx off
3.基本操作三:关闭selinux
# 改完后,在后面重启系统生效
sed -i 7s/enforcing/disabled/ /etc/selinux/config
或
vi /etc/selinux/config
#注释掉下面两行
#SELINUX=enforcing
#SELINUXTYPE=targeted
#增加一行
SELINUX=disabled
4.基本操作四:网络配置
vi /etc/sysconfig/network-scripts/ifcfg-eno16777736
重启网络服务。service network restart或/etc/init.d/network restart
当不知ip可用此配方,获取ip后重新定义
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
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=eno16777736
UUID=ef1eebe1-13a2-48d9-b7f7-23922f3efa08
DEVICE=eno16777736
ONBOOT=yes
ZONE=public
固定ip
TYPE=Ethernet
BOOTPROTO=static
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=eno16777736
UUID=aadec3e3-14d0-4943-9c8c-35004cbe690c
DEVICE=eno16777736
ONBOOT=yes
IPADDR=192.168.1.110
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=211.167.67.97
DNS2=8.8.8.8
5.基本操作五:yum配置
1
配置本地yum源
# 删除了它所有的默认的配置(因为这些默认配置要连公网的源,速度太慢)
rm -rf /etc/yum.repos.d/*
mkdir /media/cdrom
mount /dev/cdrom /media/cdrom
# 自建本地yum源配置文件
vim /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
yum-config-manager --enable local # 也可以直接把上面的enabled改为1
yum repolist
配置可选163的centos源
配置方法两种
a)直接公网连接网易163,优点:速度快,软件包会定期更新
cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
b)自己编写
# vim /etc/yum.repos.d/cento163.repo
[centos163]
name=centos163
baseurl=http://mirrors.163.com/centos/7.3.1611/os/x86_64
enabled=1
gpgcheck=0
配置可选epel源
配置方法两种
a)直接公网连接epel,优点:速度快,软件包会定期更新
# 此版本信息会随时间推移而变化
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm
rpm -ivh epel-release-7-10.noarch.rpm
b)自己编写
vim /etc/yum.repos.d/epel.repo
[epel]
name=epel
baseurl=http://dl.fedoraproject.org/pub/epel/7/x86_64
enabled=1
gpgcheck=0
配置完上面三个yum后
yum clean all
yum makecache fast
2.CentOS自带的国外源有时候会很慢,我们替换成国内的阿里源,也有很多比如163源都很好,国内很多人用,但这里我们就用阿里源做个示例,想用其他源的同学可以去百度一下。
#先进入源的目录
cd /etc/yum.repo.d
#备份一下官方源
mv CentOS-Base.repo CentOS-Base.repo.bak
#将阿里源文件下载下来
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#重建源数据缓存
yum makecache
ok,换源完成
3.更换yum源
cd /etc/yum.repos.d # 切换到yum仓库目录下
mv CentOS-Base.repo CentOS-Base.repo.bak # 把原来的源重命名备份
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo #下载163源
mv CentOS7-Base-163.repo CentOS-Base.repo #更改网易的源为默认的系统yum源
yum makecache #生成缓存,将服务器上的软件包信息在本地缓存,提高搜索安装软件的速度
6.基本操作六:输入法配置(可选)
7.基本操作七:时间同步
yum -y install ntp ntpdate
vim /etc/ntp.conf
# 确认配置文件里有下列的时间同步源
server 0.rhel.pool.ntp.org iburst
server 1.rhel.pool.ntp.org iburst
server 2.rhel.pool.ntp.org iburst
server 3.rhel.pool.ntp.org iburst
systemctl enable ntpd # 设置开机自动启动ntpd
systemctl start ntpd # 立即启动ntpd服务
ntpdate 0.rhel.pool.ntp.org # 如果还没有同步成功,可以用此命令手动同步一下
# 设置默认启动级别为图形模式(相当于以前的5级别)
systemctl get-default # 查看当前的运行模式
systemctl set-default graphical.target # 设置图形模式为默认模式
8.CentOS自带vi编辑器,功能没有vim强大,我么再安装一个vim编辑器
yum install -y vim-enhanced
9.CentOS7最小化安装后没有wget软件,但是以后我们会经常用到这个组件,所以我们安装一下
yum install -y wget
11.下一步我们就要关闭CentOS7自带的防火墙 firewall 启用 IPtable
停止 Firewall
systemctl stop firewalld
10.关闭firewall自动启动
systemctl disable firewalld.service
安装IPtables防火墙
yum install -y iptables-services