In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to use Linux system operation and maintenance tools, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
The operation and maintenance of enterprise Linux system has become the focus of enterprises at present. As an excellent open source network operating system, how to make full use of Linux tools and use corresponding methods to improve the efficiency of operation and maintenance is a very important work. This topic will introduce in detail several tools and concepts that are important to system administrators, including the operation of hard disk partitions, how to avoid problems and how to solve system problems, so as to provide useful reference for the actual operation and maintenance of enterprise Linux.
Utility 1: apply parted report and partition hard disk
The parted (Partition Editor) utility reports and manipulates hard disk partitions from the command line. The palimpsest utility uses GUI to perform the same task. In addition, the parted print command displays partition information on the / dev/sda drive:
# parted / dev/sda print Model: ATA Hitachi HDS12345 (scsi) Disk / dev/sda: 165GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 32kB 1045MB 1045MB primary ext4 boot 2 1045MB 12GB 10GB primary ext4 3 12GB 22GB 10GB primary ext4 4 22GB 165GB 143GB extended 5 22GB 23GB 1045MB logical linux-swap (v1) 6 23GB 41GB 18GB logical ext4 7 41GB 82GB 41GB logical ext4
In this example, the first few lines displayed by parted represent the model name, device name, device capacity, and partition table type on the device. After this information, the print command also displays columns that the user can follow the prompts to take action.
The Number column represents the secondary number of the device that holds the partition. This number is the same as the number of * in the device name. In this example, 5 corresponds to / dev/sda5.
The Start column indicates the location of the disk where the partition begins. The Parted utility specifies a disk location as the distance from the disk to the partition in bytes. Therefore, partition 3 starts at the location of 12 GB from the beginning of the disk.
The End column represents the disk location where the partition ends. Although partition 2 ends at 12 GB since the disk starts, and partition 3 starts in the same location, parted needs to note that individual bytes cannot overlap between partitions.
The Size column represents the size of the partition in kilobytes (KB), megabytes (MB), or gigabytes (GB).
The Type column represents the partition type: primary, extended, or logical. See the partition information in figure 1.
The File system column represents the file system type: ext2, ext3, ext4, fat32, linux-swap, and so on.
The Flags column is the partition open flag, including boot, raid, and lvm. In this example, partition 1 is the boot partition.
Figure 1. Primary and extended partitions in the example
In the previous example, partition 4 defines an extended partition that contains 143GB on the 165GB disk (figure 1). Logical partitions cannot be changed when in use, otherwise all logical partitions in them will be affected.
In addition to reporting on the layout and size of the hard drive, you can use parted to modify the disk layout interactively. Be careful when using this method, and you must back up your system before you start using this utility. Note that changing the partition information (partition table) on the disk will destroy the information on the disk. Please read the parted information page before you try to modify the partition table. It is worth noting that the wrong use of parted can destroy all data on disk.
Be careful when using parted, because you are using a utility that formats your hard drive. Changes made with parted can easily result in the loss of a large amount of data. If you have any problems with what you are doing with parted, use the Q command to exit before applying its changes. As soon as you enter the command, parted makes changes as required.
To partition the disk, you need to add the name of the device to use after the parted command. In the following example, after starting parted, the user enters the help (or just h) command and a list of parted commands is displayed:
# parted / dev/sda GNU Parted 2.3 Using / dev/sda Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) help align-check TYPE N check partition N for TYPE (min | opt) alignment check NUMBER do a simple check on the file system cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition help [COMMAND] print general help, or help on COMMAND mklabel Mktable LABEL-TYPE create a new disklabel (partition table) mkfs NUMBER FS-TYPE make a FS-TYPE file system on partition NUMBER mkpart PART-TYPE [FS-TYPE] START END make a partition mkpartfs PART-TYPE FS-TYPE START END make a partition with a file system move NUMBER START END move partition NUMBER name NUMBER NAME name partition NUMBER as NAME print [devices | free | list,all | NUMBER] display the partition table, available devices, free. Quit exit program rescue START END rescue a lost partition near START and END resize NUMBER START END resize partition NUMBER and its file system rm NUMBER delete partition NUMBER select DEVICE choose the device to edit set NUMBER FLAG STATE change the FLAG on partition NUMBER toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER unit UNIT set the default unit to UNIT version display the version number and copyright information of... (parted)
Help is followed by the name of a parted command parameter, and more information about that command parameter is displayed. When you enter the print (or just p) command, parted displays the current partition information, just like the print command on the command line.
The parted utility does not allow you to set overlapping partitions (except that logical partitions can overlap the extended partitions they contain). Similarly, it is not allowed to create a partition that starts right at the beginning of the disk (cylinder 0). All of these situations can lead to data loss.
When defining a disk partition table, keep some basic guidelines in mind. First of all, do not delete or modify the partition that defines the extended partition unless you are willing to lose all the data on all logical partitions in the extended partition. Second, if / boot is placed on a separate partition, * * is placed at the beginning of the drive (partition 1) so that Linux can boot from the nearest partition on the drive. When the cost of disk space is not an issue, * put each primary file system on a separate partition. Many people choose to put / (root), / var, and / usr together in a separate partition, which usually saves space, but occasionally causes problems. * * although parted can create some types of file systems, parted is usually used to create partitions, and then you can use mkfs and mkswap to create file systems on partitions.
The following command sequence (figure 2) defines a 300MB bootable Linux partition on a clean disk and uses it as partition 1:
Figure 2. Define the command sequence for bootable Linux partitions
When you specify a size within a parted, you can use the suffix k (kilobytes), m (megabytes), or g (gigabytes). After creating the partition, enter the print command to see where the partition ends. Define the next adjacent partition before performing this task so that space is not wasted. After setting up all partitions, use the quit command to exit parted.
Next, create a file system on each partition that contains the file system (not swapped). Unless there is a reason not to do so, set all partitions to type ext4 except swap partitions. Using mkswap, you can set up a swap area on a partition. In addition, you can use e2label to mark a partition.
Application tool 2: apply logrotate to manage log files
You may want to keep log files for a while instead of deleting or truncating them in case you need to refer to them. The logrotate utility automatically manages system log (and other) files by rotating, compressing, emailing, and deleting each specified file. The logrotate utility is controlled by the / etc/logrotate.conf file, which is used to set default values and to specify which files to rotate. Typically, logrotate.conf contains an include statement that points to the specification file in / etc/logrotate.d specified by the utility. The following are the default logrotate.conf files:
$cat / etc/logrotate.conf # see "man logrotate" for details # rotate log files weekly weekly # keep 4 weeks worth of backlogs rotate 4 # create new (empty) log files after rotating old ones create # use date as a suffix of the rotated file dateext # uncomment this if you want your log files compressed # compress # RPM packages drop log rotation information into this directory include / etc/logrotate.d # no packages own wtmp and btmp-we'll rotate them here / var/log/wtmp {monthly create 0664 Root utmp minsize 1M rotate 1} / var/log/btmp {missingok monthly create 0600 root utmp rotate 1} # system-specific logs may be also be configured here.
The logrotate.conf file sets default values for commonly used parameters. Whenever logro-tate reads another value of these parameters, the default values are reset. You can choose daily (daily), weekly (weekly), or monthly (monthly) to rotate files. The number after the rotate keyword specifies the number of rotated log files to keep. The create keyword causes logrotate to create a new log file with the same name and properties as the newly rotated log file. The dateext keyword causes logrotate to use the date as the file extension. The compress keyword (commented out in the default file) causes the log file to be compressed by gzip. The include keyword specifies the standard / etc/logrotate.d directory for the logrotate specification file for a specific program. When you install a program using rpm or a rpm-based utility, rpm places the logrotate specification files in that directory.
The * instruction set in logrotate.conf processes / var/log/wtmp and / var/log/btmp log files (wtmp saves login records, while btmp keeps records of failed login attempts); you can view these files that use who. The missingok keyword overrides only the implicit default value nomissingok of this file, which causes logrotate to continue running without sending an error message even if the log file is missing. The keyword monthly overrides only the default value of weekly for this file. The create keyword is followed by parameters that establish permissions, owners, and groups for the new file. The rotate of * * establishes the rotation log files that should be retained.
The / etc/logrotate.d/httpd file is an example of a utility logrotate specification file:
$cat / etc/logrotate.d/httpd / var/log/httpd/*log {missingok notifempty sharedscripts delaycompress postrotate / sbin/service httpd reload > / dev/null 2 > / dev/null | | true endscript}
This file is installed by the httpd package installation script, put into / etc/logrotate.d through the include statement in logrotate.conf, and uses each file whose filename ends with log (* log) in / var/log/httpd. If the log file is empty, the notifempty keyword causes logrotate not to rotate the log file, but to rewrite the empty log file. The sharedscripts keyword causes logrotate to execute commands for the prerotate and postrotate sections only once, rather than once for each rotated log file. The delaycompress keyword causes logrotate to delay one cycle of compression. The copytruncate keyword does not appear in this example, which causes logrotate to truncate the original log file immediately after copying, which is useful for programs that cannot close and reopen the log file, because these programs may continue to write to the original file if the original file has been moved. Before the rotation begins, the logrotate utility executes the command between prerotate and endscript. Similarly, when the rotation is complete, the command between postrotate and endscript is executed.
The logrotate utility uses a number of keywords, many of which take parameters and have other functions. See the logrotate man page for more information.
Application tool 3: use rsyslogd to record system messages
Traditionally, UNIX programs send log messages to standard error. If a more * log is needed, the output will be redirected to a file. To overcome the limitations of the above approach, 4.3BSD introduces the Syslog daemon (rsyslogd; www.rsyslog.com) currently used by Linux. This daemon is responsible for listening for log messages and storing them in the / var/log directory. In addition to providing logging capabilities, rsyslogd allows a machine to serve the network as a log library and allows other programs to process specific log messages.
The / etc/rsyslog.conf file stores configuration information for rsyslogd. Each line in this file contains one or more space-separated selectors (selector) and an action (action). The selector defines the source and type of the message, and the action specifies how the rsyslogd handles the message. The rsyslog.conf example is as follows (# start a comment):
# Log all kernel messages to the console. Kern.* / dev/console # Log all the mail messages in one place. Mail.* / var/log/maillog # Log cron stuff cron.* / var/log/cron # Everybody gets emergency messages * .emerg * # Save boot messages also to boot.log local7.* / var/log/boot.log
Selector
The selector is divided into two parts: facility and priority, which are separated by a period. The facility indicates the source of the message. For example, kern messages come from the kernel, and mail messages come from the mail subsystem.
Figure 3 is a list of facility names used by rsyslogd and the system that generates these messages:
Priority indicates the severity of the message. Figure 4 shows a list of priority names and the conditions they represent, listed in ascending order of priority:
Figure 4. Priority indication
A selector consists of a single facility and priority, such as kern.info, which causes the corresponding action to be applied to every message from that facility with that priority or higher priority (more urgent). Use. = to specify a single priority item; for example, kern.=info means to apply the action to kernel messages with info priority. An exclamation point specifies a priority that does not match. So kern.kernel info matches kernel messages with lower priority than info, and kern.kernel messages info matches kernel messages with non-info priority.
A row separated by semicolons that contains multiple selectors is performed whenever there is a matching selector, each selector in the row constrains the match, and subsequent selectors usually tighten the constraint. For example, the mail.infoten mail.accounerr selector matches mail subsystem messages with debug, info, notice, or warning priorities.
You can replace each part of the selector with an asterisk to match anything. The none keyword for each part of the selector indicates that it is impossible to match. The * .crit;kern.none selector matches all critical or higher priority messages, except those from the kernel.
action
Action specifies how rsyslogd handles a message that matches the selector. The simplest action is the normal files specified by their absolute path to which rsyslogd appends messages. Specify / dev/console to send messages to the system console. If you want to hard copy a message record, you need to specify a device file that represents a dedicated printer. Precede the file name with a hyphen (-) to prevent each message from being written to the file. This may improve performance, but if the system crashes, data may be lost so that the resulting message is not written to a file in time.
Important messages can be written to the user terminal by specifying one or more user names separated by commas. Very important information can be written to each logged-in terminal by using an asterisk.
To forward a message to rsyslogd on a remote system, specify the name or IP address of the system by preceded by an @ (send the message to UDP port 514) or @ @ (send the message to TCP port 514). * forward critical information from the kernel to another system because these messages may not be saved to the local disk before the system crashes. The lines in the following rsyslog.conf send critical kernel messages to plum:
Kern.crit @ plum
When editing / etc/rsyslog.conf on a remote system, whether the following two command lines are run depends on whether you want to use UDP or TCP. Do not delete the hash tag in the comment. After editing this file, use rsyslog.service to restart the rsyslogd daemon.
# Provides UDP syslog reception # $ModLoad imudp # $UDPServerRun 514 # Provides TCP syslog reception # $ModLoad imtcp # $InputTCPServerRun 514
Application tool 4: master system report
Many utilities can report on things. For example, who, finger, ls, ps, and other utilities can generate simple end-user reports. In some cases, these reports contribute to system administration. The utilities described in this section can produce more detailed reports and provide more help for system administration tasks. Linux also has many other reporting utilities, such as sar (system activity reports), iostat (input / output and CPU statistics) and mpstat (processor statistics) in the sysstat package, netstat (network reports, in the net-tools package), and nfsstat (NFS statistics, in the nfs-utils package).
Use vmstat to master virtual memory statistics
The vmstat utility (virtual memory statistics, located in the procps package) generates virtual memory information that contains disk and CPU activity data. The following example shows virtual memory statistics for seven iterations (parameter 3-7) every 3 seconds. * rows include the time since the system was started, and each subsequent line includes the time interval since the previous line.
$vmstat 37 procs-memory--swap---io-----system---cpu---- r b swpd free buff cache si so bi bo in cs us sy id wa 0 20 684328 33924 219916 0 0430 1052 1052 24 86 80 20 654632 34160 2488 400 0 4897 7683 1142 237 05 95 0 30 623528 34224 279080 05056 8237 1094 178 0 4 0 95 0 20 603176 34576 298936 0 0 3416 141 1161 255 0 4 0 96 0 20 575912 34792 325616 0 0 4516 7267 1147 231 0 4 0 96 120 549032 35164 351464 0 0 4429 77 1120 210 0 4 0 96 0 20 523432 35448 376376 0 0 4173 6577 1135 234 0 4 0 95
The following list explains the fields displayed by vmstat:
Procs process Information
R the number of processes that can be run while waiting
B the number of processes blocked (in uninterrupted sleep)
Memory memory information (in kilobytes)
Virtual memory used by swpd
Free free memory
Memory used by buff as a buffer
Cache is used as cache memory
Swap system paging activity (kilobytes per second)
Si swaps from disk to memory
So swaps memory out to disk
Io system Icano activity (blocks per second)
Blocks received by bi from block devices
Blocks sent by bo to block devices
System (unit per second)
In interrupt (including clock)
Cs context switch
Percentage of total CPU time spent by cpu per statu
Us user (non-kernel)
Sy system (kernel)
Id idle
Wa waits for Icano
St is extracted from virtual machines (only on virtual machines)
Use top to list the processes that use the most resources
The top utility is a useful complement to ps. At the very least, the system information displayed by top includes processes that are intensive using CPU. The top utility can update itself periodically, and you can exit by typing Q. Although command line options are available, it is often more helpful to use interactive commands.
Table 1. Top interactive commands
Top top-17:58:53 up 3 days, 4:20, 1 user, load average: 2.166,1.61,0.83 Tasks: 167total, 5 running, 162sleeping, 0 stopped, 0 zombie Cpu (s): 1.5%us, 0.5%sy, 1.3%ni, 96.0%id, 0.2%wa, 0.6%hi, 0.0%si, 0.0%st Mem: 2076092k total, 1990652k used, 85440k free, 18416k buffers Swap: 7815580k total, 34908k used, 7780672k free 1330008k cached PID USER PR NI VIRT RES SHR S% CPU% MEM TIME+ COMMAND 31323 zach 25 0 9020 6960 396 R 63 0.3 bzip2 31327 zach 2092 2092 596 492 R 57 0.0 cp 31311 root 15000 0 S 16 0.0 038 pdflush 6870 zach 27 12 331m 190m 37m R 29.4 root 19842.98 firefox-bin 31303 root 15000 0 S 2 0.0 firefox-bin 00.42 pdflush 1 root 150 2908 488 S 00. Will it be helpful for you to read the above content after reading the above content for 1 0Rom 01.55 init? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.