-
sentos 7安装
-
创建虚拟机
-
内存可先用2GB
-
硬盘为100GB
-
安装
- 安装系统选择Install CentOS 7,按下Tab设定kernel内核参数
-
增加内核参数 net.ifnames=0 biosdevname=0
-
增加内核参数 net.ifnames=0 biosdevname=0
-
按Enter开始安装
-
选择语言
-
设置
-
自动分区,KDUMP SECURITY POLICY关闭
-
网络设置
-
开始安装
-
密码设置
-
CentOS 6与CentOS 7区别
- 系统基础服务变化
操作 | CentOS 6 | CentOS 7 | 对比 |
自动补全 | 支持命令,文件名 | 支持命令,选项,文件名 | |
文件系统 | ext4 | xfs | 随机读写更快 |
repo仓库 | yum | yum-config-manager | 添加仓库便捷 |
修改主机名 | /etc/sysconfig/network | /etc/hostname | hostnamectl |
修改时区 | /etc/sysconfig/clock | timedatectl set-timezone | 更方便 |
防火墙 | iptables | fierwald | |
服务管理 | System V init | systemd | |
时间同步管理 | ntp | chrony |
自动补全
yum install bash-completion -y
退出一次,然后重新登录
本地yum仓库
Centos 6 | Centos 7 | |
本地yum仓库 |
将原有repo备份 gzip * 建立文件 oldboy.repo vim oldboy [local] name=This is local yum repo baseurl=file:///mnt enabled=1 gpgcheck=0 |
查询yum-config-manager工具属于哪个安装包提供 yum provides yum-config-manager 安装对应安装包 yum install yum-utils -y 备份repo文件 cd /etc/yum.repo.d/ gzip * 使用yum-config-managers创建一个本地yum仓库 yum-config-manager -add-repo=file:///mnt 测试yum能否正常使用 yum install vim -y |
挂载光盘->设置->cdrom->iso->选择对应的镜像文件
在centos7系统进行挂载
[root@mbjedu-071 ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
查询yum-config-manager工具属于哪个软件包提供(查询方式是联网)
[root@mbjedu-071 ~]# yum provides yum-config-manager
安装对应的软件包
[root@mbjedu-071 ~]# yum install yum-utils -y
备份repo文件
[root@mbjedu-071 ~]# cd /etc/yum.repos.d/
[root@mbjedu-071 yum.repos.d]# gzip *
[root@mbjedu-071 yum.repos.d]# ls
CentOS-Base.repo.gz CentOS-fasttrack.repo.gz CentOS-Vault.repo.gz
CentOS-CR.repo.gz CentOS-Media.repo.gz
CentOS-Debuginfo.repo.gz CentOS-Sources.repo.gz
使用yum-config-manager命令创建一个本地仓库
[root@mbjedu-071 yum.repos.d]# yum-config-manager –add-repo=file:///mnt
Loaded plugins: fastestmirror
adding repo from: file:///mnt
[mnt]
name=added from: file:///mnt
baseurl=file:///mnt
enabled=1
测试yum是否能正常使用
[root@mbjedu-071 yum.repos.d]# yum install vim -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
修改主机名
-
centos 6
-
centos 6
-
临时修改主机名
[root@c6 ~]# hostname oldboy_temp
[root@c6 ~]# bash
[root@oldboy_temp ~]# -
永久修改主机名
[root@oldboy_temp ~]#sed -i '/^HOSTNAME=/c HOSTNAME=oldboyedu' /etc/sysconfig/network [root@oldboy_temp ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=oldboyedu
- centos 7
-
临时修改主机名
-
临时修改主机名
- [root@mbjedu-071 ~]# hostname edu-701
[root@mbjedu-071 ~]# bash
[root@edu-701 ~]# 永久修改主机名
[root@edu-701 ~]# hostnamectl set-hostname edu-071
[root@edu-701 ~]# cat /etc/hostname
edu-071
-
修改时区
-
查看时区
-
查看时区
- [root@edu-701 ~]# timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
…… -
修改时区
-
修改时区
- [root@edu-701 ~]# timedatectl set-timezone "Africa/Abidjan"
[root@edu-701 ~]# date
Mon Sep 3 11:38:19 GMT 2018
[root@edu-701 ~]# timedatectl set-timezone "Asia/Shanghai"
[root@edu-701 ~]# date
Mon Sep 3 19:38:48 CST 2018
- 系统目录结构
系统 | CentOS 6 | CentOS 7 |
bin | bin -> usr/bin | |
sbin | sbin->/usr/sbin | |
lib | lib->/usr/lib |
lrwxrwxrwx. 1 root root 7 Sep 3 17:49 bin -> usr/bin
lrwxrwxrwx. 1 root root 7 Sep 3 17:49 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 Sep 3 17:49 lib64 -> usr/lib64
lrwxrwxrwx. 1 root root 8 Sep 3 17:49 sbin -> usr/sbin
网络接口变化
CentOS操作系统网络接口命名
接口名称 | 网卡名 | 网线 |
eth0 | 网卡1 | |
eth1 | 网卡2 | |
eth2 | 网卡3 |
命名规则
net.ifnames 基于固件、拓扑、进行自动分配网卡名称,缺点比eth0、更难读,如ens32
biosdevname 根据戴尔服务器系统的BIOS提供的信息对网络接口进行重命名,如em1
默认命名规则 | eth0 eth1 eth2 |
biosdevname | em1 em2 em3 |
net.ifnames | ens33 ens34 ens35 |
CentOS 6与CentOS 7使用网络接口规则
CentOS 6 | CentOS 7 |
net.ifnames=0 | net.ifnames=1 |
biosdevname=1 | biosdevname=1 |
默认命名规则 | 默认命名规则 |
CentOS 7 查看IP
[root@edu-701 ~]# yum install net-tools -y
[root@edu-701 ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.210 netmask 255.255.255.0 broadcast 10.0.0.255
Sysemd服务
Systemd初始
Systemd是Centos7新采用的一套管理体系,可以实现启动及进程服务管理等,对比Centos6系统之前所采用sysVini体系,带来了很多变化。
Centos7支持并行启动,显著提高开机启动效率(测试6与7区别)
Centos7关机只关闭正在运行的服务,Centos6关机会从头关到尾
Centos7服务的启动与停止不在需要init.d下的脚本
Centos6 | Centos7 | |
启动项管理 | chkconfig | systemctl |
服务管理 | service | systemctl |
系统启动级别 | init | systemctl |
日志管理 | syslog | Systemd-journal |
开机启动级别
在Centos7中没有级别的概念,而是使用target目标来涵盖启动级别的概念
设置系统启动运行级别
SysVinit | Systemd | |
关闭系统 | 0 | runlevel0.target,poweroff.target |
单用户模式 | 1 | runlevel1.target,rescue.target |
多用户模式 | 2 | runlevel2.target,multi-user.target |
多用户带网络模式 | 3 | runlevel3.target,multi-user.target |
多用户图形化模式 | 5 | runlevel5.target,graphical-user.target |
重启操作系统 | 6 | runlevel6.target,reboot.target |
centos6开机默认系统自启动级别
vim /etc/inittab
centos7开机默认系统自启动目标target
[root@mbjedu-702 ~]# systemctl get-default
multi-user.target
[root@mbjedu-702 ~]# systemctl set-default runlevel5.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.
[root@mbjedu-702 ~]# systemctl set-default runlevel3.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
centos7关机指令
关机 poweroff shutdown -h now
重启 reboot shutdown -r 0
服务管理
命令选项(非必须) 执行命令单元名称(非必须)
systemctl [OPTIONS…]COMMAND[NAME…]
操作 | Centos6 | Centos7 |
启动服务 | /etc/init.d/crond start | systemctl start crond |
停止服务 | /etc/init.d/crond stop | systemctl stop crond |
重启服务 | /etc/init.d/crond restart | systemctl restart crond |
查看状态 | /etc/init.d/crond status | systemctl status crond |
开机启动 | chkconfig –level 35 crond on | systemctl enable crond |
开机禁用 | chkconfig crond off | systemctl disable crond |
禁止运行 | systemctl umask crond |
centos7上的service命令还是为了兼容centos6的习惯
[root@edu-701 ~]# service crond restart
Redirecting to /bin/systemctl restart crond.service
centos7启动与停止建议使用systemctl
[root@edu-701 ~]# systemctl restart crond.service
centos7查看所有的服务开机启动和开机不启动的单元
[root@edu-701 ~]# systemctl list-unit-files
UNIT FILE STATE
proc-sys-fs-binfmt_misc.automount static
dev-hugepages.mount static
……
centos7开机不自启
[root@edu-701 ~]# systemctl disable crond.service
Removed symlink /etc/systemd/system/multi-user.target.wants/crond.service.
centos7开机自启
[root@edu-701 ~]# systemctl enable crond.service
Created symlink from /etc/systemd/system/multi-user.target.wants/crond.service to /usr/lib/systemd/system/crond.service.
centos7检查是否开机自启
[root@edu-701 ~]# systemctl is-enabled crond.service
enabled
系统优化
调整yum源
[root@edu-701 ~]# cd /etc/yum.repos.d/
[root@edu-701 yum.repos.d]# rm -rf *
[root@edu-701 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@edu-701 ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
清理缓存,并重新生成缓存文件
yum clean all
yum makecache
安装基础软件包
yum install net-tools vim tree htop iotop iftop \
iotop lrzsz sl wget unzip telnet nmap nc psmisc \
dos2unix bash-completion sysstat rsync nfs-utils bash-completion -y
关闭防火墙
[root@edu-701 yum.repos.d]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@edu-701 yum.repos.d]# systemctl stop firewalld.service
关闭selinux
[root@edu-701 ~]# sed '/^SELINUX/c SELINUX=disabled' /etc/selinux/config -i
[root@edu-701 ~]# tail -3 /etc/selinux/config
SELINUX=disabled
优化ulimit
[root@edu-701 ~]# echo '* – nofile 65535' >> /etc/security/limits.conf
[root@edu-701 ~]# tail -1 /etc/security/limits.conf
* – nofile 65535
关闭centos7
执行shutdown -h now 关闭centos 7系统
[root@edu-701 ~]# shutdown -h now
选择对应服务器,拍摄快照