您的位置:首页 > 运维架构 > Linux

一些Linux必须会的东西2.0

2016-11-02 20:25 260 查看
1,会创建LV的快照 

实验:

[root@storage ~]# lvcreate -L 50M -n lv2 vg0

[root@storage ~]# mkfs.ext4 /dev/vg0/lv2

[root@storage ~]# mkdir /mnt/real

[root@storage ~]# mount /dev/vg0/lv2 /mnt/real/

[root@storage ~]# cp /etc/passwd /mnt/real/

[root@storage ~]# cp /etc/hosts /mnt/real/

[root@storage ~]# dmsetup ls --tree

vg0-lv2 (253:2)

└─ (8:6)

[root@storage ~]# lvcreate -s -L 10M -n lv2-sn /dev/vg0/lv2

Rounding up size to full physical extent 12.00 MiB

Logical volume "lv2-sn" created

[root@storage ~]# lvs

LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert

lv0 vg0 -wi-ao--- 700.00m

lv1 vg0 -wi-ao--- 104.00m

lv2 vg0 owi-aos-- 52.00m

lv2-sn vg0 swi-a-s-- 12.00m lv2 0.10 

2,  统计访问apache服务的每个客户端及其访问次数(前10名)

  cut -d" " -f1 /var/log/httpd/access_log | sort | uniq -c | sort -nr | head -10

3,  使用lsof查看某个端口的占用情况

  lsof -i:80

4,  在每行的下一行输出一个空行

sed 'G' num.txt

在每行的下一行输出一个空白行

sed '/$/a \ ' num.txt

每行下面输出一个空行,最后一行下面不输出

sed '$!G' num.txt

5,仅打印httpd的进程号

# ps -ef | grep httpd | awk '{print $2}'

# ps -ef | awk '/httpd/{print $2}'

# pgrep httpd

 6,打印100以内能够被7整除,及包含7的数 (面试题)
[root@shell shelldoc]# seq 100 | awk '$1%7==0 || $1 ~ /7/'

[root@shell shelldoc]# seq 100 | awk '$1%7==0 || /7/'

[root@shell shelldoc]# seq 100 | awk '$0%7==0 || $0 ~ /7/'

[root@shell shelldoc]# seq 100 | awk '$0%7==0 || /7/'

7,对一个已经存在的表,如何添加主键?如何删除主键?

添加主键:

alter table score add primary key(sno);

删除主键

alter table score drop primary key;  

8,非交互式执行sql语句 

-e

[root@mysql ~]# mysql -uroot -predhat -e "show processlist"

[root@mysql ~]# mysql -uroot -predhat -e "create database up11;use up11;create table douniwan (id int)"

[root@mysql ~]# mysql -uroot -predhat -e "use up11;show tables"
生成数据库列表文件

[root@mysql ~]# mysql -uroot -predhat -e "show databases" | grep -v Data > /tmp/db_list

9,面试题:常见的HTTP状态码

200 (成功)服务器已成功处理了请求 OK

301 代表永久性转移(Permanently Moved)。

302 代表暂时性转移(Temporarily Moved )。

404 服务器找不到请求的网页(NOT FOUND)

403 服务器拒绝请求(Forbidden)

500 (服务器内部错误)服务器遇到错误,无法完成请求。

502 (错误网关)服务器作为网关或代理,从上游服务器收到无效响应。

504 (网关超时)服务器作为网关或代理,但是没有及时从上游服务器收到请求   

10,进程和线程的区别

 进程独享资源,线程是共享资源 

11,,用iptables添加一条规则允许192.168.0.123访问本机的3306端口。

  iptables -A INPUT -s 192.168.0.123 -p tcp --dport 3306 -j ACCEPT

12,如何将本地80端口的请求转发到8080端口,当前主机IP为192.168.2.1

  iptables -t nat -A PREROUTING -d 192.168.2.1 -p tcp --dport 80 -j DNAT --to-destination 192.168.2.1:8080

13, linux中查看硬件的日志信息的命令

dmesg

14,清除DNS缓存

1、Linux机器

[root@forward ~]# rndc flush

2、windows机器

C:\Documents and Settings\Administrator>ipconfig /displaydns //查看缓存

C:\Documents and Settings\Administrator>ipconfig /flushdns

15,写出以下硬件的速度由快到慢的顺序

cpu > 内存 > 本地硬盘 > 光驱  

16,  硬件raid是在操作系统不存在的情况下创建的,那么级别是在哪设定的?

在BIOS中设定的        

 17,查找系统中拥有suid权限的文件

find / -perm -4000 

 18,如果你不小心执行了chmod -x /bin/chmod

方法一:重新安装。 yum reinstall /bin/chmod -y

方法二:

[root@server200 base]# chmod -x /bin/chmod

[root@server200 base]# ll /bin/chmod

-rw-r--r-- 1 root root 48712 Apr 17 2012 /bin/chmod

[root@server200 base]# setfacl -m u:root:rx /bin/chmod

[root@server200 base]# chmod +x /bin/chmod

[root@server200 base]# setfacl -b /bin/chmod

19,那么如何让一个命令或者程序执行脱离终端? 

 [root@server200 ~]# nohup firefox 172.16.0.1 &

[root@server200 ~]# nohup: ignoring input and appending output to `nohup.out' //正常现象,按回车。

[root@server200 ~]# ls nohup.out

nohup.out

20,  对于一个已经运行的进程,如何将其放置于后台?

[root@server200 ~]# firefox 172.16.0.1 //按下ctrl + z,将进程放置于后台,但是进程是停止的状态

^Z

[2]+ Stopped firefox 172.16.0.1

[root@server200 ~]# bg 2 //激活后台进程 background:后台

[2]+ firefox 172.16.0.1 &

[root@server200 ~]# jobs //查看后台进程的

[2]+ Running firefox 172.16.0.1 &

bg 任务编号:激活后台进程

fg 任务编号:将后台运行的进程调到前台来运行 foreground:前台

[root@server200 ~]# fg 2

firefox 172.16.0.2

21,假设你是root,如何不提示删除目录?(写出三种方法)

1)rm -rf

2)\rm -r

3)  /bin/rm -r 使用命令的绝对路径删除

22,  假设我们公司有5个部门,每个部门有25人,至少需要有几位主机位?

  2^x-2>=25 (x代表主机位位数)
x>=5

23,  TCP和UDP区别

tcp
udp

是否连接 面向连接
面向非连接

传输可靠性 可靠
不可靠

应用场合 传输大量的数据
少量数据

速度 慢
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  面试题