linux系统安装-优化

  1. sentos 7安装
  2. 创建虚拟机
  3. 内存可先用2GB
  4. 硬盘为100GB
  5. 安装
  6. 安装系统选择Install CentOS 7,按下Tab设定kernel内核参数

    %title插图%num

    1. 增加内核参数 net.ifnames=0 biosdevname=0

    %title插图%num

  7. 按Enter开始安装
  8. 选择语言

    %title插图%num

  9. 设置

    %title插图%num

  10. 自动分区,KDUMP SECURITY POLICY关闭
  11. 网络设置

    %title插图%num

    %title插图%num

    %title插图%num

  12. 开始安装

    %title插图%num

  13. 密码设置

    %title插图%num

  14. CentOS 6与CentOS 7区别
  15. 系统基础服务变化
    操作CentOS 6CentOS 7对比
    自动补全支持命令,文件名支持命令,选项,文件名 
    文件系统ext4xfs随机读写更快
    repo仓库yumyum-config-manager添加仓库便捷
    修改主机名/etc/sysconfig/network/etc/hostnamehostnamectl
    修改时区/etc/sysconfig/clocktimedatectl set-timezone更方便
    防火墙iptablesfierwald 
    服务管理System V initsystemd 
    时间同步管理ntpchrony 
  16. 自动补全

    yum install bash-completion -y

    退出一次,然后重新登录

  17. 本地yum仓库
     Centos 6Centos 7
    本地yum仓库
    • 挂载光盘
    • 在Centos进行挂载 mount /dev/cdrom /mnt
    • 将原有repo备份

      gzip *

    • 建立文件 oldboy.repo

      vim oldboy

      [local]

      name=This is local yum repo

      baseurl=file:///mnt

      enabled=1

      gpgcheck=0

    • 挂载光盘
    • 在Centos进行挂载 mount /dev/cdrom /mnt
    • 查询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

  18. 挂载光盘->设置->cdrom->iso->选择对应的镜像文件
  19. 在centos7系统进行挂载

    [root@mbjedu-071 ~]# mount /dev/cdrom /mnt/

    mount: /dev/sr0 is write-protected, mounting read-only

  20. 查询yum-config-manager工具属于哪个软件包提供(查询方式是联网)

    [root@mbjedu-071 ~]# yum provides yum-config-manager

  21. 安装对应的软件包

    [root@mbjedu-071 ~]# yum install yum-utils -y

  22. 备份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

  23. 使用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

  24. 测试yum是否能正常使用

    [root@mbjedu-071 yum.repos.d]# yum install vim -y

    Loaded plugins: fastestmirror

    Loading mirror speeds from cached hostfile

  25. 修改主机名
    • centos 6
  1. 临时修改主机名

    [root@c6 ~]# hostname oldboy_temp

    [root@c6 ~]# bash

    [root@oldboy_temp ~]#

  2. 永久修改主机名

    [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

  1. 修改时区
    • 查看时区

    [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

  1. 系统目录结构
    系统CentOS 6CentOS 7
     binbin -> usr/bin
     sbinsbin->/usr/sbin
     liblib->/usr/lib

    [root@edu-701 ~]# ll / |grep "^l"

    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

  2. 网络接口变化
  3. CentOS操作系统网络接口命名
    接口名称网卡名网线
    eth0网卡1 
    eth1网卡2 
    eth2网卡3 
  4. 命名规则

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

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

    默认命名规则eth0 eth1 eth2
    biosdevnameem1 em2 em3
    net.ifnamesens33 ens34 ens35
  5. CentOS 6与CentOS 7使用网络接口规则
    CentOS 6CentOS 7
    net.ifnames=0net.ifnames=1
    biosdevname=1biosdevname=1
    默认命名规则默认命名规则
  6. 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

  7. Sysemd服务
  8. Systemd初始

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

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

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

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

     Centos6Centos7
    启动项管理chkconfigsystemctl
    服务管理servicesystemctl
    系统启动级别initsystemctl
    日志管理syslogSystemd-journal
  9. 开机启动级别

    在Centos7中没有级别的概念,而是使用target目标来涵盖启动级别的概念

    设置系统启动运行级别

     SysVinitSystemd
    关闭系统0runlevel0.target,poweroff.target
    单用户模式1runlevel1.target,rescue.target
    多用户模式2runlevel2.target,multi-user.target
    多用户带网络模式3runlevel3.target,multi-user.target
    多用户图形化模式5runlevel5.target,graphical-user.target
    重启操作系统6runlevel6.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.

  10. centos7关机指令

    关机 poweroff shutdown -h now

    重启 reboot shutdown -r 0

  11. 服务管理

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

    systemctl [OPTIONS…]COMMAND[NAME…]

    操作Centos6Centos7
    启动服务/etc/init.d/crond startsystemctl start crond
    停止服务/etc/init.d/crond stopsystemctl stop crond
    重启服务/etc/init.d/crond restartsystemctl restart crond
    查看状态/etc/init.d/crond statussystemctl status crond
    开机启动chkconfig –level 35 crond onsystemctl enable crond
    开机禁用chkconfig crond offsystemctl disable crond
    禁止运行 systemctl umask crond
  12. centos7上的service命令还是为了兼容centos6的习惯

    [root@edu-701 ~]# service crond restart

    Redirecting to /bin/systemctl restart crond.service

  13. centos7启动与停止建议使用systemctl

    [root@edu-701 ~]# systemctl restart crond.service

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

    [root@edu-701 ~]# systemctl list-unit-files

    UNIT FILE STATE

    proc-sys-fs-binfmt_misc.automount static

    dev-hugepages.mount static

    ……

  15. 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.

  16. centos7检查是否开机自启

    [root@edu-701 ~]# systemctl is-enabled crond.service

    enabled

  17. 系统优化
  18. 调整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

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

    yum clean all

    yum makecache

  20. 安装基础软件包

    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

  21. 关闭防火墙

    [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

  22. 关闭selinux

    [root@edu-701 ~]# sed '/^SELINUX/c SELINUX=disabled' /etc/selinux/config -i

    [root@edu-701 ~]# tail -3 /etc/selinux/config

    SELINUX=disabled

  23. 优化ulimit

    [root@edu-701 ~]# echo '* – nofile 65535' >> /etc/security/limits.conf

    [root@edu-701 ~]# tail -1 /etc/security/limits.conf

    * – nofile 65535

  24. 关闭centos7

    执行shutdown -h now 关闭centos 7系统

    [root@edu-701 ~]# shutdown -h now

  25. 选择对应服务器,拍摄快照
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郭亚望

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值