某金融公司面试题

                              某金融公司面试题   

                                                          作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

                                                                                                    

 

1.Linux怎么查看用户登录日志

 1 #我们知道/var/log/wtmp日志文件记录用户登录的数据。但这个文件是被编码的文件,不能直接用vi、cat等命令查看,可以用last命令读取。每一次登录就会产生一条记录,包括用户名、登录端、时间跨度等信息,如下:
 2 [root@yinzhengjie ~]# last
 3 root     pts/0        172.30.1.2       Mon Feb 27 09:17   still logged in   
 4 root     pts/0        172.30.1.2       Fri Feb 24 14:39 - 18:21  (03:41)    
 5 root     pts/0        172.30.1.2       Thu Feb 16 11:16 - 13:01  (01:44)    
 6 root     pts/1        172.30.1.21      Thu Feb 16 10:59 - 16:32  (05:32)    
 7 root     pts/0        172.30.1.2       Wed Feb 15 11:07 - 11:10 (1+00:03)   
 8 root     pts/1        172.30.1.2       Wed Feb 15 11:02 - 11:02  (00:00)    
 9 root     pts/0        172.30.1.2       Wed Feb 15 10:54 - 11:02  (00:08)    
10 root     pts/0        172.30.1.2       Thu Feb  9 18:22 - 16:47 (4+22:25)   
11 root     pts/0        172.30.1.2       Thu Feb  9 18:17 - 18:22  (00:04)    
12 root     pts/0        172.30.1.2       Thu Feb  9 18:16 - 18:17  (00:00)    
13 root     pts/0        172.30.1.2       Thu Feb  9 18:12 - 18:16  (00:03)    
14 root     pts/0        172.30.1.2       Thu Feb  9 15:59 - 16:08  (00:09)    
15 root     pts/0        172.30.1.2       Fri Feb  3 09:01 - 18:02 (1+09:00)   
16 root     pts/0        172.30.1.21      Sun Jan 22 17:57 - 18:01  (00:04)    
17 root     pts/0        172.30.1.21      Sun Jan 22 17:56 - 17:56  (00:00)    
18 root     pts/0        172.30.1.2       Tue Jan 17 17:19 - 14:45 (2+21:25)   
19 root     pts/0        172.30.1.2       Fri Jan 13 16:09 - 18:43  (02:33)    
20 root     pts/1        172.30.1.2       Tue Jan 10 13:07 - 08:59 (2+19:52)   
21 root     pts/0        172.30.1.2       Mon Jan  9 17:48 - 08:59 (3+15:10)   
22 root     pts/1        172.30.1.2       Fri Jan  6 18:17 - 18:23 (2+00:05)   
23 root     pts/0        172.30.1.2       Fri Jan  6 17:37 - 18:23 (2+00:45)   
24 root     pts/1        172.30.1.2       Thu Dec 29 13:42 - 18:20 (1+04:37)   
25 root     pts/1        172.30.1.2       Tue Dec 27 11:55 - 20:42  (08:47)    
26 root     pts/0        172.30.1.2       Tue Dec 27 11:53 - 18:20 (3+06:26)   
27 root     pts/2        172.30.1.2       Thu Dec 22 15:56 - 19:13  (03:16)    
28 root     pts/1        172.30.1.2       Thu Dec 22 14:37 - 16:48  (02:11)    
29 root     pts/0        172.30.1.2       Thu Dec 22 14:10 - 16:48  (02:37)    
30 root     pts/2        172.30.1.2       Thu Dec 22 11:54 - 12:23  (00:28)    
31 root     pts/2        192.168.1.182    Wed Dec 21 12:31 - 12:31  (00:00)    
32 root     pts/1        172.30.1.2       Wed Dec 21 09:28 - 12:17 (1+02:48)   
33 root     pts/0        172.30.1.2       Wed Dec 21 08:53 - 12:17 (1+03:24)   
34 root     pts/1        172.30.1.222     Tue Dec 20 16:21 - 19:58  (03:36)    
35 root     pts/0        172.30.1.222     Tue Dec 20 10:05 - 19:58  (09:53)    
36 reboot   system boot  2.6.32-358.el6.x Tue Dec 20 09:49 - 09:22 (68+23:33)  
37 root     pts/2        172.30.1.2       Tue Dec 20 09:44 - down   (00:02)    
38 root     pts/2        172.30.1.2       Tue Dec 20 09:25 - 09:44  (00:18)    
39 root     pts/1        172.30.1.2       Mon Dec 19 09:07 - down  (1+00:38)   
40 root     pts/1        192.168.100.100  Sun Dec 18 10:56 - 11:16  (00:20)    
41 root     pts/4        172.30.1.2       Fri Dec 16 15:48 - 02:11 (1+10:22)   
42 root     pts/3        172.30.1.2       Fri Dec 16 15:48 - 02:11 (1+10:23)   
43 root     pts/2        172.30.1.2       Fri Dec 16 10:56 - 02:11 (1+15:14)   
44 root     pts/2        172.30.1.2       Wed Dec 14 15:35 - 10:56 (1+19:21)   
45 root     pts/1        172.30.1.2       Wed Dec 14 15:08 - 02:11 (3+11:03)   
46 root     pts/0        :0.0             Wed Dec 14 15:03 - down  (5+18:42)   
47 root     pts/0        :0.0             Wed Dec 14 14:59 - 15:01  (00:01)    
48 root     tty1         :0               Wed Dec 14 14:55 - down  (5+18:50)   
49 reboot   system boot  2.6.32-358.el6.x Wed Dec 14 14:50 - 09:46 (5+18:56)   
50 reboot   system boot  2.6.32-358.el6.x Wed Dec 14 14:46 - 14:47  (00:00)    
51 reboot   system boot  2.6.32-358.el6.x Wed Dec 14 14:36 - 14:47  (00:11)    
52 
53 wtmp begins Wed Dec 14 14:36:12 2016
54 [root@yinzhengjie ~]# 
55 
56 #而/var/log/lastlog日志文件记录了每个用户最近的登录时间 。每个用户只有一条记录,如:
57 [root@yinzhengjie ~]# lastlog 
58 用户名           端口     来自             最后登陆时间
59 root             pts/0    172.30.1.2       一 2月 27 09:17:23 +0800 2017
60 bin                                        **从未登录过**
61 daemon                                     **从未登录过**
62 adm                                        **从未登录过**
63 lp                                         **从未登录过**
64 sync                                       **从未登录过**
65 shutdown                                   **从未登录过**
66 halt                                       **从未登录过**
67 mail                                       **从未登录过**
68 uucp                                       **从未登录过**
69 operator                                   **从未登录过**
70 games                                      **从未登录过**
71 gopher                                     **从未登录过**
72 ftp                                        **从未登录过**
73 nobody                                     **从未登录过**
74 dbus                                       **从未登录过**
75 usbmuxd                                    **从未登录过**
76 vcsa                                       **从未登录过**
77 rpc                                        **从未登录过**
78 rtkit                                      **从未登录过**
79 avahi-autoipd                              **从未登录过**
80 abrt                                       **从未登录过**
81 rpcuser                                    **从未登录过**
82 nfsnobody                                  **从未登录过**
83 haldaemon                                  **从未登录过**
84 gdm                                        **从未登录过**
85 ntp                                        **从未登录过**
86 apache                                     **从未登录过**
87 saslauth                                   **从未登录过**
88 postfix                                    **从未登录过**
89 pulse                                      **从未登录过**
90 sshd                                       **从未登录过**
91 tcpdump                                    **从未登录过**
92 nginx                                      **从未登录过**
93 mysql                                      **从未登录过**
94 zabbix                                     **从未登录过**
95 xinxin                                     **从未登录过**
96 [root@yinzhengjie ~]# 
last与lastlog

 

2.Linux中lastlog,messages,wtmp,utmp各文件中的作用

 1 1>.最后一次登录文件可以用lastlog命令察看;
 2 [root@yinzhengjie ~]# lastlog
 3 用户名           端口     来自             最后登陆时间
 4 root             pts/1    172.30.1.2       一 2月 27 09:28:12 +0800 2017
 5 bin                                        **从未登录过**
 6 daemon                                     **从未登录过**
 7 adm                                        **从未登录过**
 8 lp                                         **从未登录过**
 9 sync                                       **从未登录过**
10 shutdown                                   **从未登录过**
11 halt                                       **从未登录过**
12 mail                                       **从未登录过**
13 uucp                                       **从未登录过**
14 operator                                   **从未登录过**
15 games                                      **从未登录过**
16 gopher                                     **从未登录过**
17 ftp                                        **从未登录过**
18 nobody                                     **从未登录过**
19 dbus                                       **从未登录过**
20 usbmuxd                                    **从未登录过**
21 vcsa                                       **从未登录过**
22 rpc                                        **从未登录过**
23 rtkit                                      **从未登录过**
24 avahi-autoipd                              **从未登录过**
25 abrt                                       **从未登录过**
26 rpcuser                                    **从未登录过**
27 nfsnobody                                  **从未登录过**
28 haldaemon                                  **从未登录过**
29 gdm                                        **从未登录过**
30 ntp                                        **从未登录过**
31 apache                                     **从未登录过**
32 saslauth                                   **从未登录过**
33 postfix                                    **从未登录过**
34 pulse                                      **从未登录过**
35 sshd                                       **从未登录过**
36 tcpdump                                    **从未登录过**
37 nginx                                      **从未登录过**
38 mysql                                      **从未登录过**
39 zabbix                                     **从未登录过**
40 xinxin                                     **从未登录过**
41 [root@yinzhengjie ~]# 
42 
43 2>.messages是从syslog(系统日志)中记录信息
44 
45 [root@yinzhengjie ~]# tail -10f /var/log/messages
46 Feb 26 18:21:01 bogon NetworkManager[1609]: <info>   gateway 192.168.1.1
47 Feb 26 18:21:01 bogon NetworkManager[1609]: <info>   nameserver '192.168.1.1'
48 Feb 27 05:38:56 bogon dhclient[1674]: DHCPREQUEST on em1 to 192.168.1.1 port 67 (xid=0x2fbb65f6)
49 Feb 27 05:38:56 bogon dhclient[1674]: DHCPACK from 192.168.1.1 (xid=0x2fbb65f6)
50 Feb 27 05:38:56 bogon dhclient[1674]: bound to 192.168.2.45 -- renewal in 36537 seconds.
51 Feb 27 05:38:56 bogon NetworkManager[1609]: <info> (em1): DHCPv4 state changed renew -> renew
52 Feb 27 05:38:56 bogon NetworkManager[1609]: <info>   address 192.168.2.45
53 Feb 27 05:38:56 bogon NetworkManager[1609]: <info>   prefix 16 (255.255.0.0)
54 Feb 27 05:38:56 bogon NetworkManager[1609]: <info>   gateway 192.168.1.1
55 Feb 27 05:38:56 bogon NetworkManager[1609]: <info>   nameserver '192.168.1.1'
56 
57 3>.登录进入和退出纪录在文件wtmp中,用w命令调用(注意:wtmp和utmp文件都是二进制文件,他们不能被诸如tail命令剪贴或合并(使用cat命令)。用户需要使用who、w、users、last和ac来使用这两个文件包含的信息。)
58 [root@yinzhengjie ~]# w
59  09:34:22 up 68 days, 23:46,  2 users,  load average: 0.99, 1.22, 1.14
60 USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
61 root     pts/0    172.30.1.2       09:17    6:37   0.13s  0.13s -bash
62 root     pts/1    172.30.1.2       09:28    0.00s  0.06s  0.00s w
63 [root@yinzhengjie ~]# 
64 
65 4.有关当前登录用户的信息记录在文件utmp中,who命令来调用。
66 [root@yinzhengjie ~]# who
67 root     pts/0        2017-02-27 09:17 (172.30.1.2)
68 root     pts/1        2017-02-27 09:28 (172.30.1.2)
69 [root@yinzhengjie ~]# 
70 
71 
72 #扩展:
73       last命令往回搜索wtmp来显示自从文件第一次创建以来登录过的用户
74   users用单独的一行打印出当前登录的用户,每个显示的用户名对应一个登录会话
75   w命令查询utmp文件并显示当前系统中每个用户和它所运行的进程信息
76   who命令查询utmp文件并报告当前登录的每个用户
77   ac命令根据当前的/var/log/wtmp文件中的登录进入和退出来报告用户连结的时间(小时)
78   utmp文件,它记录当前登录进系统的各个用户;
调用方法展示

 

3.列举你熟悉的服务器性能查看命令

  1 #1>.free –m  查看内存使用情况
  2 [root@yinzhengjie ~]# free -m
  3              total       used       free     shared    buffers     cached
  4 Mem:          7855       7706        149          0        149       6352
  5 -/+ buffers/cache:       1203       6651
  6 Swap:         7983         57       7926
  7 [root@yinzhengjie ~]# 
  8 '''
  9 这个命令比较简单,-m 代表下面的是以M为单位,Mem是表示物理内存,主要看 Mem free代表还有多少内存可以
 10 说一下第二行的 -/+ buffers/cache:
 11 used = 第一行的used - buffers - cached (表示实际使用的内存总数)
 12 free = 第一行的free + buffers + cached (表示实际剩余的内存总数)
 13 所以一般查看内存还剩余多少查看第二行的free参数
 14 '''
 15 #2>.iostat是查看系统IO情况的命令
 16 
 17 [root@yinzhengjie ~]# iostat 
 18 Linux 2.6.32-358.el6.x86_64 (yinzhengjie)       2017年02月27日  _x86_64_        (4 CPU)
 19 
 20 avg-cpu:  %user   %nice %system %iowait  %steal   %idle
 21            2.67    0.00    0.68    7.79    0.00   88.86
 22 
 23 Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
 24 sda              64.94         1.20      2341.79    7140718 13960973732
 25 dm-0            292.75         1.19      2341.77    7094986 13960850376
 26 dm-1              0.00         0.00         0.02      19872     122184
 27 dm-2              0.00         0.00         0.00       2458       1088
 28 
 29 [root@yinzhengjie ~]# 
 30 
 31 ‘’‘
 32 % user显示了在用户级(应用程序)执行时产生的 CPU 使用率百分比。
 33 % system显示了在系统级(内核)执行时产生的 CPU 使用率百分比。
 34 % idle显示了在 CPU 空闲并且系统没有未完成的磁盘 I/O 请求时的时间百分比。
 35 
 36 % iowait显示了 CPU 空闲期间系统有未完成的磁盘 I/O 请求时的时间百分比。
 37 
 38 %nicenice操作(改变进程优先序列操作)操作使用的CPU百分比
 39 
 40 %steal管理程序维护另一个虚拟处理器时候,虚拟CPU的无意识等待时间百分比
 41 
 42  干货分享:
 43 1 iowait,如果iowait较高,表示硬盘操作存在IO瓶颈
 44 2 idle, 如果高,说明CPU较空闲,如果持续低于10的话,说明CPU处理能力低,此时存在CPU瓶颈
 45 更多信息请参考:http://wenku.baidu.com/view/404bcac48bd63186bcebbc95.html
 46 ’‘’
 47 
 48 #3>.sar是查看操作系统的资源使用情况,CPU,内存,IO等都会在这个命令中得到体现,用法:sar [参数] [间隔次数] [统计次数]
 49 [root@yinzhengjie ~]# sar -A 1 3 | less   (代表列出所有统计项目,每1s统计一次,共统计3次并且分页显示)
 50 Linux 2.6.32-358.el6.x86_64 (yinzhengjie)       2017年02月27日  _x86_64_        (4 CPU)
 51 
 52 09时59分25秒     CPU      %usr     %nice      %sys   %iowait    %steal      %irq     %soft    %guest     %idle
 53 09时59分26秒     all      1.51      0.00      0.76     12.34      0.00      0.00      0.00      0.00     85.39
 54 09时59分26秒       0      3.03      0.00      1.01     29.29      0.00      0.00      0.00      0.00     66.67
 55 09时59分26秒       1      4.08      0.00      1.02     20.41      0.00      0.00      0.00      0.00     74.49
 56 09时59分26秒       2      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00    100.00
 57 09时59分26秒       3      0.00      0.00      1.98      0.00      0.00      0.00      0.00      0.00     98.02
 58 
 59 09时59分25秒    proc/s   cswch/s
 60 09时59分26秒      0.00   2853.54
 61 
 62 09时59分25秒      INTR    intr/s
 63 09时59分26秒       sum    792.93
 64 09时59分26秒         0      0.00
 65 09时59分26秒         1      0.00
 66 09时59分26秒         2      0.00
 67 09时59分26秒         3      0.00
 68 09时59分26秒         4      0.00
 69 09时59分26秒         5      0.00
 70 09时59分26秒         6      0.00
 71 ‘’‘
 72 用法说明:
 73 (8 CPU)很明显,这台机子是8核的
 74 %irq CPU用于硬件交互所占用的时间百分比
 75 %soft CPU用于应用程序交互所占用的时间百分比
 76 %guest CPU用于虚拟处理器所占用的时间百分比
 77 ’‘’
 78 还有一种用法如下:
 79 await  IO请求平均需要耗费的时间
 80 svstm  IO访问设备的平均时间
 81 %util  CPU的IO访问所占用和等候的时间,如果这个时间很大的话,就说明CPU的时间都放在IO操作和等候上了。此时IO瓶颈。
 82 [root@yinzhengjie ~]# sar -d 1 2
 83 Linux 2.6.32-358.el6.x86_64 (yinzhengjie)       2017年02月27日  _x86_64_        (4 CPU)
 84 
 85 10时02分00秒       DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util
 86 10时02分01秒    dev8-0     30.00      0.00    424.00     14.13      0.46     15.00      8.03     24.10
 87 10时02分01秒  dev253-0     54.00      0.00    432.00      8.00      0.90     16.50      4.46     24.10
 88 10时02分01秒  dev253-1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
 89 10时02分01秒  dev253-2      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
 90 
 91 10时02分01秒       DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util
 92 10时02分02秒    dev8-0     41.41      0.00    896.97     21.66      0.48     11.98      8.93     36.97
 93 10时02分02秒  dev253-0    111.11      0.00    888.89      8.00      1.40     12.72      3.33     36.97
 94 10时02分02秒  dev253-1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
 95 10时02分02秒  dev253-2      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
 96 
 97 平均时间:       DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util
 98 平均时间:    dev8-0     35.68      0.00    659.30     18.48      0.47     13.25      8.55     30.50
 99 平均时间:  dev253-0     82.41      0.00    659.30      8.00      1.15     13.96      3.70     30.50
100 平均时间:  dev253-1      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
101 平均时间:  dev253-2      0.00      0.00      0.00      0.00      0.00      0.00      0.00      0.00
102 [root@yinzhengjie ~]
103 '''
104 await  IO请求平均需要耗费的时间
105 svstm  IO访问设备的平均时间
106 %util  CPU的IO访问所占用和等候的时间,如果这个时间很大的话,就说明CPU的时间都放在IO操作和等候上了。此时IO瓶颈。
107 
108 sar还有更多选项可以参考:http://linux.die.net/man/1/sar
109 '''
110 
111 #4>.netstat连接数说明
112 [root@yinzhengjie ~]# netstat -untalp | less
113 Active Internet connections (servers and established)
114 Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
115 tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1509/rpcbind        
116 tcp        0      0 0.0.0.0:8051                0.0.0.0:*                   LISTEN      1954/nginx          
117 tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      10283/vsftpd        
118 tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1843/sshd           
119 tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1693/cupsd          
120 tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1923/master         
121 tcp        0      0 192.168.2.45:666            0.0.0.0:*                   LISTEN      23587/rsync         
122 tcp        0      0 0.0.0.0:10051               0.0.0.0:*                   LISTEN      18101/zabbix_server 
123 tcp        0      0 0.0.0.0:60452               0.0.0.0:*                   LISTEN      1628/rpc.statd      
124 tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      2355/php-fpm        
125 tcp        0      0 0.0.0.0:6666                0.0.0.0:*                   LISTEN      18054/mysqld        
126 tcp        0      0 192.168.2.45:55162          192.168.3.8:10050           TIME_WAIT   -                   
127 :
128 '''
129 用法说明:(这里就说几个常看的)
130 Local Address是本地端口
131 Foreign Address是连接到外部的IP和端口
132 state是这个socket的状态
133 Recv-Q和Send-Q表示端口的吞吐量
134 '''
135 比如,我们可以看nginx目前有多少个连接数,可以这么玩
136 [root@yinzhengjie ~]# netstat -untalp  | grep nginx
137 tcp        0      0 0.0.0.0:8051                0.0.0.0:*                   LISTEN      1954/nginx          
138 tcp        0      0 192.168.2.45:8051           172.30.1.2:54345            ESTABLISHED 30063/nginx         
139 tcp        0      0 192.168.2.45:8051           172.30.1.2:54256            ESTABLISHED 30063/nginx         
140 [root@yinzhengjie ~]# netstat -untalp  | grep nginx | wc -l
141 3
142 [root@yinzhengjie ~]# 
143 更多方法请参考man帮助:http://linux.die.net/man/8/netstat
查看linux服务器性能的方法

 

4.Linux服务器怎么实现无密码登陆,列举操作步骤

 具体操作请参考我的另外一篇博客:http://www.cnblogs.com/yinzhengjie/p/6473094.html

 

5.使用tcpdump嗅探80端口的访问看看谁的最高.

 

 1 #在同一台服务器上运行以下命令:(抓取80端口的数据进行测试,去重并降序排列打印排名前5的.)
 2 [root@yinzhengjie ~]# tcpdump  -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print  $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr  |head -5
 3 
 4 #与此同时,开始用appche自带的ab压力测试工具进行压力测试
 5 [root@yinzhengjie ~]# ab -n 5000 -c 200 http://localhost/index.php
 6 This is ApacheBench, Version 2.3 <$Revision: 655654 $>
 7 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
 8 Licensed to The Apache Software Foundation, http://www.apache.org/
 9 
10 Benchmarking localhost (be patient)
11 Completed 500 requests
12 Completed 1000 requests
13 Completed 1500 requests
14 Completed 2000 requests
15 Completed 2500 requests
16 Completed 3000 requests
17 Completed 3500 requests
18 Completed 4000 requests
19 Completed 4500 requests
20 Completed 5000 requests
21 Finished 5000 requests
22 
23 
24 Server Software:        Apache/2.2.15
25 Server Hostname:        localhost
26 Server Port:            80
27 
28 Document Path:          /index.php
29 Document Length:        282 bytes
30 
31 Concurrency Level:      200
32 Time taken for tests:   4.764 seconds
33 Complete requests:      5000
34 Failed requests:        0
35 Write errors:           0
36 Non-2xx responses:      5006
37 Total transferred:      2312772 bytes
38 HTML transferred:       1411692 bytes
39 Requests per second:    1049.46 [#/sec] (mean)
40 Time per request:       190.574 [ms] (mean)
41 Time per request:       0.953 [ms] (mean, across all concurrent requests)
42 Transfer rate:          474.06 [Kbytes/sec] received
43 
44 Connection Times (ms)
45               min  mean[+/-sd] median   max
46 Connect:        0    1   1.3      1       8
47 Processing:     4   52 422.0     14    4753
48 Waiting:        0   51 422.0     13    4752
49 Total:          6   54 422.4     15    4759
50 
51 Percentage of the requests served within a certain time (ms)
52   50%     15
53   66%     16
54   75%     16
55   80%     16
56   90%     17
57   95%     20
58   98%     24
59   99%     26
60  100%   4759 (longest request)
61 [root@yinzhengjie ~]# 
62 
63 
64 #重复进行压力测试会有以下,抓包排名结果如下:
65 [root@yinzhengjie ~]# tcpdump  -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print  $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr  |head -20
66 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
67 listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
68 1000 packets captured
69 1000 packets received by filter
70 0 packets dropped by kernel
71    1000 IP 172.30.1.120
72 [root@yinzhengjie ~]#
73 
74 
75 #更多用法请参考:http://www.cnblogs.com/yinzhengjie/p/6382734.html
用法展示

 

6.查看当前系统每个IP的连接数

 

 1 [root@yinzhengjie ~]# netstat -n | awk '/^tcp/ {print $5}' |awk -F : '{print $1}' | sort | uniq -c | sort -rn
 2       2 192.168.2.45
 3       2 172.30.1.2
 4       1 61.213.149.41
 5 [root@yinzhengjie ~]# 
 6 
 7 '''
 8 参数说明:
 9 sort命令:进行排序,-r 反向排序 -n 使用纯数字进行排序
10 uniq 将重复的数据仅仅列出一个来显示,uniq -c,进行计数
11 awk -F: '{print $1}'  以F 为分界符,取出第一个:之前的数据
12 '''
统计当前IP连接数情况

 

7.统计出Nginx的access.log中访问量最多的5个IP

 

1 [root@yinzhengjie ~]# cat /usr/local/nginx/logs/access.log  | awk '{print $1}' |sort| uniq -c | sort -nr | head -5
2       2 192.168.100.100
3       1 172.30.1.2
4 [root@yinzhengjie ~]# 
统计IP的访问次数

 

8.怎么查看user使用了那种存储引擎,当前Mysql支持哪种存储引擎,怎么结束某个连接

 1  #1>. 查看系统支持的存储引擎
 2  mysql> show engines;
 3  +--------------------+---------+------------------------------------------------------------+--------------+------+------------+
 4  | Engine             | Support | Comment                                                    | Transactions | XA   | Savepoints |
 5  +--------------------+---------+------------------------------------------------------------+--------------+------+------------+
 6  | PERFORMANCE_SCHEMA | YES     | Performance Schema                                         | NO           | NO   | NO         |
 7  | InnoDB             | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
 8  | MyISAM             | YES     | MyISAM storage engine                                      | NO           | NO   | NO         |
 9  | MRG_MYISAM         | YES     | Collection of identical MyISAM tables                      | NO           | NO   | NO         |
10  | CSV                | YES     | CSV storage engine                                         | NO           | NO   | NO         |
11  | MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables  | NO           | NO   | NO         |
12  +--------------------+---------+------------------------------------------------------------+--------------+------+------------+
13  6 rows in set (0.00 sec)
14  
15  mysql> 
16  
17  #2>.查看表使用的存储引擎
18  方法一:[root@yinzhengjie ~]# show table status from db_name where name='table_name';
19  例如:
20  
21  mysql> show table status from zabbix where name='rights';
22  +--------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------+
23  | Name   | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time | Check_time | Collation       | Checksum | Create_options | Comment |
24  +--------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------+
25  | rights | InnoDB |      10 | Compact    |    0 |              0 |       16384 |               0 |        32768 |   8388608 |           NULL | 2016-12-14 16:01:27 | NULL        | NULL       | utf8_general_ci |     NULL |                |         |
26  +--------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-----------------+----------+----------------+---------+
27  1 row in set (0.00 sec)
28  
29  mysql> 
30  
31  方法二:
32  
33  mysql> show create table rights\g;
34  +--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
35  | Table  | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
36  +--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
37  | rights | CREATE TABLE `rights` (
38    `rightid` bigint(20) unsigned NOT NULL,
39    `groupid` bigint(20) unsigned NOT NULL,
40    `permission` int(11) NOT NULL DEFAULT '0',
41    `id` bigint(20) unsigned NOT NULL,
42    PRIMARY KEY (`rightid`),
43    KEY `rights_1` (`groupid`),
44    KEY `rights_2` (`id`),
45    CONSTRAINT `c_rights_1` FOREIGN KEY (`groupid`) REFERENCES `usrgrp` (`usrgrpid`) ON DELETE CASCADE,
46    CONSTRAINT `c_rights_2` FOREIGN KEY (`id`) REFERENCES `groups` (`groupid`) ON DELETE CASCADE
47  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
48  +--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
49  1 row in set (0.00 sec)
50  
51  ERROR: 
52  No query specified
53  
54  mysql> 
55  ‘’‘
56  补充:
57        有人说用第二种方法不准确,我试了下,关闭掉原先默认的Innodb引擎后根本无法执行show create table table_name指令,因为之前建的是Innodb表,关掉后默认用MyISAM引擎,导致Innodb表数据无法被正确读取。在这里我推荐使用方法一。
58  ’‘’
59  
60  
61  
62  '''
63  扩展:
64  
65  修改mysql的默认存储引擎
66   
67  1、查看mysql存储引擎命令,
68  在mysql>提示符下搞入show engines;
69  字段 Support为:Default表示默认存储引擎  
70    www.2cto.com  
71  2、设置InnoDB为默认引擎:
72  在配置文件my.cnf中的 [mysqld] 下面加入
73  default-storage-engine=INNODB 一句
74   
75  3、重启mysql服务器:
76  mysqladmin -u root -p shutdown
77  或者service mysqld restart 登录mysql数据库
78   
79 
80  MySQL查看和修改表的存储引擎:
81  1>.修改表引擎方法
82  alter table table_name engine=innodb;
83  2>.关闭Innodb引擎方法
84  关闭mysql服务: net stop mysql
85  找到mysql安装目录下的my.ini文件:
86  找到default-storage-engine=INNODB 改为default-storage-engine=MYISAM
87  找到#skip-innodb 改为skip-innodb
88  启动mysql服务:net start mysql
89  
90  '''
mysql存储引擎的调用方法

 

9.mysql高可用方案有哪些?mysql备份方案有哪些?有什么优缺点?

 参考一:http://xjcf00.blog.51cto.com/10170403/1640820/

参考二:http://www.jb51.net/article/83400.htm

 

10.有个“test.txt”文件的内容如下:

http://a.yinzhengjie.com/1.html

http://b.yinzhengjie.com/2.html

http://c.yinzhengjie.com/3.html

http://a.yinzhengjie.com/4.html

http://b.yinzhengjie.com/5.html

http://a.yinzhengjie.com/6.html

请写出命令行或者脚本得出以下结果:

3  a.yinzhengjie.com

2  b.yinzhengjie.com

1  c.yinzhengjie.com

 

 1 [root@yinzhengjie ~]# cat test.txt 
 2 http://a.yinzhengjie.com/1.html
 3 
 4 http://b.yinzhengjie.com/2.html
 5 
 6 http://c.yinzhengjie.com/3.html
 7 
 8 http://a.yinzhengjie.com/4.html
 9 
10 http://b.yinzhengjie.com/5.html
11 [root@yinzhengjie ~]# cat test.txt | awk -F / '{print $3}' | grep -v ^$ |sort | uniq -c | sort -rn
12       2 b.yinzhengjie.com
13       2 a.yinzhengjie.com
14       1 c.yinzhengjie.com
15 [root@yinzhengjie ~]# 
利用awk取到想要的内容

 

11.在Linux系统中,我们通常使用终端shell脚本处理一些数据,十分高效,现在有以下两个文件:

'''
file_1:
user passwd
yinzhengjie 123
zhangjie subfer212
liudehua film432
fanbingbin performer432
canglaoshi Japanese teacher
zhaoziyi lovely

file_2:
id user
001 zhaoziyi
002 yinzhengjie
003 canadian
004 march
'''

 

写一段shell脚本,输出同时存在file_1和file_2中的用户名的密码

 

 1 [root@yinzhengjie shell]# cat test.sh 
 2 #!/bin/bash
 3 while read user pass
 4     do
 5         count=`grep $user file_2|grep -v "user"|wc -l`
 6         if [[ $count -gt 0 ]];then
 7             echo "$user:$pass"
 8         fi  
 9     done < file_1
10 [root@yinzhengjie shell]# 
11 
12 #以上代码执行结果如下:
13 [root@yinzhengjie shell]# sh test.sh  
14 yinzhengjie:123
15 zhaoziyi:lovely
16 [root@yinzhengjie shell]# 
shell解法点这里

 

 1 #!/usr/bin/env python
 2 #_*_coding:utf-8_*_
 3 #@author :yinzhengjie
 4 #blog:http://www.cnblogs.com/yinzhengjie/tag/python%E8%87%AA%E5%8A%A8%E5%8C%96%E8%BF%90%E7%BB%B4%E4%B9%8B%E8%B7%AF/
 5 #EMAIL:y1053419035@qq.com
 6 f_1 = open("file_1","r",encoding="utf-8")
 7 f_2 = open("file_2","r",encoding="utf-8")
 8 for i in f_1.readlines():
 9     user = i.split()[0]
10     passwd = i.split()[1]
11     for j in f_2.readlines():
12         j = j.split()[1]
13         if user in j:
14             print(user,passwd)
15         f_2.seek(0)  #这是将文件的读取的光标指回最初点,便于下次循环又重头开始读取f_2这个文件
16 f_1.close()
17 f_2.close()
18 
19 #以上代码执行结果如下:
20 user passwd
21 yinzhengjie 123
22 zhaoziyi lovely
python解法点这里

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值