Test staff Common Linux commands

Source: Internet
Author: User
Tags bz2 local time rar cpu usage iptables

Tag:cpu   nbsp   nginx   drop    Update      Understanding     model     between    .gz   

1. Firewall 1) After reboot effective Open: Chkconfig iptables on off: chkconfig iptables off2) immediate effect, restart after failure to open: Service iptables start shutdown: Service iptable s Stop View status service iptables status2. Shut down # shutdown-h now #立刻关机 # shutdown-h ' Halt ' #2点30分关机, note the local time is the # halt-p #立刻关机 # Init 0 #立即将系统运行级别切换为0, that is, shutdown # shutdown-r now #立刻重启3. Reboot # shutdown-k now ' reboot ' #发出警告讯息, but no real shutdown. # shutdown-t10-r now #立刻重  10 seconds between warning and deletion of processes. # init 6 #立即将系统运行级别切换为6, that is, reboot # shutdown-r +10 ' reboot ' #10分钟后重启 # shutdown-c #取消之前的shutdown命令 #  Shutdown now #切换至单人操作模式 (when no options are added) 4. Modify the System time Date window Date-s ' 2017-08-01 10:10:00 ' Change month day hour minutes date-s 10:00:02 change time not change clock -W Write system time Hwclock sync BIOS Time service ntpdate start turn on network time Sync systemctl start ntpdate.service turn on network time sync Red Hat 7chkconfig--lev Es 2345 ntpdate on boot time zone: DATE-RTZSELECT5, Port 1, Lsof-i: Port number 2, netstat-tunlp|grep port number 3, Netstat-anp|grep 80 port enabled, stop 1, Open port (take port 80 as an example) method one:/sbin/iptables-i input-p tcp--dport 80-j ACCEPT write modify/etc/init.d/iptables Save save modify service Iptables re Start restart Firewall, modification effective method two: VI/ETC/SYSCOnfig/iptables Open the configuration file by adding the following statement:-a input-p tcp-m state--state new-m TCP--dport 80-j ACCEPT Restart firewall, modify completion 2, close Port method one:/sbin/ipt Ables-i input-p TCP--dport 80-j DROP write modify/etc/init.d/iptables Save save modify service iptables Restart Restart firewall, modify effective method two: vi/etc/ Sysconfig/iptables Open the configuration file by adding the following statement:-a input-p tcp-m state--state new-m TCP--dport 80-j DROP Restart Firewall, modify finish 6, view CPU, memory configuration HDD: D F-HCPU, Memory: top# #CPU型号查看: Cat/proc/cpuinfo | grep name | Cut-f2-d: | Uniq-c# #从应用程序的角度来说, available memory = System Free memory+buffers+cached. # #查看cpu是几核的, can also be shown with the command, 4 is the 4-core cat/proc/cpuinfo |grep "cores" |uniq CPU cores:4# #查看物理CPU的个数, 1 for only one physical cpucat/proc/ Cpuinfo |grep "Physical id" |sort |uniq|wc-l View video card: Lspci |grep-i Vga7, terminal garbled modified # vim/etc/sysconfig/i18n modified to: lang= "en_US. UTF-8 "sysfont=" Latarcyrheb-sun16 "9.top interface Introduction The first line: 13:42:59 the current system time 6 days, 9:29 the system has been running 6 Day 6 hours 29 minutes (during which no restart) 3 users There are currently 3 users logged in to the system load average:3.06,3.01, 1.79 load average the three number behind is 1 minutes, 5 minutes, 15 minutes of loading situation respectively. The load average data is the number of active processes that are checked every 5 seconds and then calculated by a particular algorithm. If this number is divided by the number of logical CPUs, the result above 5 indicates that the system is overloaded. Second line: Tasks Task (process), the system now has a total of 131 processes, of which there are 3 in the running, 127 in hibernation (sleep), 0 in the stoped state, and 1 in the Zombie State (zombie). Third line: CPU status 10.6% US user space as a percentage of CPU usage. 2.2% Sy Core Space consumes a percentage of the CPU. 0.0% NI changed the priority of the process to occupy the percentage of CPU 84.5% ID idle CPU percentage 2.5% wa io wait cpu percentage 0.1% hi hard Interrupt (Hardware IRQ)% of CPU 0.0% si soft interrupt (software Int errupts) Percentage of CPU used here the CPU usage ratio and the Windows concept are different, if you do not understand the user space and kernel space, need to recharge. Row four: Memory status 8300124k Total physical memory (8GB) total amount of memory (5.7GB) 2320648k free memory Total (2.2G) 455544k buffers cache amount in used (434M) line fifth: Swap swap partition 8193108k Total swap area (8GB) 41568k used total swap area (40.6M) 8151540k free Swap area total (8GB) 4217456k Cached Total buffer Swap (4GB) * * * * total memory (used) refers to the amount of memory that is now controlled by the system kernel, and the total amount of free memory that the kernel has not included in its control range. The memory that is included in kernel management is not always in use, but also includes the memory that has been used in the past that can now be reused, and the kernel does not return these reusable memory to free, so there is less memory on Linux, but don't worry about it. Approximate calculation formula for available memory: line Fourth of free + fourth row of buffers + fifth line of cached, press this formula available memory for this server: 2320648+455544 +4217456 = 6.6GB. In top we have to monitor the used of the fifth swap partition at all times, and if this value is constantly changing, it means that the kernel is constantly swapping memory and swap data, which is really not enough memory. Line seventh below: status monitoring of each process (Task) PID process Iduser Process owner PR process priority NI nice value. A negative value represents a high priority, and a positive value represents the total amount of virtual memory used by the low-priority virt process, in kilobytes. Virt=swap+resres processThe amount of physical memory that is used, not swapped out, in kilobytes. RES=CODE+DATASHR Shared memory size, unit KBS process state. d= non-disruptive sleep state r= run s= sleep t= track/stop z= zombie process%cpu on +--update to current CPU time consumption percent%mem the percentage of physical memory used by the process time+ the total CPU time used by the process, Unit 1/100 SEC command Process name (command name/command line) ******************** Multi-core CPU monitor **************************************************** in the top basic view, press the keypad number 1 , you can monitor the status of each logical CPU: By default, when top is reached, each process is sorted by CPU consumption, and the MYSQLD process with process ID 3527 in "Top View 01" is ranked first (CPU occupied 2%). The Java process with process ID 26955 is ranked second (CPU occupied 1%). You can change the sort field by keyboard instruction, for example, to monitor which process consumes mem most, I use the following method as follows: 1. Tap Keyboard B (turn on/off highlighting), the top view changes as follows: We found that the process ID 20517 of the top process is highlighted, generally running state (runing) process is highlighted, you can hit the Y key to turn off or turn on the highlight effect of the running process. 2. Tap keyboard x (Highlight effect on/off column), the top view changes as follows: You can see that the default sort column for top is%CPU.  3. Through SHIFT + > or SHIFT +<You can change the sequence of rows to the right or left, by pressing shift once+ >: The view is now sorted according to%mem. Change process display Field 1. Hit the F key and top into another view, where you can orchestrate the display fields in the base view: Here are all the process fields available in the top basic view, with * and the fields marked as uppercase are visible, fields without * and lowercase letters are not displayed. If you want to display the code and data two fields in the base view, you can tap the R and S keys: 2. Return to the basic view, you can see the code and data two fields: The top command of the Supplemental Top command for system monitoring on Linux is the preferred command, but sometimes do not meet our requirements, the top command of the minimum Monitoring Unit is the process, so you do not see the number of threads of the program and the number of customer connections, It is usually possible to add PS and netstate two commands to complement the top shortage. Number of monitoring Java threads: ps-elf | grep java | Wc-l Monitoring network client connections: netstat-n | grep TCP | grep Listening Port | Wc-l the above two commands, can change the parameters of grep, to achieve more detailed monitoring requirements. In the Linux system everything is the idea of the implementation of the guidance, all processes running state can be used to obtain files. system root/proc, each digital subdirectory name is the PID of the running process, into any process directory, through which files or directories to observe the process of the various operational indicators, such as the task directory is used to describe the thread of the process, Therefore, you can also get the number of threads running in a process by using the following method (PID refers to the process ID): Ls/proc/pid/task | Wc-l also has a command pmap in Linux to output the state of the process memory, which can be used to analyze the thread stack: Pmap pid%cpu= (CPU time in the lifetime of the process) *100/(the length of time represented by the process's life cycle) For example, the life cycle of a process is 1000s, and then the CPU time in this 1000s is 500s, then%cpu=500*100/1000=50 that the final result represents 50%10. Modify the IP address vim/etc/sysconfig/ Network-scripts/ifcfg-eth0service network restart11. Process Management Check Process PS command to find the PID number associated with the process: PS A shows all the programs under the current terminal, including the other user's programs. Ps-a Show All Programs. PS C shows the actual instruction name of each program when the program is listed, not including the path, parameter, or indication of the resident service. Ps-e the effect of this parameter and specifying the "A" parameterSame. When you list a program, PS e displays the environment variables that are used by each program. PS F Displays the tree structure with ASCII characters and expresses the relationship between the programs. PS-H displays a tree structure that represents the inter-program relationship. Ps-n shows all the programs except the ones that perform the PS command terminal. PS s uses program signal format to display program status. PS S lists programs, including interrupted sub-program data. Ps-t<Terminal number> Specify the terminal number and list the status of the program that belongs to the terminal. PS U Displays the status of the program in a user-oriented format. PS x shows all the programs, not the terminal to distinguish. The most common method is PS aux, which is then filtered by the grep command to find a particular process and then operate on a particular process. PS aux | grep program_filter_word,ps-ef |grep tomcatps-ef|grep java|grep-v grep shows all the Java processes and places the current grep process away. Kill the process using the KILL command to end the process: Kill XXX Common: kill-9 324Linux also provides a killall command, you can directly use the name of the process instead of the process identification number, for example: # killall-9 name enters the path to the execution file of the process , execute the file./File name 12. Apache Restart on CentOS, MySQL restart, nginx restart Method 1. Restart Apache service httpd restart/etc/init.d/httpd stop/etc/init.d/httpd start 2. Restart MySQL service MySQL restart/etc/init.d/mysqld stop/etc/init.d/mysqld start 3. Restart Nginx service Nginx restart/etc  /init.d/nginx Stop/etc/init.d/nginx start13. View Linux version: Lsb_release-a cat/etc/issue uname-a number of digits: getconf long_bit file /bin/ls14. Linux network card Monitoring watch more/proc/net/dev15. Packaging and Compression (note: Many of the compressors in Linux can only be compressed for one file) 01-.tar format unpacking: [*******]$ tar XVF Filename.tar Packaging: [*******]$ tar cvf filename.tar DirName (Note: Tar is packaged, not compressed!) ) 02-.gz format decompression 1:[*******]$ gunzip filename.gz decompression 2:[*******]$ gzip-d filename.gz compression: [*******]$Gzip filename03-.tar.gz format decompression: [*******]$ tar zxvf FileName.tar.gz compression: [*******]$ tar zcvf FileName.tar.gz DIRNAME04-.BZ2 format Decompression 1:[*******]$ bzip2-d filename.bz2 decompression 2:[*******]$ bunzip2 filename.bz2 compression: [*******]$ bzip2-z FILENAME05-.TAR.BZ2 format decompression: [*******]$ tar jxvf FileName.tar.bz2 compression: [*******]$ tar jcvf FileName.tar.bz2 DIRNAME06-.BZ format Decompression 1:[*******]$ bzip2-d filename.bz decompression 2:[*******]$ bunzip2 filename.bz./bin/pika-c conf/ PIKA.CONF07-.TAR.BZ format decompression: [*******]$ tar jxvf filename.tar.bz08-.z format decompression: [*******]$ uncompress filename.z compression: [*******]$ Compress filename09-.tar.z Format decompression: [*******]$ tar zxvf filename.tar.z compression: [*******]$ tar zcvf filename.tar.z DIRNAME10-.TGZ format decompression: [*******]$ tar zxvf filename.tgz11-.tar.tgz format decompression: [*******]$ tar zxvf FileName.tar.tgz compression: [*******]$ Tar zcvf FileName.tar.tgz filename12-.zip format decompression: [*******]$ unzip filename.zip compression: [*******]$ zip Filename.zip Dirname13-.lha format decompression: [*******]$ lha-e Filename.lha compression: [*******]$ lha-a Filename.lha filename14-.rar format decompression: [*******]$ rar A Filename.rar compression: [*******]$ rar e filename.rar16. View the path of the process cd/proc/29565 ll 

Test staff Common Linux commands

Related Article

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.