linux base instruction (lower)

Twelve Linux partition, mount

12.1 Partition Basics

12.1.1 partitioning

mbr分区:
1.最多支持四个主分区
2.系统只能安装在主分区上
3.扩展分区要占一个主分区
4.mbr最大只支持2TB,但拥有最好的兼容性
gpt分区:
1.支持无限多个主分区(但操作系统会限制,比如windows下最多支持128个主分区)
2.最大支持18EB的容量(1EB=1024PB)
3.windows7 64位后支持gpt模式

12.1.2 windows partition under

1569514978762

12.2Linux partition

12.2.1 introduces the principle of

1.Linux is whether there are several partitions, which points to the directory to use, in the final analysis it is only one root directory, a separate and unique file structure, Linux each partition is used to make up part of the file system

2.Linux using a processing method called "load", and its entire file system contains a set of files and directories, and a partition and a directory link. Then you want to load a partition will make storage space available under a directory

1569494254388

12.2.2 Drive description

Now the main hard drives are scsi hard disk

linux scsi hard disk in the identification of "sdx ~"

Such as:

sda1: 1 indicates that the disk partition, here to give the boot, to boot, linux operating system can not start their own, need this guide to start, similar to the temporary operating system windows.

sda2: 2 represents the disk partition, where the virtual memory is normally set to 1.5 to 2 times the physical memory is allocated out of the disk space, as when the physical memory is not enough, the preliminary memory, but at a much slower.

sda3: 3 indicates that the disk partition, this one is going to the root directory / of things at the root of all accounts this space.

So, assuming that this machine has 20g disk, it will give boot 200mb, 2g to the swap, the rest of 17.8g gave root directory.

Mount point: mount point of this document is to hook with a piece of the disk, the operation of this document is the operating disk.

1569516268004

12.3 Mounting classic case

Demand is to give our Linux system to add a new hard drive and mount it to / home / newdisk

步骤:
1.虚拟机添加硬盘
2.分区
    fdisk /dev/sdb
    m   选择帮助
    n   增加分区    选这个,增加一个分区,然后会让你选配置,随便选然后↓
    p   划主分区
    1   主分区1
    1   默认
    w   写入分区信息并退出   上面的增加分区和配置弄完以后,在选w,就有分区了。

3.格式化
    mkfs -t ext4 /dev/sdb1  这个是给分区增加一个uuid的。

4.挂载
    mount /dev/sdb1 /home/newdisk
    
    注意:以上这种挂载方式,只是临时挂在,重启就莫得了。要自动挂载的话,用下面这种方式


5.设置自动挂载
    vim /etc/fstab
    (内容如下)
    mount -a   立即生效

1569518493964

12.4 Disk case inquiry

12.4.1 query system overall disk usage

df -lh

12.4.2 query disk consumption specified directory

du  [选项]        /目录
    -h  带计量单位 (以人类可读)
    -s  指令目录占用磁盘大小
    -a  含文件
    -c  列出明细,并显示汇总值
    --max-depth=1   子目录深度
例子:
查询  /opt 目录的磁盘占用情况,深度为 1

du -ach --max-depth=1 /opt

12.4.3 Common Case

1.统计/home 文件夹下文件的个数
    ls -l /home | grep '^-' | wc -l
2.统计/home 文件夹下目录的个数
    ls -l /home | grep '^d' | wc -l
3.统计/home 文件夹下文件的个数,包括子文件夹里的
    ls -lR /home | grep '^-' | wc -l
4.统计文件夹下目录的个数,包括子文件夹里的
    ls -lR /home | grep '^d' | wc -l

Thirteen Network Configuration

13.1Linux network configuration diagram (NAT)

img

13.2 view network ip and gateway

13.2.1 Viewing Virtual Network Editor

img

13.2.2 modify ip address (to modify the virtual network ip)

img

13.2.3 View Gateway

img

13.2.4 查看windows环境的中 VMnet8

网络配置 (ipconfig 指令)

1.使用命令查看

ipconfig

2.界面查看

img

13.3 ping 测试主机之间网络连通

13.3.1 基本语法

ping 目标ip               测试当前服务器是否可以连接目的主机

13.3.2 小例子

测试当前服务器是否可以连接百度

ping www.baidu.com

13.4 Linux网络环境配置

13.4.1 第一种方法(自动获取)

img

此方式的缺点:

linux 启动后会自动获取 IP,缺点是每次自动获取的
ip 地址可能不一样。这个不适用于做服务器,因为我们的服务器的
ip 需要时固定的。

13.4.2 第二种方法(指定固定ip)

直 接 修 改 配 置 文 件 来 指 定 IP, 并 可 以 连 接 到 外 网

vim  /etc/sysconfig/network-scripts/ifcfg-eth0

img

修改配置文件后,要重启网络服务才能生效

service network restart

十四 进程管理

14.1 基本介绍

1.在 LINUX 中,每个执行的程序(代码)都称为一个进程。每一个进程都分配一个 ID 号
2.每一个进程,都会对应一个父进程,而这个父进程可以复制多个子进程
3.每个进程都可能以两种方式存在的。前台与后台,所谓前台进程就是用户目前的屏幕上可以进行操作的。后台进程则是实际在操作,但由于屏幕上无法看到的进程,通常使用后台方式执行
4.一般系统的服务都是以后台进程的方式存在,而且都会常驻在系统中。直到关机才才结束

14.2 显示系统执行的进程

14.2.1 说明

查看进行使用的指令是 ps ,一般来说使用的参数是 ps -aux,ps -ef,正常与grep连用

14.2.2 ps指令详解

BSD风格 详解

user            用户名称
pid             进程号
%cpu            进程占用cpu百分比
%%mem           进程占用物理内存的百分比
vsz             进程占用虚拟内存的大小
rss             进程占用物理内存的大小
tty             终端名称(后台则为?)
stat            进程状态
    S:睡眠
    s:会话的先导进程
    N:进程拥有比普通优先级更低的优先级
    R:正在运行
    D:短期等待
    Z:僵尸进程
    T:被跟踪或者被停止
start           进程启动时间
time            使用cpu总时间
command         启动进程所用的命令和参数,如果过长会被截断显示

system V 风格详解

uid             用户id
pid             进程id
ppid            父进程id
C               进程占cpu百分比
stime           进程启动时间
tty             终端名称(后台则为?)
cmd             启动进程所用的命令和参数
例子:
1.查看sshd进程的父进程id是多少

14.3 终止进程kill和killall

14.3.1 说明

若是某个进程执行一半需要停止时,或是已消了很大的系统资源时,此时可以考虑停止该进程。

14.3.2 基本语法:

kill 进程号
    -9 强迫进程立即停止
killall 进程名称

14.3.4 例子

1.踢掉某个非法登录用户

2.终止远程登录服务
sshd, 在适当时候再次重启
sshd 服务

3.终止多个 gedit 编辑器 【killall
, 通过进程名称来终止进程】

4.强制杀掉一个终端

14.4 查看进程树 pstree

pstree [选项]
    -p    查看进程pid
    -u    查看进程所属用户

14.5 服务(service)管理

14.5.1 说明

服务(service) 本质就是进程,但是是运行在后台的,通常都会监听某个端口,等待其它程序的请求,比如(mysql , sshd 防火墙等),因此我们又称为守护进程,是
Linux 中非常重要的知识点。

img

14.5.2 基本使用

service 服务名 [start | stop | restart | reload | status]

14.5.3 例子

1.查看当前防火墙的状况,关闭防火墙和重启防火墙(iptables)

img

service这种方式关闭或者打开服务只是临时生效

重启后,还是回到以前对服务的设置

14.5.4 查看服务名

/etc/init.d 此文件夹下放着系统都有哪些服务

ls -l /etc/init.d

14.5.5 服务器运行级别(runlevel)

查看或者修改默认级别: vi /etc/inittab

Linux 系统有 7 种运行级别(runlevel):常用的是级别 3 和 5

运行级别 0:系统停机状态,系统默认运行级别不能设为 0,否则不能正常启动

运行级别 1:单用户工作状态,root 权限,用于系统维护,禁止远程登陆

运行级别 2:多用户状态(没有 NFS),不支持网络

运行级别 3:完全的多用户状态(有 NFS),登陆后进入控制台命令行模式

运行级别 4:系统未使用,保留

运行级别 5:X11 控制台,登陆后进入图形 GUI 模式

运行级别 6:系统正常关闭并重启,默认运行级别不能设为 6,否则不能正常启动

14.5.6 开机流程说明

img

14.5.7 chkconfig指令

14.5.7.1 说明

通过 chkconfig 命令可以给每个服务的各个运行级别设置自启动/关闭

14.5.7.2 基本语法

chkconfig                             查看每个服务的配置
chkconfig 服务名                       查看具体服务的配置
chkconfig --level 5 服务名  on/off     给服务设置是否自动启动

14.5.7.3 例子

1.请显示当前系统所有服务的各个运行级别的运行状态
2.请查看 sshd 服务的运行状态
3.将 sshd 服务在运行级别 5 下设置为不自动启动,看看有什么效果?
4.当运行级别为 5 时,关闭防火墙。
5.在所有运行级别下,关闭防火墙
6.在所有运行级别下,开启防火墙

chkconfig 重新设置服务后自启动或关闭,需要重启机器
reboot
才能生效

14.6 动态监控进程

14.6.1 说明

top
与 ps 命令很相似。它们都用来显示正在执行的进程。Top 与 ps 最大的不同之处,在于
top 在执行一段时间可以更新正在运行的的进程

14.6.2 基本语法

top [选项]
    -d          指定每隔几秒更新,默认3秒
    -i          不显示任何闲置或者僵尸进程
    -p id号      监听指定进程


交互操作:
P       以cpu使用率排序,默认就这个
M       以内存使用率排序
N       以pid排序
u       监听具体用户
k       终止指定进程
q       退出top

img

14.6.3 examples

1.监视特定用户
2.终止指定的进程
3.指定系统状态更新的时间(每隔 10 秒自动更新, 默认是 3 秒)

Fifteen. Rpm and yum

15.1 rpm package management

15.1.1 Introduction

An Internet download package packaging and installation tools. It generates a .RPM
file extension. RPM
is the RedHat
abbreviation Package Manager (RedHat package management tool), similar to the
windows of setup.exe

Simple query command 15.1.2 rpm package

rpm –qa             查询已安装的 rpm 列表

15.1.3 rpm basic format of the package name

A rpm package name: firefox-45.0.1-1.el6.centos.x86_64.rpm

firefox:名称
45.0.1-1:版本号
el6.centos.x86_64:centos6.X---64位

15.1.4 rpm other instructions

rpm -q 软件包名                 查看是否已经安装
rpm -qi 软件包名                查看软件包信息
rpm -ql 软件包名                查看软件包中的文件安装位置
rpm -qf 文件(如:/etc/passwd)    查看某个文件属于哪个rpm包

15.1.5 Uninstall rpm package

rpm -e 包名
例子:
rpm -e firefox

Package dependency problems:

If other packages depend on the packages you want to uninstall, uninstall it will produce an error message

 rpm -e --nodeps 包名             强制删除

15.1.6 install the rpm package

rpm -ivh RPM 包全路径名称

i:install 安装
v:verbose 提示
h:hash 进度条
例子:安装firefox

1.挂载centos的iso镜像文件
2.media下找到rpm
3.拷贝到opt下
4.安装

15.2 yum

15.2.1 Description

Yum
is a
Shell front-end package manager. Based RPM package management can be automatically downloaded from the server specified
RPM package and install, can be handled automatically dependencies and install all dependent packages. Use yum premise that can be networked.

Type in python pip

15.2.2 Basic Instructions

yum list|grep xx        查询yum服务器上是否有需要安装的包
yum install xxx         下载安装
例子:
1.使用yum下载安装firefox

Guess you like

Origin www.cnblogs.com/chanyuli/p/12191959.html