1、linux现连接一个新的存储(如 /dev/sdb,容量为200G)一人应用程序需要在 /data 目录使用此存储的100G的内存空间,若做成 LVM 需要哪些步骤,请描述
[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write the
m.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x10cd6a18.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-419430399, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-419430399, default 41
9430399): +100G
Partition 1 of type Linux and of size 100 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# pvcreate /dev/sdb1 //创建PV
Physical volume "/dev/sdb1" successfully created
[root@localhost ~]# vgcreate vgdata /dev/sdb1 //创建VG
Volume group "vgdata" successfully created
[root@localhost ~]# lvcreate -n lvdata -l 100%free vgdata //创建LV
Logical volume "lvdata" created.
[root@localhost ~]# mkfs.ext4 /dev/vg //下面的那条命令才是需要执行的,我在这里用了Tab键补全
vga_arbiter vgdata/
[root@localhost ~]# mkfs.ext4 /dev/vgdata/lvdata //要使用lvm就必须对lv进行格式化和挂载
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26213376 blocks
1310668 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2174746624
800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]# mount /dev/vgdata/lvdata /data/ //挂载
[root@localhost ~]# lsblk /dev/sdb //查看
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 0 200G 0 disk
└─sdb1 8:17 0 100G 0 part
└─vgdata-lvdata 253:0 0 100G 0 lvm /data
2、打印 /etc/passwd 的 1 到 3 行
方法一:
[root@centos7 ~]# sed -n '1,3p' /etc/passwd
root:x:0:0:root:/root:/bin/bash
system:x:0:0::/home/system:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
方法二:
[root@centos7 ~]# awk 'NR>=1&&NR<=3{print $0}' /etc/passwd
root:x:0:0:root:/root:/bin/bash
system:x:0:0::/home/system:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
3、用 sed 命令将指定的路径 /usr/local/http 替换成为 /usr/src/local/http
[root@centos7 ~]# echo "/usr/local/http/" | sed 's#/usr/local/#/usr/src/local/#'
4、打印 /etc/ssh/sshd_config 的第一百行
sed -n '100p' /etc/ssh/sshd_config
5、用 sed 命令永久关闭防火墙
[root@centos7 ~]# sed -i.bak 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@centos7 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
7、快速查找 /root 目录中大于 2M 的文本,并将文件中的wang,换成www.wang.com
[root@centos6 ~]# dd if=/dev/zero of=f1.txt bs=1M count=3
3+0 records in
3+0 records out
3145728 bytes (3.1 MB) copied, 0.0027172 s, 1.2 GB/s
[root@centos6 ~]# echo "wang" >> f1.txt
[root@centos6 ~]# find /root/ -maxdepth 1 -type f -size +2M -exec sed -i 's/wang/www.wang.com/g' {} \;
[root@centos6 ~]# cat f1.txt
www.wang.com
8、对 /etc/fstab 非#号开头的加注释
sed -r 's/(^[^#])/#&/' /etc/fstab
9、CentOS7 取 取 eno16777736 的 的 IP 地址
[root@centos7 ~]# ifconfig eno16777736 | sed -n 2p | sed -e 's/.*net //' -e 's/ net.*//'
172.16.251.191
10 、查看本机路由的三种方式
[root@centos6 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.220.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
172.16.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 172.16.0.1 0.0.0.0 UG 0 0 0 eth0
[root@centos6 ~]# netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.220.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
172.16.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 172.16.0.1 0.0.0.0 UG 0 0 0 eth0
[root@centos6 ~]# ip route
192.168.220.0/24 dev eth1 proto kernel scope link src 192.168.220.157 metric 1
169.254.0.0/16 dev eth0 scope link metric 1002
172.16.0.0/16 dev eth0 proto kernel scope link src 172.16.251.6
default via 172.16.0.1 dev eth0 proto static
11、发 4 个包,与 测试本机与 172.18.0.1 的连通性
ping -c 4 -w 4 172.168.220.164
13 、分别提供 CentOS6 与 CentOS7
[root@centos7 ~]# hostname //先查看一下原有主机名
centos7
[root@centos7 ~]# hostnamectl set-hostname centos7.9 //更改主机名(第一种方法)
[root@centos7 ~]# hostname // 查看一下是否更改成功
centos7.9
[root@centos7 ~]# hostname centos7 //更改主机名(第二种方# 法)
[root@centos7 ~]# hostname //查看一下是否修改成功
centos7
上面是 centos7 修改主机名的两种方法;
下面我们来看 centos6 又是如何修改主机名的:
[root@centos6 ~]# hostname //查看原有主机名一下
centos6
[root@centos6 ~]# hostname centos6.9 //更改主机名
[root@centos6 ~]# cat /etc/sysconfig/network //查看一下配置文件是否修改成功
NETWORKING=yes
HOSTNAME=centos6.9
14、如何禁 ping
[root@node0 ~]# echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all //这个时候,别人是可以 ping 通自己的
[root@node1 ~]# ping 192.168.6.6
PING 192.168.6.6 (192.168.6.6) 56(84) bytes of data.
64 bytes from 192.168.6.6: icmp_seq=1 ttl=64 time=1.79 ms
64 bytes from 192.168.6.6: icmp_seq=2 ttl=64 time=0.597 ms
[root@node0 ~]# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
[root@node1 ~]# ping 192.168.6.6 //ping 不能了
PING 192.168.6.6 (192.168.6.6) 56(84) bytes of data.
--- 192.168.6.6 ping statistics ---
93 packets transmitted, 0 received, 100% packet loss, time 92168ms
网友评论