第1章centos7的使用
串行启动:一次一个,一个一个启动
并行启动:全部的一起启动
init优点
运行非常良好。主要依赖于shell脚本
init缺点
1、启动慢
2、容易夯住,fstab与nfs挂载问题
使用的版本:
centos6
ubuntu14
克服init固有缺点,提高系统的启动速度
降低迁移成本
1、解决socket 依赖/端口依赖
socket 网络套接字文件
2、解决D-Bus
依赖:采用了D-Bus 为程序之间的通讯工具,类似消息队列,可以缓存信息
3、解决文件系统依赖、类似autofs机制
磁盘空间尽量大一些
1)开机进入安装
2)按下TAB键
添加内核参数 让网卡名称变为eth
空格 输入 net.ifnames=0 biosdevname=0 然后回车
3)选择语言
4) 设置网络连接和主机名
5)注意勾选开机自启动
6) 设置ip地址
同样的方式将另外 一块网卡配置好
7) 修改主机名
8)选择安装的环境,选择最小化安装。
注意勾选依赖包
9)磁盘分区为自定义分区。
选择/boot挂载点的大小。这里设置为1g
添加swap挂载点
注意选择都为标准分区类型,直接写到磁盘
添加根分区后选择完成
关闭密码保护
选择关闭
关闭KDUMP功能
开始安装,注意为469个包
安装的过程中设置root的密码。
查看系统版本
[root@CentOS7 ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
修改yum源,base源
[root@CentOS7 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2573 100 2573 0 0 2940 0 --:--:-- --:--:-- --:--:-- 2940
epel源
[root@CentOS7 ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
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 补全命令参数的包
更改名称的方法
修改CentOS7网卡名称为传统名称eth0格式
http://oldboy.blog.51cto.com/2561410/1722101
centos7 上管理网路的图形化工具
临时 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
临时
[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
[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"
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
之前的查看运行级别的方法依旧使用
[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
系统启动文件的目录
[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
关闭防火墙服务及开机自启动
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的启动脚本,而且够在进程启动过程中更有效地引导加载服务。。
systemctl start crond.service和systemctl start crond效果一样。
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
[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.
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 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有