CentOS7版本基础使用

第1章 CentOS7的使用

1.1 为什么要使用CentOS7版本

CentOS7是在CentOS6基础上发布的新版本,与之前的版本相比,主要的更新包括:

1、内核更新到3.10.0

2、支持Linux容器

3、LVM快照支持ext4和XFS

4、转用systemd、firewalld和GRUB2

5、XFS作为缺省文件系统

6、支持PTPv2

7、支持40G 以太网卡

8、在兼容的硬件上支持以UEFI安全启动模式安装

这其中最令人瞩目的新特性就是支持Docker技术。作为目前流行的应用虚拟化技术之一,Docker能够将应用程序与系统完全隔离,让其在系统之间实现迁移而不需要停机,提高了应用程序的移动性和灵活性。CentOS7在内核层面支持Docker容器技术,可以提高Docker稳定性和可靠性。

综上,我们会选择CentOS7来作为服务器的操作系统。

第2章 CentOS7与CentOS6版本的区别

2.1 系统基础服务变化

操作

Centos6

Centos7

对比

自动补全

只支持命令、文件名

支持命令、选项、文件名

文件系统

ext4       

xfs                

随机读写更快

repo仓库

yum

yum-config-manager  

添加仓库便捷

修改主机名

/etc/sysconfig/network

/etc/hostname            

hostnamectl

修改时区    

/etc/sysconfig/clock

timedatectl set-timezone   

更方便

修改字符集

/etc/sysconfig/il8n    

/etc/locale.conf           

localectl

防火墙

iptables

firewalld

服务管理

System V init

systemd

时间同步服务

ntp

chrony 

2.2 系统文件目录结构

centos6

cetos7

bin 

usr/bin

sbin

usr/sbin

lib

usr/lib

2.3 修改主机名

2.3.1 centos6实现方式

临时修改主机名

[root@zeq ~]# hostname zeq_temp

[root@zeq ~]# bash

[root@zeq_temp ~]#
永久修改主机名

[root@zeq_temp ~]# sed -i '/^HOSTNAME=/c HOSTNAME=zeq' /etc/sysconfig/network

[root@zeq_temp ~]# cat /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=zeq

2.3.2 centos7实现方式

临时修改主机名

[root@zeq ~]# hostname zeq-c7

[root@zeq ~]# bash
永久修改主机名

[root@zeq-c7 ~]# hostnamectl set-hostname zeq-cc7

[root@zeq-c7 ~]# cat /etc/hostname

zeq-cc7

2.4 时区修改

2.4.1 查看时区

[root@zeq ~]# timedatectl list-timezones

2.4.2 修改时区

[root@zeq ~]#timedatectl set-timezone "America/Punta_Arenas" 

[root@zeq ~]# timedatectl set-timezone "Asia/Shanghai"

2.5 网络接口变化

net.ifnames 基于固件、拓扑、进行自动分配网卡名称,缺点比eth0、更难读,如ens32

biosdevname 根据戴尔服务器系统的BIOS提供的信息对网络接口进行重命名,如em1

默认命名规则 eth0 eth1 eth2

biosdevname em1 em2 em3

net.ifnames ens33 ens34 ens35

2.5.1 centos7使用ip命令查看ip地址方法

1.查看ip地址信息 ip addr

2.添加多个IP地址 ip addr add 192.168.56.200/24 dev eth0:1

3.控制网络接口 ip link set dev eth0 down

2.6 Systemd服务概述

Systemd初始

Systemd是Centos7新采用的一套管理体系,可以实现启动及进程服务管理等,对比Centos6系统之前所采用sysVini体系,带来了很多变化。

Centos7支持并行启动,显著提高开机启动效率(测试6与7区别)

Centos7关机只关闭正在运行的服务,Centos6关机会从头关到尾

Centos7服务的启动与停止不在需要init.d下的脚本

2.7 systemd启动级别

在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

Centos7开机默认系统启动目标target

multi-user.target: analogous to runlevel 3

graphical.target: analogous to runlevel 5

2.7.1 查看系统当前默认运行级别(目标)

[root@zeq ~]# systemctl get-default

multi-user.target

2.7.2 修改系统启动默认级别(目标)

[root@zeq ~]# systemctl set-default runlevel5.target

建议修改回去

[root@zeq ~]# systemctl set-default multi-user.target

2.7.3 centos7关机指令

poweroff、shutdown -h now、init0 (不建议使用)

reboot

2.8 systemd服务管理

命令 选项(非必须) 执行命令 单元名称(非必须)

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

2.8.1 centos7上的service命令还是为了兼容centos6的习惯

[root@zeq ~]# service crond restart

Redirecting to /bin/systemctl restart crond.service

2.8.2 centos7启动与停止建议使用systemctl

[root@zeq ~]# systemctl restart crond

2.8.3 centos7查看所有的服务开机启动和开机不启动的单元

[root@zeq ~]# systemctl list-unit-files

2.8.4 centos7开机不自启

[root@zeq ~]# systemctl disable crond

2.8.5 centos7开机自启

[root@zeq ~]# systemctl enable crond

2.8.6 centos7检查是否开机自启

[root@zeq ~]# systemctl is-enabled crond

disabled

第3章 CentOS7系统优化

3.1 调整yum源

rm -rf /etc/yum.repos.d/*

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

3.2 清理缓存,并重新生成缓存文件

yum clean all

yum makecache

3.3 安装基础软件包

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 -y

3.4 关闭防火墙

systemctl disable firewalld

systemctl stop firewalld

3.5 关闭selinux

sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config

3.6 优化ulimit

echo '* - nofile 65535' >> /etc/security/limits.conf

3.7 执行shutdown -h now 关闭Centos7系统

3.8 选中对应的虚拟机->快照->拍摄快照

第3章 参考文献

参考与徐亮伟(标杆徐)的讲解:http://www.xuliangwei.com

猜你喜欢

转载自www.cnblogs.com/zeq912/p/9589999.html