Linux基础知识day-5
Posted neuropathy_ldsly
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux基础知识day-5相关的知识,希望对你有一定的参考价值。
基础命令:
51.mkfs:用于格式化磁盘。例如:格式化/dev/sdb1
mkfs.ext4 /de/sdb1
mkfs.ext3 /de/sdb1
mkfs.xfs /de/sdb1
mkfs.vfat /de/sdb1
1 [[email protected] ~]# mkfs.xfs /dev/sdb1 2 meta-data=/dev/sdb1 isize=512 agcount=4, agsize=65472 blks 3 = sectsz=512 attr=2, projid32bit=1 4 = crc=1 finobt=0, sparse=0 5 data = bsize=4096 blocks=261888, imaxpct=25 6 = sunit=0 swidth=0 blks 7 naming =version 2 bsize=4096 ascii-ci=0 ftype=1 8 log =internal log bsize=4096 blocks=855, version=2 9 = sectsz=512 sunit=0 blks, lazy-count=1 10 realtime =none extsz=4096 blocks=0, rtextents=0 11 12 [[email protected] /]# mkfs.ext4 /dev/sdb1 13 mke2fs 1.42.9 (28-Dec-2013) 14 Filesystem label= 15 OS type: Linux 16 Block size=4096 (log=2) 17 Fragment size=4096 (log=2) 18 Stride=0 blocks, Stripe width=0 blocks 19 65536 inodes, 261888 blocks 20 13094 blocks (5.00%) reserved for the super user 21 First data block=0 22 Maximum filesystem blocks=268435456 23 8 block groups 24 32768 blocks per group, 32768 fragments per group 25 8192 inodes per group 26 Superblock backups stored on blocks: 27 32768, 98304, 163840, 229376 28 29 Allocating group tables: done 30 Writing inode tables: done 31 Creating journal (4096 blocks): done 32 Writing superblocks and filesystem accounting information: done 33 34 [[email protected] /]#
52.mkswap和swapon
mkswap:用于创建交换分区
swapon:用户挂载交换分区
例如:
1 [[email protected] /]# mkswap /dev/sdb1 2 mkswap: /dev/sdb1: warning: wiping old ext4 signature. 3 Setting up swapspace version 1, size = 1047548 KiB 4 no label, UUID=8392318c-5956-492a-96c0-f98f484bd1ef 5 [[email protected] /]# 6 [[email protected] /]# swapon /dev/sdb1 7 [[email protected] /]# lsblk 8 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT 9 sda 8:0 0 8G 0 disk 10 ├─sda1 8:1 0 1G 0 part /boot 11 └─sda2 8:2 0 7G 0 part 12 ├─cl-root 253:0 0 6.2G 0 lvm / 13 └─cl-swap 253:1 0 820M 0 lvm [SWAP] 14 sdb 8:16 0 1G 0 disk 15 └─sdb1 8:17 0 1023M 0 part [SWAP] 16 sr0 11:0 1 4G 0 rom /var/www/html/iso 17 [[email protected] /]#
53.ifconfig:用于查看激活的网卡信息
如果没有ifconfig命令,可以安装net-tools包就有了。
ifup:激活一块网卡
ifdown:停用一块网卡
ifconfig [网卡名] [IP/Netmask] :临时配置一个IP
1 [[email protected] ~]# ifconfig 2 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 3 inet 192.168.119.129 netmask 255.255.255.0 broadcast 192.168.119.255 4 inet6 fe80::d060:4681:d1fd:8d0 prefixlen 64 scopeid 0x20<link> 5 ether 00:0c:29:c3:86:17 txqueuelen 1000 (Ethernet) 6 RX packets 311 bytes 90725 (88.5 KiB) 7 RX errors 0 dropped 0 overruns 0 frame 0 8 TX packets 222 bytes 32237 (31.4 KiB) 9 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 10 11 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 12 inet 127.0.0.1 netmask 255.0.0.0 13 inet6 ::1 prefixlen 128 scopeid 0x10<host> 14 loop txqueuelen 1 (Local Loopback) 15 RX packets 0 bytes 0 (0.0 B) 16 RX errors 0 dropped 0 overruns 0 frame 0 17 TX packets 0 bytes 0 (0.0 B) 18 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 19 20 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 21 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 22 ether 52:54:00:67:b1:2a txqueuelen 1000 (Ethernet) 23 RX packets 0 bytes 0 (0.0 B) 24 RX errors 0 dropped 0 overruns 0 frame 0 25 TX packets 0 bytes 0 (0.0 B) 26 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
54.网卡配置文件:/etc/sysconfig/network-scripts/ifcfg-XXXX :ifcfg-XX开头的网卡对应名称文件。可更改配置文件然后重启网络服务生效配置。
如果网卡没有下列条目,可以手动添加至文件中。
TYPE:类型
BOOTPROTO:网卡工作模式(静态or动态)
IPADDR:IP地址
NETMASK:子网掩码
ONBOOT:服务启动时,是否启动网卡
DNS1:主DNS地址
DNS2:副DNS地址
GATEWAY:网关地址
55.nmcli:使用命令配置网卡信息。此种方式相较于上面的命令复杂但是管理很方便。推荐新手使用上面的两种方式。
nmcli中connection指的是一种逻辑上的网卡。device指的是真实的物理设备。connection和device绑定起来就相当于给某个device配置上网络信息。
nmcli connection show:显示连接信息
1 [[email protected] ~]# nmcli connection show 2 NAME UUID TYPE DEVICE 3 ens33 97218e89-b4d0-49a8-a37a-ac86d833c081 802-3-ethernet ens33 4 virbr0 d3bbdc43-cead-4a09-811f-8c0661350ad8 bridge virbr0 5 [[email protected] ~]#
nmcli device show:显示设备信息
1 [[email protected] ~]# nmcli device show 2 GENERAL.DEVICE: virbr0 3 GENERAL.TYPE: bridge 4 GENERAL.HWADDR: 52:54:00:67:B1:2A 5 GENERAL.MTU: 1500 6 GENERAL.STATE: 100 (connected) 7 GENERAL.CONNECTION: virbr0 8 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 9 IP4.ADDRESS[1]: 192.168.122.1/24 10 IP4.GATEWAY: 11 IP6.GATEWAY: 12 13 GENERAL.DEVICE: ens33 14 GENERAL.TYPE: ethernet 15 GENERAL.HWADDR: 00:0C:29:C3:86:17 16 GENERAL.MTU: 1500 17 GENERAL.STATE: 100 (connected) 18 GENERAL.CONNECTION: ens33 19 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/0 20 WIRED-PROPERTIES.CARRIER: on 21 IP4.ADDRESS[1]: 192.168.119.129/24 22 IP4.GATEWAY: 23 IP4.DNS[1]: 192.168.119.1 24 IP4.DOMAIN[1]: localdomain 25 IP6.ADDRESS[1]: fe80::d060:4681:d1fd:8d0/64 26 IP6.GATEWAY: 27 28 GENERAL.DEVICE: lo 29 GENERAL.TYPE: loopback 30 GENERAL.HWADDR: 00:00:00:00:00:00 31 GENERAL.MTU: 65536 32 GENERAL.STATE: 10 (unmanaged) 33 GENERAL.CONNECTION: -- 34 GENERAL.CON-PATH: -- 35 IP4.ADDRESS[1]: 127.0.0.1/8 36 IP4.GATEWAY: 37 IP6.ADDRESS[1]: ::1/128 38 IP6.GATEWAY:
nmcli connection [up|down|reload] [连接名]:来启用、关闭、重载某个连接
[[email protected] ~]# nmcli connection show NAME UUID TYPE DEVICE eth1 8d601dba-ddb1-433f-8934-8f79cf9d8c67 802-3-ethernet ens33 ens33 97218e89-b4d0-49a8-a37a-ac86d833c081 802-3-ethernet -- [[email protected] ~]# nmcli connection down eth1 [[email protected] ~]# nmcli connection show NAME UUID TYPE DEVICE ens33 97218e89-b4d0-49a8-a37a-ac86d833c081 802-3-ethernet ens33 eth1 8d601dba-ddb1-433f-8934-8f79cf9d8c67 802-3-ethernet -- [[email protected] ~]#
nmcli connection add con-name [连接名] type [连接类型] ifname [设备名]:添加一个连接并绑定设备
1 [[email protected] ~]# nmcli connection add con-name eth1 type ethernet ifname ens33 2 Connection ‘eth1‘ (8d601dba-ddb1-433f-8934-8f79cf9d8c67) successfully added. 3 [[email protected] ~]# nmcli connection show 4 NAME UUID TYPE DEVICE 5 ens33 97218e89-b4d0-49a8-a37a-ac86d833c081 802-3-ethernet ens33 6 eth1 8d601dba-ddb1-433f-8934-8f79cf9d8c67 802-3-ethernet -- //ens33设备目前绑定在 ens33连接上,所以 eth1 的DEVICE信息为“--”。 7 [[email protected] ~]#
nmcli connection modify eth1 ipv4.addresses "192.168.119.130/24" ipv4.gateway 192.168.1.1 ipv4.dns 114.114.114.114 ipv4.method manual connection.autoconnect yes
//上面的命令是为 eth1 配置 IP地址:192.168.119.130/24 网关:192.168.1.1 DSN地址:114.114.114.114 地址为静态地址并设置为开机自动启动。
nmcli connection modify [连接名] ipv4.addresses "[IP地址/掩码]" ipv4.gateway [网关地址] ipv4.dns [DNS地址] ipv4.method [模式] connection.autoconnect yes[开机自启]
1 [[email protected] ~]# nmcli connection modify eth1 ipv4.addresses "192.168.119.130/24" ipv4.gateway 192.168.1.1 ipv4.dns 114.114.114.114 ipv4.method manual connection.autoconnect yes 2 3 [[email protected] ~]# nmcli connection show eth1 4 connection.id: eth1 5 connection.uuid: 8d601dba-ddb1-433f-8934-8f79cf9d8c67 6 connection.stable-id: -- 7 connection.interface-name: ens33 8 connection.type: 802-3-ethernet 9 connection.autoconnect: yes 10 connection.autoconnect-priority: 0 11 connection.timestamp: 1496156248 12 connection.read-only: no 13 connection.permissions: 14 connection.zone: -- 15 connection.master: -- 16 connection.slave-type: -- 17 connection.autoconnect-slaves: -1 (default) 18 connection.secondaries: 19 connection.gateway-ping-timeout: 0 20 connection.metered: unknown 21 connection.lldp: -1 (default) 22 802-3-ethernet.port: -- 23 802-3-ethernet.speed: 0 24 802-3-ethernet.duplex: -- 25 802-3-ethernet.auto-negotiate: yes 26 802-3-ethernet.mac-address: -- 27 802-3-ethernet.cloned-mac-address: -- 28 802-3-ethernet.generate-mac-address-mask:-- 29 802-3-ethernet.mac-address-blacklist: 30 802-3-ethernet.mtu: auto 31 802-3-ethernet.s390-subchannels: 32 802-3-ethernet.s390-nettype: -- 33 802-3-ethernet.s390-options: 34 802-3-ethernet.wake-on-lan: 1 (default) 35 802-3-ethernet.wake-on-lan-password: -- 36 ipv4.method: manual 37 ipv4.dns: 114.114.114.114 38 ipv4.dns-search: 39 ipv4.dns-options: (default) 40 ipv4.dns-priority: 0 41 ipv4.addresses: 192.168.119.130/24 42 ipv4.gateway: 192.168.1.1 43 ipv4.routes: 44 ipv4.route-metric: -1 45 ipv4.ignore-auto-routes: no 46 ipv4.ignore-auto-dns: no 47 ipv4.dhcp-client-id: -- 48 ipv4.dhcp-timeout: 0 49 ipv4.dhcp-send-hostname: yes 50 ipv4.dhcp-hostname: -- 51 ipv4.dhcp-fqdn: -- 52 ipv4.never-default: no 53 ipv4.may-fail: yes 54 ipv4.dad-timeout: -1 (default) 55 ipv6.method: auto 56 ipv6.dns: 57 ipv6.dns-search: 58 ipv6.dns-options: (default) 59 ipv6.dns-priority: 0 60 ipv6.addresses: 61 ipv6.gateway: -- 62 ipv6.routes: 63 ipv6.route-metric: -1 64 ipv6.ignore-auto-routes: no 65 ipv6.ignore-auto-dns: no 66 ipv6.never-default: no 67 ipv6.may-fail: yes 68 ipv6.ip6-privacy: -1 (unknown) 69 ipv6.addr-gen-mode: stable-privacy 70 ipv6.dhcp-send-hostname: yes 71 ipv6.dhcp-hostname: -- 72 ipv6.token: -- 73 [[email protected] ~]#
56.route:查看本机的路由信息
添加网关:
route add default gw [网关IP] dev [网卡名]
删除网关:
route add default gw [网关IP]
57.systemctl :控制服务的启动停止。
systemctl [stop|start|restart] [服务名]
58.rpm:用于安装本地的rpm包。
用法rpm [选项] [参数]
-qa:查询系统已安装的所有软件包
-ivh:安装软件包
-qi:查询软件包信息
-ql:查询软件包中的文件
-qf:查看某个文件是那个rpm包产生的
-e:卸载rpm包
59.yum:centos/redhat/Fedora中的 软件包管理程序。
安装软件包:
yum install [软件包名]
删除软件包:
yum remove [软件包名]
查询软件包:
yum search [软件包名]
建立yum源缓存:
yum makecache
查看源列表:
yum repolist
安装软件包组:
yum groupinstall [软件包组名]
删除软件包组:
yum groupremove [软件包名]
清空yum缓存:
yum clean all
创建仓库:
createrepo [rpm包文件夹]
自定义repo文件,使用本地iso内的源:
1)编辑配置文件:vim /etc/yum.repos.d/iso.rpeo ,并移除其他所有的repo文件。
2)文件内容如下:
[name] //源名称,不允许包含空格
name=lcoal iso //源简介,随意填写
baseurl=file:///media //源地址,支持http、ftp、file(本地文件)
gpgcheck=0 //是否校验,0不校验,1校验(需提供密钥文件)
enabled=1 //是否启用这个源,1启用,0不启用
3)确保本地iso挂载正确,baseurl填写的挂载点对。执行yum clean all 清空缓存。
4)执行yum makecache,建立缓存。
源码安装软件:
例如安装Python3.6.1:
1)从官网获取源码包:https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
2)解压Python-3.6.1.tgz。
1 [[email protected] Downloads]# tar xvf Python-3.6.1.tgz
3)进入解压出的目录执行:./configure --prefix=/usr/local/python36 ,--prefix参数用于指定安装目录。
1 [[email protected] Python-3.6.1]# ./configure --prefix=/usr/local/python36
4)通过检查之后执行make && make install,如报错请查询错误原因解决。
1 [[email protected] Python-3.6.1]# make && make install
5)进入安装目录,执行./python3,正确执行安装完毕。想在系统任何位置调用Python就添加路径变量到系统就行。
[[email protected] bin]# cd /usr/local/python36/ [[email protected] python36]# ls bin include lib share [[email protected] python36]# cd bin/ [[email protected] bin]# ls 2to3 easy_install-3.6 idle3.6 pip3.6 pydoc3.6 python3.6 python3.6m python3-config pyvenv-3.6 2to3-3.6 idle3 pip3 pydoc3 python3 python3.6-config python3.6m-config pyvenv [[email protected] bin]# ./python3 Python 3.6.1 (default, May 31 2017, 01:22:32) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exit() [[email protected] bin]#
以上是关于Linux基础知识day-5的主要内容,如果未能解决你的问题,请参考以下文章
Python 基础 - Day 5 Learning Note - 模块 之 介绍篇