前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >centos7_1708 安装

centos7_1708 安装

原创
作者头像
惨绿少年
发布2017-12-14 19:35:47
1.4K0
发布2017-12-14 19:35:47
举报
文章被收录于专栏:惨绿少年惨绿少年

第1章centos7的使用

1.1centos的演变

1.1.1启动流程sysvinit

串行启动:一次一个,一个一个启动

并行启动:全部的一起启动

init优点

运行非常良好。主要依赖于shell脚本

init缺点

1、启动慢

2、容易夯住,fstab与nfs挂载问题

1.1.2upstart 技术

使用的版本:

centos6

ubuntu14

1.1.3systemd技术

克服init固有缺点,提高系统的启动速度

降低迁移成本

1.1.4三种启动技术对比

1.1.5并行启动三大原理:

1、解决socket 依赖/端口依赖

socket 网络套接字文件

2、解决D-Bus

依赖:采用了D-Bus 为程序之间的通讯工具,类似消息队列,可以缓存信息

3、解决文件系统依赖、类似autofs机制

1.2安装centos7系统

1.2.1虚拟机选择

磁盘空间尽量大一些

1.2.2系统安装

1)开机进入安装

2)按下TAB键

添加内核参数 让网卡名称变为eth

空格 输入 net.ifnames=0 biosdevname=0 然后回车

3)选择语言

4) 设置网络连接和主机名

5)注意勾选开机自启动

6) 设置ip地址

同样的方式将另外 一块网卡配置好

7) 修改主机名

8)选择安装的环境,选择最小化安装。

注意勾选依赖包

9)磁盘分区为自定义分区。

选择/boot挂载点的大小。这里设置为1g

添加swap挂载点

注意选择都为标准分区类型,直接写到磁盘

添加根分区后选择完成

关闭密码保护

选择关闭

关闭KDUMP功能

开始安装,注意为469个包

安装的过程中设置root的密码。

1.3安装完成后的优化

查看系统版本

代码语言:txt
复制
[root@CentOS7 ~]# cat /etc/redhat-release 
代码语言:txt
复制
CentOS Linux release 7.3.1611 (Core)

修改yum源,base源

代码语言:txt
复制
[root@CentOS7 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
代码语言:txt
复制
 % Total % Received % Xferd Average Speed Time Time Time Current
代码语言:txt
复制
 Dload Upload Total Spent Left Speed
代码语言:txt
复制
100 2573 100 2573 0 0 2940 0 --:--:-- --:--:-- --:--:-- 2940

epel源

代码语言:txt
复制
[root@CentOS7 ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
代码语言:txt
复制
 % Total % Received % Xferd Average Speed Time Time Time Current
代码语言:txt
复制
 Dload Upload Total Spent Left Speed
代码语言:txt
复制
100 1084 100 1084 0 0 915 0 0:00:01 0:00:01 --:--:-- 916

安装软件

yum install vim wget bash-completion lrzsz nmap nc tree htop iftop net-tools -y

bash-completion 补全命令参数的包

1.4centos7 与centos 6的区别

1.4.1解决更换网卡后名称变更的问题

更改名称的方法

修改CentOS7网卡名称为传统名称eth0格式

http://oldboy.blog.51cto.com/2561410/1722101

1.4.2nmtui

centos7 上管理网路的图形化工具

1.4.3主机名配置文件的区别

临时 hostname

永久 /etc/hostname

[root@CentOS7 ~]# cat /etc/hostname

CentOS7

一步到位

[root@CentOS7 ~]# hostnamectl

Static hostname: CentOS7

Icon name: computer-vm

Chassis: vm

Machine ID: 4ab1c20b25f64a38a7197b8453b04b2c

Boot ID: abd0a393540b4788bc1e571b413b33c4

Virtualization: vmware

Operating System: CentOS Linux 7 (Core)

CPE OS Name: cpe:/o:centos:centos:7

Kernel: Linux 3.10.0-514.el7.x86_64

Architecture: x86-64

修改主机名

[root@CentOS7 ~]# hostnamectl set-hostname clsn

1.4.4字符集

临时

[root@clsn ~]# echo $LANG

zh_CN.UTF-8

永久

[root@clsn ~]# cat /etc/locale.conf

LANG="zh_CN.UTF-8"

一步到位

[root@clsn ~]# localectl

System Locale: LANG=zh_CN.UTF-8

VC Keymap: cn

X11 Layout: cn

1.4.5查看系统版本号

[root@clsn bin]# cat /etc/os-release

NAME="CentOS Linux"

VERSION="7 (Core)"

ID="centos"

ID_LIKE="rhel fedora"

VERSION_ID="7"

PRETTY_NAME="CentOS Linux 7 (Core)"

ANSI_COLOR="0;31"

CPE_NAME="cpe:/o:centos:centos:7"

HOME_URL="https://www.centos.org/"

BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"

CENTOS_MANTISBT_PROJECT_VERSION="7"

REDHAT_SUPPORT_PRODUCT="centos"

REDHAT_SUPPORT_PRODUCT_VERSION="7"

1.4.6兼容的rc.local

cat /etc/rc.local

# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure

# that this script will be executed during boot.

想要使用rc.local要给他可执行权限

[root@clsn bin]# chmod +x /etc/rc.d/rc.local

[root@clsn bin]# ll /etc/rc.d/rc.local

-rwxr-xr-x. 1 root root 473 11月 7 2016 /etc/rc.d/rc.local

1.4.7运行级别Runlevel

之前的查看运行级别的方法依旧使用

[root@clsn init.d]# runlevel

N 3

原运行级别文件

[root@clsn init.d]# cat /etc/inittab

# inittab is no longer used when using systemd.

#

# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.

#

# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target

#

# systemd uses 'targets' instead of runlevels. By default, there are two main targets:

#

# multi-user.target: analogous to runlevel 3

# graphical.target: analogous to runlevel 5

#

# To view current default target, run:

# systemctl get-default

#

# To set a default target, run:

# systemctl set-default TARGET.target

7中设置运行级别

root@clsn init.d]# systemctl get-default multi-user.target

systemctl get-default #查看运行级别

示例

[root@clsn ~]# systemctl get-default

multi-user.target

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

Removed symlink /etc/systemd/system/default.target.

Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.

运行级别的变更

[root@clsn ~]# ls -lh /usr/lib/systemd/system/runlevel*.target

lrwxrwxrwx. 1 root root 15 11月 13 11:16 /usr/lib/systemd/system/runlevel0.target -> poweroff.target

lrwxrwxrwx. 1 root root 13 11月 13 11:16 /usr/lib/systemd/system/runlevel1.target -> rescue.target

lrwxrwxrwx. 1 root root 17 11月 13 11:16 /usr/lib/systemd/system/runlevel2.target -> multi-user.target

lrwxrwxrwx. 1 root root 17 11月 13 11:16 /usr/lib/systemd/system/runlevel3.target -> multi-user.target

lrwxrwxrwx. 1 root root 17 11月 13 11:16 /usr/lib/systemd/system/runlevel4.target -> multi-user.target

lrwxrwxrwx. 1 root root 16 11月 13 11:16 /usr/lib/systemd/system/runlevel5.target -> graphical.target

lrwxrwxrwx. 1 root root 13 11月 13 11:16 /usr/lib/systemd/system/runlevel6.target -> reboot.target

1.4.8systemd一统天下

系统启动文件的目录

[root@clsn init.d]# ls /usr/lib/systemd/system

启动命令示例

[root@clsn init.d]# cat /usr/lib/systemd/system/crond.service

[Unit]

Description=Command Scheduler

After=auditd.service systemd-user-sessions.service time-sync.target

[Service]

EnvironmentFile=/etc/sysconfig/crond

ExecStart=/usr/sbin/crond -n $CRONDARGS

ExecReload=/bin/kill -HUP $MAINPID

KillMode=process

[Install]

WantedBy=multi-user.target

语法格式

http://www.jinbuguo.com/systemd/systemd.service.html

1.4.9管理服务

关闭防火墙服务及开机自启动

systemctl stop postfix.service

systemctl disable postfix.service

关闭防火墙详细过程

[root@clsn ~]# 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@clsn ~]# systemctl stop firewalld.service

[root@clsn ~]# systemctl status firewalld.service

systemctl:融合service和chkconfig的功能于一体,兼容SysV和LSB的启动脚本,而且够在进程启动过程中更有效地引导加载服务。。

1.4.10命令对比

systemctl start crond.service和systemctl start crond效果一样。

1.4.11开机时间优化

systemd-analyze time

systemd-analyze blame

systemd-analyze plot >bootime.avg

开机启动时间

[root@clsn system]# systemd-analyze time

Startup finished in 387ms (kernel) + 1.406s (initrd) + 31.831s (userspace) = 33.626s

查看具体的使用时间

[root@clsn system]# systemd-analyze blame

10.812s sshd-keygen.service

10.758s abrt-ccpp.service

6.395s chronyd.service

……

生产图表

[root@clsn tmp]# systemd-analyze plot >bootime.svg

[root@clsn tmp]# sz bootime.svg

1.4.12开机启动项优化

[root@kickstart ~]# systemctl list-unit-files|egrep "^ab|^aud|^kdump|vm|^md|^mic|^post|lvm" |awk '{print $1}'|sed -r 's#(.*)#systemctl disable &#g'|bash

Removed symlink /etc/systemd/system/multi-user.target.wants/abrt-ccpp.service.

Removed symlink /etc/systemd/system/multi-user.target.wants/abrt-oops.service.

Removed symlink /etc/systemd/system/multi-user.target.wants/abrt-vmcore.service.

Removed symlink /etc/systemd/system/multi-user.target.wants/abrt-xorg.service.

Removed symlink /etc/systemd/system/multi-user.target.wants/abrtd.service.

Removed symlink /etc/systemd/system/multi-user.target.wants/auditd.service.

Removed symlink /etc/systemd/system/basic.target.wants/microcode.service.

Removed symlink /etc/systemd/system/multi-user.target.wants/vmtoolsd.service.

Removed symlink /etc/systemd/system/vmtoolsd.service.requires/vgauthd.service.

1.4.13中文参考文档

https://access.redhat.com/documentation/zh-CN/Red_Hat_Enterprise_Linux/7/index.html

nginx在windows开机自启动

C:\Users\用户名\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

C:\Users\default.DESKTOP-U9D5JP4\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1.1centos的演变
    • 1.1.1启动流程sysvinit
      • 1.1.2upstart 技术
        • 1.1.3systemd技术
          • 1.1.4三种启动技术对比
            • 1.1.5并行启动三大原理:
            • 1.2安装centos7系统
              • 1.2.1虚拟机选择
                • 1.2.2系统安装
                • 1.3安装完成后的优化
                • 1.4centos7 与centos 6的区别
                  • 1.4.1解决更换网卡后名称变更的问题
                    • 1.4.2nmtui
                      • 1.4.3主机名配置文件的区别
                        • 1.4.4字符集
                          • 1.4.5查看系统版本号
                            • 1.4.6兼容的rc.local
                              • 1.4.7运行级别Runlevel
                                • 1.4.8systemd一统天下
                                  • 1.4.9管理服务
                                    • 1.4.10命令对比
                                      • 1.4.11开机时间优化
                                        • 1.4.12开机启动项优化
                                          • 1.4.13中文参考文档
                                          相关产品与服务
                                          领券
                                          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档