标签:linux
一、创建一个10G的文件系统,类型为ext4,要求开机可自动挂载至单独数据/data目录;
1.首先在系统之中添加一块硬盘,然后通过fdisk -l 命令显示当前磁盘信息
[root@localhost /]# fdisk -l #列出当前系统中的磁盘信息
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0009b708
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 5220351 2097152 82 Linux swap / Solaris
/dev/sda3 5220352 41943039 18361344 83 Linux
Disk /dev/sdb: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
然后通过fdisk /dev/sdb对该硬盘进行分区
[root@localhost /]# fdisk /dev/sdb #对指定的设备进行分区操作
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x591b79ce.
Command (m for help): n #通过输入"n"进行新建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p #分区类型为"p"主分区
Partition number (1-4, default 1): 1 #分区序号为"1"
First sector (2048-125829119, default 2048): #使用默认值
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-125829119, default 125829119): +10G #容量为10G
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): w #保存分区表
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3.对分区进行格式化
使用mkfs.ext4 /dev/sdb1 对分区进行格式化为ext4文件系统
[root@localhost /]# mkfs.ext4 /dev/sdb1 #使用mkfs.ext4命令最指定分区进行ext4格式化
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
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2151677952
80 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
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
4.创建挂载目录,并将分区挂载到当前目录上,然后设置为开机自动挂载
[root@localhost /]# mkdir /data
[root@localhost /]# mount /dev/sdb1 /data
[root@localhost /]# blkid /dev/sdb1 #通过bllid命令查看分区的UUID
/dev/sdb1: UUID="56125348-4317-4768-8b89-58a11ab3fbad" TYPE="ext4"
复制分区的UUID,编辑/etc/fstab 使分区开机自动挂载
vi /etc/fstab
# /etc/fstab
# Created by anaconda on Mon Dec 28 13:08:33 2015
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk‘
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=70f32111-3801-4e51-acb7-a2358d634ff5 / xfs defaults 0 0
UUID=f3475e9a-eb61-477c-ae86-849413418ae7 /boot xfs defaults 0 0
UUID=344d8447-fd3a-4d72-a15e-d4dd9590c7a7 swap swap defaults 0 0
UUID=56125348-4317-4768-8b89-58a11ab3fbad /data ext4 defaults 0 0
通过编辑fstab使分区自动挂载
5.执行df -h命令查看分区挂载情况
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 782M 17G 5% /
devtmpfs 482M 0 482M 0% /dev
tmpfs 490M 0 490M 0% /dev/shm
tmpfs 490M 6.7M 484M 2% /run
tmpfs 490M 0 490M 0% /sys/fs/cgroup
/dev/sda1 497M 98M 400M 20% /boot
/dev/sdb1 9.8G 37M 9.2G 1% /data #显示目前/dev/sdb 目前正挂载在/data目录下。
二、显示`netstat -tan`命令结果中以‘LISTEN’后跟0个、1个或者多个空白字符结尾的行;
[root@simple89860-6 ~]# netstat -tan | egrep "LISTEN[[:space:]]*"
tcp 0 0 0.0.0.0:60512 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 :::111 :::* LISTEN
tcp 0 0 :::38772 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:631 :::* LISTEN
三、添加用户nginx、zabbix、tomcat、nologin以及hadoop用户(nologin用户的shell为/sbin/nologin);而后找出/etc/passwd文件中用户名与其shell名相同的行;
1.通过执行 useradd 命令添加上述所需用户
[root@localhost /]# useradd nginx
[root@localhost /]# useradd zabbix
[root@localhost /]# useradd tomcat
[root@localhost /]# useradd nologin
[root@localhost /]# useradd hadoop
2.通过chsh 命令修改nologin用户的shell
[root@localhost /]# chsh -s /sbin/nologin nologin
Changing shell for nologin.
Shell changed.
3.通过grep命令查找/etc/passwd文件中用域名于shell名相同的行
[root@localhost /]# grep "^\([[:alnum:]]\+\>\).*\1$" /etc/passwd
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
nologin:x:1004:1004::/home/nologin:/sbin/nologin
四、找出/etc/rc.d/init.d/functions文件中某单词(单词中间可以存在下划线)后面跟着一组小括号的行;
##########################################################################################
egrep这一块自己还没有掌握,这个题中的很多东西是参照的别人的,特此说明!
[root@simple89860-6 ~]# cat /etc/rc.d/init.d/functions | egrep "\<[[:alpha:]]?.*[_]?\>[(][)]"
fstab_decode_str() {
checkpid() {
__readlink() {
__fgrep() {
__umount_loop() {
__umount_loopback_loop() {
__pids_var_run() {
__pids_pidof() {
daemon() {
killproc() {
pidfileofproc() {
pidofproc() {
status() {
echo_success() {
echo_failure() {
echo_passed() {
echo_warning() {
update_boot_stage() {
success() {
failure() {
passed() {
warning() {
action() {
action_silent() {
strstr() {
confirm() {
get_numeric_dev() {
is_ignored_file() {
is_true() {
is_false() {
apply_sysctl() {
key_is_random() {
find_crypto_mount_point() {
init_crypto() {
五、使用echo输出一个路径,而后egrep找出其路径基名;进一步的使用egrep取出其目录名(注意是目录名,而非目录路径);
####################################################################################################
egrep这一块自己还没有掌握,这个题中的很多东西是参照的别人的,特此说明!
[root@simple89860-6 ~]# echo "/etc/sysconfig/network" | egrep -o "\<[[:alnum:]]+\>$"
network
[root@simple89860-6 ~]#
六、查找/usr目录下不属于root、bin或hadoop的所有文件;
[root@localhost /]# find /usr -not -user root -a -not -user bin -a -not -user hadoop
/usr/share/polkit-1/rules.d #查找到的不属于上述条件的文件
七、某天系统被入侵了,黑客在你系统下留下木马文件: 现需要查找当前系统上没有属主或属组,且最近一周内曾被访问过的所有文件; 另外,需要查找/etc目录下大于20k且类型为普通文件的所有文件;
1.
[root@localhost /]# find /etc -nouser -o -nogroup -atime -7
[root@localhost /]# #查找结果是无
2.find /etc -size +20k -typ f
[root@localhost /]# find /etc -size +20k -type f
/etc/pki/ca-trust/extracted/java/cacerts
/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem
/etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem
/etc/pki/nssdb/cert8.db
/etc/udev/hwdb.bin
/etc/services
/etc/sysconfig/network-scripts/network-functions-ipv6
/etc/ssh/moduli
/etc/dnsmasq.conf
/etc/selinux/targeted/contexts/files/file_contexts
/etc/selinux/targeted/modules/active/base.pp
/etc/selinux/targeted/modules/active/file_contexts
/etc/selinux/targeted/modules/active/file_contexts.template
/etc/selinux/targeted/modules/active/modules/apache.pp
/etc/selinux/targeted/modules/active/modules/init.pp
/etc/selinux/targeted/modules/active/modules/staff.pp
/etc/selinux/targeted/modules/active/modules/sysadm.pp
/etc/selinux/targeted/modules/active/modules/unprivuser.pp
/etc/selinux/targeted/modules/active/modules/virt.pp
/etc/selinux/targeted/modules/active/modules/xguest.pp
/etc/selinux/targeted/modules/active/modules/xserver.pp
/etc/selinux/targeted/policy/policy.29
/etc/openldap/certs/cert8.db
/etc/postfix/access
/etc/postfix/header_checks
/etc/postfix/main.cf
八、创建目录/test/data,让某组内普通用户对其有写权限,且创建的所有文件的属组为目录所属的组;此外,每个用户仅能删除自己的文件。
######################################################################################################
针对目录赋予权限这道题目部分内容为百度的,特此说明;
[root@localhost Test]# mkdir -p /test/data
[root@localhost /]# chmod g+w /test/data/
[root@localhost /]# chmod g+s /test/data/
[root@localhost /]# chmod o+t /test/data/
Linux 运维实践案例-2015年12月20日-12月31日
标签:linux
原文地址:http://simple89860.blog.51cto.com/9658631/1730047