1、高级 Linux 命令精通指南管理linux环境4Guide to Advanced Linux Command Mastery, Part 4: Managing the Linux Environmentby Arup NandaPublished May 2009In this installment, learn how to manage the Linux environment effectively through these commonly used commands.ifconfigThe ifconfig command shows the details of the
2、 network interface(s) defined in the system. The most common option is -a , which shows all the interfaces.# ifconfig -aThe usual name of the primary Ethernet network interface is eth0. To find out the details of a specific interface, e.g. eth0, you can use:# ifconfig eth0The output is show below, w
3、ith explanation:Here are some key parts of the output: Link encap: the type of the hardware physical medium supported by this interface (Ethernet, in this case) HWaddr: the unique identifier of the NIC card. Every NIC card has a unique identifier assigned by the manufacturer, called MAC or MAC addre
4、ss. The IP address is attached to the MAC to the server. If this IP address is changed, or this card is moved from this server to a different one, the MAC does not change. Mask: the netmask inet addr: the IP address attached to the interface RX packets: the number of packets received by this interfa
5、ce TX packets: the number of packets sent errors: the number of errors in sending or receivingThe command is not just used to check the settings; its used to configure and manage the interface as well. Here is a short list of parameters and options for this command:up/down enables or disables a spec
6、ific interface. You can use the down parameter to shutdown an interface (or disable it):# ifconfig eth0 downSimilarly to bring it up (or enable) it, you would use:# ifconfig eth0 upmedia sets the type of the Ethernet media such as 10baseT, 10 Base 2, etc. Common values for the media parameter are 10
7、base2, 10baseT, and AUI. If you want Linux to sense the media automatically, you can specify “auto”, as shown below:# ifconfig eth0 media autoadd sets a specific IP address for the interface. To set an IP address of 192.168.1.101 to the interface eth0, you would issue:# ifconfig eth0 add 192.168.1.1
8、01netmask sets the netmask parameter of the interface. Here is an example where you can set the netmask of the eth0 interface to 255.255.255.0# ifconfig eth0 netmask 255.255.255.0In an Oracle Real Application Clusters environment you have to set the netmask in a certain way, using this command.In so
9、me advanced configurations, you can change the MAC address assigned to the network interface. The hw parameter accomplishes that. The general format is:ifconfig hw Theshows the type of the interface, e.g. ether, for Ethernet. Here is how the MAC address is changed for eth0 to 12.34.56.78.90.12 (Note
10、: the MAC address shown here is fictional. If it matches any actual MAC, its purely coincidental.):# ifconfig eth0 hw ether 12.34.56.78.90.12This is useful when you add a new card (with a new MAC address) but do not want to change the Linux-related configuration such as network interfaces.Usage for
11、the Oracle UserThe command, along with nestat described below, is one of the most widely used in managing Oracle RAC. Oracle RACs performance depends heavily on the interconnect used between the nodes of the cluster. If the interconnect is saturated (that is, it no longer carries any additional traf
12、fic) or is failing, you may see reduced performance. The best course of action in this case is to look at the ifconfig output to view any failures. Here is a typical example:# ifconfig eth9eth9 Link encap:Ethernet HWaddr 00:1C:23:CE:6F:82 inet addr:10.14.104.31 Bcast:10.14.104.255 Mask:255.255.255.0
13、 inet6 addr: fe80:21c:23ff:fece:6f82/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1204285416 errors:0 dropped:560923 overruns:0 frame:0 TX packets:587443664 errors:0 dropped:623409 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1670104239570 (1.5 TiB) TX byte
14、s:42726010594 (39.7 GiB) Interrupt:169 Memory:f8000000-f8012100 Note the text highlighted in red. The dropped count is extremely high; the number should ideally be 0 or close to it. A high number more than half a million sounds like a faulty interconnect that drops packets, causing the interconnect
15、to resend packetswhich should be a clue in the issue statThe status of the input and output through a network interface is assessed via the command netstat. This command can provide the complete information on how the network interface is performing, down to even socket level. Here is an example:# n
16、etstatActive Internet connections (w/o servers)Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 prolin1:31027 prolin1:5500 TIME_WAIT tcp 4 0 prolin1l:1521 applin1:40205 ESTABLISHED tcp 0 0 prolin1l:1522 prolin1:39957 ESTABLISHED tcp 0 0 prolin1l:3938 prolin1:31017 TIME_WAITtcp 0 0 pro
17、lin1l:1521 prolin1:21545 ESTABLISHED and so on The above output goes on to show all the open sockets. In very simplistic terms, asocketis akin to aconnectionbetween two processes. Please note: strictly speaking, “sockets” and “connections” are technically different. A socket could exist without a co
18、nnection. However, a discussion on sockets and connections is beyond the scope of this article. Therefore I have merely presented the concept in an easy-to-understand manner. Naturally, a connection has to have a source and a destination, calledlocalandremoteaddress. The end points could be on the s
19、ame server; or on different servers.In many cases, the programs connect to the same server. For instance, if two processes communicate among each other, the local and remote addresses will be the same, as you can see in the first line the local and remote addresses are both the sever “prolin1”. Howe
20、ver, the processes communicate over aport, which will be different. This port is shown next to the host name after the “:” (colon) mark. The user program sends the data to be sent across the socket to a queue and the receiver reads from a queue at the remote end. Here are the columns of the output:1
21、. The leftmost column “Proto” shows the type of the connection tcp in this case.2. The columnRecv-Qshows the bytes of data in the queue to be sent to the user program that established the connection. This value should be as close to 0 as possible. In busy servers this value will be more than 0 but s
22、houldnt be very high. A higher number may not mean much, unless you see a large number inSend-Qcolumn, described below.3. TheSend-Qcolumn denotes the bytes in the queue to be sent to the remote program, i.e. the remote program has not yet acknowledged receiving it. This should be close to 0. A large
23、 number may indicate a network bottleneck.4. Local Addressis source of the connection and the port number of the program.5. Foreign Addressis the destination host and port number. In the first line, both the source and destination are on the same host: prolin1. The connection is simply waiting. The
24、second line shows and established connection between port 1521 of proiln1 going to the port 40205 of the host applin1. Its most likely an Oracle connection coming from the client applin1 to the database server prolin1. The Oracle listener on prolin1 runs on port 1521; so the port of the source is 15
25、21. In this connection, the server is sending the requested data to the client.6. The columnStateshows the status of the connection. Here are some common values.7. o ESTABLISHED that the connection has been established. It does not mean that any data is flowing between the end points; merely that th
26、e end points have talked to each other.o CLOSED the connection has been closed, i.e. not used now.o TIME_WAIT the connection is being closed but there are still packets in the network that are being handled.o CLOSE_WAIT the remote end has shutdown and has asked to close the connection.Well, from the
27、 foreign and local addresses, especially from the port numbers, you can probably guess that the connections are Oracle related, but wont it be nice to know that for sure? Of course. The -p option shows the process information as well:# netstat -pProto Recv-Q Send-Q Local Address Foreign Address Stat
28、e PID/Program name tcp 0 0 prolin1:1521 prolin1:33303 ESTABLISHED 1327/oraclePROPRD1 tcp 0 0 prolin1:1521 applin1:51324 ESTABLISHED 13827/oraclePROPRD1 tcp 0 0 prolin1:1521 prolin1:33298 ESTABLISHED 32695/tnslsnr tcp 0 0 prolin1:1521 prolin1:32544 ESTABLISHED 15251/oracle+ASM tcp 0 0 prolin1:1521 pr
29、olin1:33331 ESTABLISHED 32695/tnslsnr This clearly shows the process IP and the process name in the last column, which confirms it to be Oracle server processes, listener process, and ASM server processes.The netstat command can have various options and parameters. Here are some key ones:To find out
30、 the network statistics for various interfaces, use the -i option.# netstat -iKernel Interface tableIface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flgeth0 1500 0 6860659 0 0 0 2055833 0 0 0 BMRUeth8 1500 0 2345 0 0 0 833 0 0 0 BMRUlo 16436 0 14449079 0 0 0 14449079 0 0 0 LRUThis
31、 shows the different interfaces present in the server (eth0, eth8, etc.) and the metrics associated with the interface. RX-OKshows the number of packets successfully sent (for this interface) RX-ERRshows number of errors RX-DRPshows packets dropped and had to be re-sent (either successfully or not)
32、RX-OVRshows packets overrunThe next sets of columns (TX-OK, TX-ERR, etc.) show the corresponding stats for send data.Flgcolumn is a composite value of the property of the interface. Each letter indicates a specific property being present. Here is an explanation of the letters.B BroadcastM MulticastR Run
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1