本节主要介绍 centos6 和 centos7 的区别和常用的简单配置:
第一部分:
1. 对比文件系统
2. 对比防火墙, 内核版本, 默认数据库
3. 对比时间同步, 修改时区, 修改语言
4. 对比主机名
5. 对比网络服务管理
6. 对比网络设置
7. 对比网络配置的命令
8. 对比网络的服务
第二部分:
1. 修改 centos7 为 eth0 的网卡名字
2. 本节常用命令
3. 添加一个普通的用户
4.CentOS 更换 yum 源
5. 安装必要的软件包
6. 开机优化启动项
7. 设置静态地址
8. 关闭防火墙和 selinux
9. 优化 VMware 的 SSH 使其连接时候更快的连接
10. 修改主机名
11.host 解析
12. 使用本地 yum 源
13. 其他:
本节主要介绍 centos6 和 centos7 的区别和常用的简单配置:
第一部分: centos6 和 centos7 的对比
第二部分: CentOS 的简单配置
第一部分:
1. 对比文件系统
centos6.: EXT4
EXT4 的单个文件系统的容量达到 1EB, 单个文件大小则达到 16TB.
centos7.:XFS
XFS 默认支持 8EB 减掉 1 字节的单个文件系统, 最大支持的文件大小为 9EB, 最大文件系统支持 18EB.
2. 对比防火墙, 内核版本, 默认数据库
centos6:
防火墙: iptables
内核版本: 2.6.x-x
默认数据库: MySQL
centos7:
防火墙: firewalld (也可以使用 iptables)
内核版本: 3.10.x-x (可以更好的支持 docker)
默认数据库: MariaDB (也可以用 MySQL)
3. 对比时间同步, 修改时区, 修改语言
centos6:
时间同步: ntpq -p
修改时区:/etc/sysconfig/clock
修改语言: /etc/sysconfig/I18N
centos7:
时间同步: chronyc sources
修改时区: timedatectl set-timezone Asia/Shanghai
修改语言: localectl set-locale LANG=zh_CN.UTF-8
但是我基本不用, 记住修改后需要重启. 我常用:
- # locale -a |grep CN 先查看有没有 zh_CN.utf-8 没有就安装
- # yum install kde-l10n-Chinese -y ; yum groupinstall "fonts" -y
- # VIM /etc/locale.conf
- #LANG="en_US.UTF-8" #英文
- LANG="zh_CN.UTF-8" #修改后的中文
- # source /etc/locale.conf
4. 对比主机名
centos6.:
配置文件在 / etc/sysconfig/network 这里永久设置主机名字
centos7.:
配置文件在 / etc/hostname (永久设置)
hostnamectl set-hostname liych
5. 对比网络服务管理
centos6:
service 服务名 状态
状态:
- status
- start
- stop
- --status-all
- chkconfig:
- on
- off
- --list
- centos7:
systemctl 服务名 状态
状态:
- status
- start
- stop
- list-units
- enable
- disable
- list-units-files
6. 对比网络设置
centos6:
网卡名字是: eth0
centos7:
网卡名字是: ens33 ... enp4s0f0 ... eno1 ... eno167....
7. 对比网络配置的命令
- centos6:
- ifconfig ,setup
- centos7:
- ip ,nmtui
8. 对比网络的服务
- centos6:
- network
- centos7:
- networkmanager
第二部分:
1. 修改 centos7 为 eth0 的网卡名字
- # cd /etc/sysconfig/network-scripts/
- # cp -a ifcfg-ens33 ifcfg-eth0
将网卡名字修改
- NAME=eth0
- DEVICE=eth0
修改 grub 配置文件
# VIM /etc/defaule/grub
修改 grub 文件 在 GRUB_CMDLINE_LINUX 原有的参数后面加上 "net.ifnames=0 biosdevname=0"
- # grub2-mkconfig -o /boot/grub2/grub.cfg
- # reboot
2. 本节常用命令
- whoami #查看当前用户是谁
- su - # 加 - 表示 带环境变量切换
- su root
3. 添加一个普通的用户
- #useradd liych
- #passwd liych
4.CentOS 更换 yum 源
镜像源:
搜狐: http://mirrors.sohu.com
网易: http://mirrors.163.com
阿里云: https://opsx.alibaba.com/mirror
淘宝: http://npm.taobao.org
阿里云镜像站: https://opsx.alibaba.com/mirror (这里使用阿里云提供的源, 在做 yum 本地仓库的是也推荐使用阿里源)
使用阿里云源:
CentOS
1, 备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2, 下载新的 CentOS-Base.repo 到 / etc/yum.repos.d/
- CentOS 7
- wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3, 之后运行 yum makecache 生成缓存
4, 其他
非阿里云 ECS 用户会出现 Couldn't resolve host'mirrors.cloud.aliyuncs.com' 信息, 不影响使用.
用户也可自行修改相关配置:
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
5. 安装必要的软件包
yum install tree telnet dos2unix sysstat lrzsz -y
6. 开机优化启动项
将不常用的服务关闭掉:
# systemctl list-unit-files|egrep "^ab|^aud|^kdump|vm|^md|^mic|^post|lvm" |awk '{print $1}'|sed -r 's#(.*)#systemctl disable &#g'|bash
7. 设置静态地址
dhcp 的地址总是变化, 需要设置静态地址, 可以不变, 方便连接使用.
配置文件路径: cd /etc/sysconfig/network-scripts/
- TYPE=Ethernet
- BOOTPROTO=none #取消 dhcp
- NAME=eth0
- DEVICE=eth0
- ONBOOT=yes #设置开机启动
- IPADDR=172.16.0.5 #IP 地址
- NETMASK=255.255.255.0 #子网掩码
- GATEWAY=172.16.0.254 #网关
- DNS1=114.114.114.114 #DNS
8. 关闭防火墙和 selinux
配置服务实验环境, 建议不启用这些, 必要时候需要配置防火墙.
关闭防护墙:
- # systemctl stop firewalld
- # systemctl disable firewalld.service
- # systemctl status firewalld
关闭 selinux:
- # sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
- # sestatus
9. 优化 VMware 的 SSH 使其连接时候更快的连接
当时有 CRT 或 Xshell 连接虚拟机的时候, 连接的速度很慢, 会卡顿.
关闭登陆的时候客户端需要对服务器端的 IP 地址进行反解析.
但是测试的是发现 GSSAPIAuthentication 是默认关闭的, 所以可以只设置 UseDNS no 就可以加速连接.
# sed -i '[email protected] [email protected] [email protected];[email protected]#UseDNS [email protected] [email protected]' /etc/SSH/sshd_config
为了避免迷惑解释下 93s 和 129s 的示意如下:
- [[email protected] ~]# cat 1.txt
- # Don't read the user's ~/.rhosts and ~/.shosts files
- #IgnoreRhosts yes
- [[email protected] ~]# sed '[email protected]@[email protected];[email protected]@[email protected]' 1.txt
- # 123't read the user's ~/.rhosts and ~/.shosts files
- #IgnoreRhosts 456
- [[email protected] ~]# sed '[email protected]@[email protected];[email protected]@[email protected]' 1.txt
- # 123't read the user's ~/.rhosts and ~/.shosts files
- #IgnoreRhosts 456
10. 修改主机名
# hostnamectl set-hostname liych
11.host 解析
- # VIM /etc/hosts
- 172.16.0.5 liych
12. 使用本地 yum 源
后续单独出讲
13. 其他:
1. 时间:
查看系统的开机时间:
systemd-analyze time
查看具体服务的运行时间:
systemd-analyze blame
输出图形展示:
# systemd-analyze plot>system_time.svg
来源: http://www.bubuko.com/infodetail-3257754.html