28 typical O & M questions on April 9, 2017 !, 2017

Source: Internet
Author: User
Tags ftp protocol

28 typical O & M questions on April 9, 2017 !, 2017




1. in Linux, how does one Mount shared directories in windows?

Mount. cifs // ip address/server/mnt/server-o user = administrator, password = 123456
For linux server, you need to manually create a user and pass following the password of the windows host. Note the space and comma.


2. How do I view the number of concurrent http requests and their TCP connection status?

Netstat-n | awk '/^ tcp/{+ B [$ NF]}' END {for (a in B) print a, B [a]}'

There is also ulimit-n to view the maximum file descriptor opened in linux. The default value is 1024. It is useless to modify the web server without modifying it. If you want to use it, you can modify several methods. Here we will describe one of them:
Modify/etc/security/limits. conf
* Soft nofile 10240
* Hard nofile 10240
Effective after restart


3. How can I use tcpdump to sniff port 80 for the highest access?

Tcpdump-I eth0-tnn dst port 80-c 1000 | awk-F ". '{print $1 ″. "$2 ″. "$3 ″. "$4 ″. '}' | sort | uniq-c | sort-nr | head-5


4. How do I view the number of files in the/var/log directory?

Ls/var/log/-1R | grep "-" | wc-l


5. How do I view the number of connections of each ip address in Linux?

Netstat-n | awk '/^ tcp/{print $5}' | awk-F: '{print $1}' | sort | uniq-c | sort-rn


6. Generate a 32-bit random password in shell

Cat/dev/urandom | head-1 | md5sum | head-c 32>/pass


7. Calculate the five most visited ip addresses in apache access. log.

Cat access. log | awk '{print $1}' | sort | uniq-c | sort-n-r | head-5


8. How to view the binary file content?

We generally use the hexdump command to view the binary file content.
Hexdump-c xxx (File Name)-C is a parameter with different meanings
-C is a standard hexadecimal and ASCII code display.
-C: single-byte character display
-B single-byte octal display
-O is double-byte octal display
-D is double-byte decimal display
-X indicates the dual-byte hexadecimal display.


9. What does VSZ in ps aux mean? What does RSS mean?

VSZ: Virtual Memory set, virtual memory space occupied by processes
RSS: Physical memory set. The actual physical memory space is used for process warfare.


10. How to detect and fix/dev/hda5?

Fsck is used to check and maintain inconsistent file systems. If the system power is down or the disk is faulty, use the fsck command to check the file system.


11. Introduce the boot sequence of the Linux system.

Load BIOS-> Read MBR-> Boot Loader-> load kernel-> User-layer init-inittab file to set the system running level (generally 3 or
5. 3 is the multi-user command line, 5 is the interface)-> the init process executes rc. syninit-> Start the kernel module-> execute script programs running at different levels-> execute/etc/rc. d/rc. local (local Running Service)-> execute/bin/login to log on.


12. Differences between symbolic links and hard links

We can use Symbolic Links, that is, soft connections, as shortcuts in windows.
The hard link is like copying another copy. For example:
Ln 3.txt 4.txt is a hard link, which is equivalent to copying and cannot be used across partitions. However, if you modify 3 or 4, it will be changed. If you delete 3 or 4, it will not be affected.
Ln-s 3.txt 4.txt is a soft connection, which is equivalent to a shortcut. Modifications 4 and 3 will also change. If you delete 3 and 4, it will break down. It cannot be used.


13. Save the Partition Table of the current disk partition

The dd command is a powerful command to convert data while copying data.
Dd if =/dev/sda of =./mbr.txt bs = 1 count = 512


14. How can I copy, paste, delete, delete all rows, search by row, and search by letter in text?

The following operations are performed in the command line status. Do not edit the status.
Move the row to be copied in the text and press yy to copy the row. Then press P to paste it.
Delete a row and move it to another row. Press dd.
Delete all dG. Note that G must be capitalized.
Search by row: 90. In this case, 90th rows are found.
Search by letter/path is the location where the word path is located. There may be multiple words in the text, and multiple searches will be displayed in different locations.


15. Manually install grub

Grub-install/dev/sda


16. Modify Kernel Parameters

Vi/etc/sysctl. conf modify the parameters here
Available after sysctl-p refresh


17. Obtain a random number from 1 to 39

Expr $ [RANDOM % 39] + 1
RANDOM Number
% 39 return remainder range 0-38


18. The number of new connections per second in apache is limited to 1 and the peak value is 3.

The number of new connections per second is generally implemented by the firewall. apache itself does not seem to be able to set the number of new connections per second, but can only set the maximum connection:
Iptables-a input-d 172.16.100.1-p tcp-dport 80-m limit-limit 1/second-j ACCEPT


19. Active and passive FTP Modes

The FTP protocol can work in two ways: PORT and PASV. The Chinese meaning is active and passive.


The PORT connection process is as follows:The client sends a connection request to the FTP port of the server (21 by default). The server accepts the connection and establishes a command link. When data needs to be transmitted, the client uses the PORT command on the command link to tell the server: "I opened PORT XX and you came to connect to me ". The server sends a connection request from Port 20 to port XX of the client and establishes a data link to transmit data.


The PASV (passive) connection process is: The client sends a connection request to the FTP port of the server (21 by default). The server accepts the connection and establishes a command link. When data needs to be transmitted, the server uses the PASV command on the command link to tell the client: "I opened port XX and you came to connect to me ". Therefore, the client sends a connection request to port XX of the server and establishes a data link to transmit data.


From the above, we can see that the command link connection methods of the two methods are the same, and the data link creation methods are completely different.


20. The/etc/inittab starts with "#", followed by one or more white spaces, and followed by any non-white lines.

Grep "^ # \ {1, \} [^]"/etc/inittab


21. The/etc/inittab contains the rows of a number (that is, a number between two colons ).

Grep "\: [0-9] \ {1 \}:"/etc/inittab


22. How can I add a script to the system service and call it using the service?

Add in the script
#! /Bin/bash
# Chkconfig: 345 85 15
# Description: httpd
Then save
Chkconfig httpd-add: Create a system service
Now you can use service to start or restart


23. Write a script to add 20 users in batches

Username is user01-20, password is followed by 5 random characters

#! /Bin/bash
# Description: useradd
For I in 'seq-f "% 02g" 1 20'; do
Useradd user $ I
Echo "user $ I-'echo $ RANDOM | md5sum | cut-c 1-5'" | passwd-stdinuser $ I>/dev/null 2> & 1
Done


24. Write a script to determine which IP addresses are online in the 192.168.1.0/24 network.

#! /Bin/bash
For ip in 'seq 1 255'
Do
Ping-c 1 192.168.1. $ ip>/dev/null 2> & 1
If [$? -Eq 0]; then
Echo 192.168.1. $ ip UP
Else
Echo 192.168.1. $ ip DOWN
Fi
}&
Done
Wait

25. Write a script to check whether a specified script is a syntax error.

If any error occurs, the user is reminded to press Q or q to ignore the error and exit any other key. You can use vim to open the specified script.

[Root @ localhost tmp] # cat checksh. sh
#! /Bin/bash
Read-p "please input check script->" file
If [-f $ file]; then
Sh-n $ file>/dev/null 2> & 1
If [$? -Ne 0]; then
Read-p "You input $ file syntax error, [Type q to exit or Type vim to edit]" answer
Case $ answer in
Q | Q)
Exit 0
;;
Vim)
Vim $ file
;;
*)
Exit 0
;;
Esac
Fi
Else
Echo "$ file not exist"
Exit 1
Fi

26. How to write a script:

Create a function and accept two parameters:
1) The first parameter is the URL to download the file, and the second parameter is the directory, that is, the location saved after the download;


2) If the directory provided by the user does not exist, the system prompts whether to create the directory. If the directory is created, the system continues to execute. Otherwise, the function returns an error value of 51 to the calling script;


3) if a directory exists, download the file. After the download command is executed, test whether the file is successfully downloaded. If yes, return 0 to the script. Otherwise, return 52 to the call script;

[Root @ localhost tmp] # cat downfile. sh
#! /Bin/bash
Url = $1
Dir = $2
Download ()
{
Cd $ dir>/dev/null 2> & 1
If [$? -Ne 0]; then
Read-p "$ dir No such file or directory, create? (Y/n) "answer
If ["$ answer" = "y"]; then
Mkdir-p $ dir
Cd $ dir
Wget $ url 1>/dev/null 2> & 1
Else
Return "51"
Fi
Fi
If [$? -Ne 0]; then
Return "52"
Fi
}
Download $ url $ dir
Echo $?

27. Write a script. The detailed requirements are as follows:

1. Create a function

You can take a disk device path (such as/dev/sdb) as the parameter. You are reminded of the danger before you start the next step and asked the user to choose whether to continue; then, clear all the partitions on the disk device. (The command dd if =/dev/zero of =/dev/sdb bs = 512 count = 1 is displayed, note that the device path should not be wrong;


If this step fails, 67 is returned to the main program;

Create two primary partitions on the disk device. One is 100 mb and the other is 1 GB. If this step fails, 68 is returned to the main program;


Format the two partitions. The file system type is ext3. If this step fails, 69 is returned to the main program;
If the above process is normal, return 0 to the main program;


2. Call this function

The execution status is determined by receiving the return value of the function execution and the information is displayed;

Local Darray = ('ls/dev/sd [a-z] ')
For I in $ {Darray}; do
[["$ I" = "$1"] & Sd = $ I & break
Done
Else
Return66
Fi


# When the match is successful, go to the selection page and tell the user whether to continue. If an error is entered, go to the infinite loop. When the user selects Y, clear the target partition and exit the while loop.

While:; do
Read-p "Warning !!! This operation will clean $ Sd data. Next = y, Quit = n [y | n]: "Choice
Case $ Choice in
Y)
Dd if =/dev/zero of = $ Sd bs = 512 count = 1 &>/dev/null & break | return 67 ;;
N)
Exit 88 ;;
*)
Echo "Invalid choice, please choice again .";;
Esac
Done


# Use echo to pass to fdisk for partitioning. If this command fails, it will jump out. The error value is 68. Note that sometimes the return value is very strange, the previous success or failure of the author is the return of 1. After the restart, it will be fine. If you are careful, you can judge the created partition, but you need to use other tools to intercept related fields, although it is a little troublesome

Echo-e "n \ np \ n1 \ n + 100M \ nn \ np \ n2 \ n + 1024M \ nw \ n" | fdisk/dev/sdb &> /dev/null | return 68


# Before formatting, let the kernel re-read the disk partition table. It is worth noting that in some system versions, the use of partprobe is invalid. For example, the author's environment is rhel5.8, and after rhel6.0, this command is very dangerous, and the use of partx-a/dev/sdb is better... This item requires caution. If the formatting fails, it indicates defining the failed partition as a variable, jumping out of the function, and bringing out the error value 69.

'Partprobe'
Part = 'fdisk-l/dev/$ Sd | tail-2 | cut-d "-f1'
For M in $ {Part}; do
Mke2fs-j $ M &>/dev/null & ErrorPart = $ M & return 69
Done
Return 0
}


# The following code calls a function, receives the return value of the function, and determines the Error Based on the returned value.

Disk_Mod $1
Res = $?
[$ Res-eq 0] & exit 0
[$ Res-eq 66] & echo "Error! Invalid input ."
[$ Res-eq 67] & echo "Error! Command-> dd fdisk mke2fs

28. How can I display the specific time of the history command?

HISTTIMEFORMAT = "% Y-% m-% d % H: % M: % S"
Export HISTTIMEFORMAT
It will be restored after reboot. You can write/etc/profile

From: http://www.yunweipai.com/archives/18798.html


Free Linux cloud computing courses are booming,5 days freeO & M dry goods content free of charge,Click the end of the article"Read original"Free O & M courses!Speed to grab ~~~~

PS: Check out the free gift package provided by xiaobian ~

Free | more than 1000 sets of resume templates are offered free of charge, and a resume creation tutorial is provided!

Free of charge | the "Shell script 100 cases" ebook is free of charge and must be used for O & M ~


Click 【Read original], Free to listen to five days of Linux O & M Dry Goods sharing courses, hot discussion, come to grab!

  • This article has been included in the following columns:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.