UNIX system common management commands _unix Linux

Source: Internet
Author: User
Tags nfsd

I. INTRODUCTION
Unix system, as a powerful multi-user time-sharing operating system, has been applied in more and more occasions, and the requirements of UNIX system management are more and more, but the current Books on UNIX system management commands are not many. This article is primarily for UNIX system administrators, with the Sun SOLARIS 2.6 system as
Examples, the use of some UNIX commonly used management commands and problems encountered in their use, and the solution, for your reference.

Two. Introduction of common system Management commands
1. Share and Mount command

This is the two commands commonly used by system administrators, the share command is used to share native directories so that other UNIX systems can be used, and the Mount command is used to hook up directories shared by other UNIX systems to the local hook point, allowing the use of resources from other UNIX systems. For example:
Enter machinea# share-f nfs-o on Machine a rw/share-dir
Enter machineb# mount-f NFS Machinea:/share-dir/mount-point on machine b
The first command shares the Share-dir directory of Machine A, and the shared permission is readable and writable;
The second command hooks the shared directory of machine A to the Mount-point directory of Machine B.
After these two commands are completed, the user will be able to manipulate the mount-point on machine B by accessing the
Share-dir directory.

But sometimes when we do the Mount command on machine B, we return
Errors such as "Rpc:program not registered" are due to the lack of mountd and nfsd daemons (daemon) on machine A. When the UNIX system is started, the/etc/dfs/dfstab files are automatically checked, and if there are resources to share in the file, the two daemons are started, and conversely, they are not started. So if we don't have content in the/etc/dfs/dfstab, the system cannot start the Mountd and Nfsd daemons, and the directories shared with the share command cannot really be shared by other systems.

The solution to this problem is simple, we can put the directory to be shared into the/etc/dfs/dfstab, the next time the system will start automatically share the directory, in addition, we can manually start the two daemons, by first using the root of the user to log in, At the command line, enter the following command:
machine_a#/etc/rc3.d/s15nfs.server Start
or enter:
machine_a#/usr/lib/nfs/mountd
machine_a#/usr/lib/nfs/nfsd-a 16
You can start the two daemons.

Once the daemon is started, the shared directory is actually shared, and then the Mount command on machine B can hook up the directory of machine A to machine B.

2. Quota Series Command

Unix as a multi-user system, it allows multiple users to use the system's resources, including the system's memory, CPU and hard disk. By default, the system does not limit the size of the hard disk space that each user can use, so if the user maliciously uses the hard drive, or if the user inadvertently consumes all of the hard disk space, it will cause other users to be unable to use the hard drive, resulting in degraded system performance and even a crash risk.

In fact, the quota series commands provided by UNIX can help us solve this problem, and these commands include:
Quota: Displays the user's hard disk limit and usage.
Edquota: Set the hard disk limit for each user.
Quotaon: Boot file system hard disk quota service
Quotaoff: Turn off File system hard disk quota service
Repquota: Displays current disk limit status
The way to configure this service is simple. But before using the hard disk limit service, we need to understand the two concepts of hard limit and soft limit. The so-called hard limit refers to the absolute limit of resource nodes and data blocks, and in no case allows users to exceed this limit; soft limit refers to the user can be within a certain time range (the default is one week, set in the/usr/include/sys/fs/ufs_quota.h file) Exceed the limit of soft limits and continue to request resources within a hard limit, while the system gives a warning message when the user logs on and continues to request the remaining time for the resource. If the time limit is reached, the user's hard drive is still more than the soft limit, the system will not allow users to request hard disk resources.

Understanding these two concepts, we can configure the hard disk limit service, we must first in the file system to limit the root directory to create a quotas file, the file owner should be root, and other users can not write to it. The method is:
# cd/home (enter file system root directory, note not system root directory, this example is/home directory)
# Touch quotas (Create an empty text with a name of quotas)
# chmod 644 Quotas (change file properties so that only root can write to it)

Then, we edit the/etc/vfstab file, find the file system for the hard disk quota service, and
The value of the Mount option field is set to RQ, and then the disk is exited.

After completing these two steps, we use the Edquota command to set the hard disk limit for each user, and enter the following command under root permissions:
#edquota username
The system automatically generates a temporary file and has the following contents:
Fs/users blocks (soft = 0, hard = 0) inodes (soft = 0, hard = 0)
Where the FS field indicates a file system with a hard disk limit, this example is/users,block and inodes indicating the number of hard drives that users can use, the amount of hard disk space available to the user, and the number of files that can be built, soft and hard, respectively, for the soft and hard limits mentioned above.

Edit this file, set the soft, hard limit to the appropriate value, and then save the disk. At this point we can see that the size of the quotas file has been changed, indicating that the user's limit has been stored. Repeat this command to configure the disk limit for each user. In addition, if we assign the same amount of hard disk to the user, we can use the "-P" parameter instead of editing a file for each user, and it is used in the following ways:
#edquota-P reference-username username

After editing the file, we can use Quotaon to start the service, under root permissions to enter
#quotaon/users
You can start the quota service. If we want to see the current usage of individual users, you can use the
Repquota command, enter under root permission:
#repquota/users
The system will display:


From this we can easily see the user's hard disk and file usage as well as the time after the soft limit can still apply for resources and so on.

Of course we can use Quotaoff to cancel the hard disk limit service. In addition, the system also provides a Quotacheck command to check the consistency of the quotas.

3. Ifconfig command

The Ifconfig command is used to view and change the address and parameters of the network interface, and if you want to display the IP address of a UNIX host, we can enter at the command line:
$ifconfig-A
The system displays the name of the network interface, the state of the interface (up or down), the IP address and mask of the interface, and so on.

If we want to change the IP address of the network interface, we can enter it under root permission:
#ifconfig HME0 Down
#ifconfig HME0 202.1.2.3 netmask 255.255.255.0 up
First, use the down command parameter to temporarily stop the service of the network interface HME0, and then use the Ifconfig command to assign a new IP address and mask to the interface and start the network interface service. In this example, the IP address of the HME0 interface is set to 202.1.2.3, and the mask is 255.255.255.0.

We can also change the IP address of the machine by changing the value of the IP address in the file/etc/hosts and restarting the system.

When the system starts, the network interface service is automatically started, we do not need to manually create the network port service, but sometimes we change the network card or increase the network card, the system can not automatically start the interface service, then we need to manually create the network port service, under the root permissions input:
#ifconfig HME0 Plumb
You can create a network port service for the interface Le0.
Accordingly, with the ifconfig with Unplumb parameters can stop the service and shut down the network interface, then we use the IFCONFIG-A command will not see the network interface.

4. Format command
Format is also an important system management command, but because it's devastating, be careful when you use it. The format command has two main uses, that is, to format the hard disk and repartition the hard disk, as described below:
1) format the hard drive
Like DOS, a UNIX hard drive needs to be formatted before it can be used, and before it is formatted, we need to restart the system in single-user form.
#reboot-S
Log in with the root user after startup and enter at the command line:
#format
The system will display all the hard drives and let us select the hard disk to format:

In this example, the system has two sun2.1g hard drives, we choose 1 and return, the system will display the following menu:

Enter type at the prompt to select the hard drive type, the system will list the type of hard disk it supports, select the appropriate hard disk type and enter the appropriate code (or enter 0 to automatically detect the system). After you select the hard disk type, you can configure the hard disk partition, see the "2" repartition section for specific operations on partitions.

After the configuration is finished, enter the format command for formatting, which will take a certain amount of time, depending on the machine model and the size of the hard disk. Once the format is complete, you can enter the QUIT command to exit.

After the hard drive is formatted and cannot be used immediately, we also need to create the file system on it and use the command Newfs to create the file system for each partition:
#newfs/dev/rdsk/c0t1d0s0
#newfs/dev/rdsk/c0t1d0s1
...
The specific values of the parameters are set according to the partition.

In addition, if the hard disk contains a boot partition (root partition), we need to manually install the boot module, the first to install the UNIX system installation CD-ROM, we start with the CD, the system root partition hook up, and from the CD to install the boot module, the specific methods are as follows:
#reboot cdrom-s (boot from CD and into Single-user mode)
#mount/dev/dsk/c0t1d0s0/mnt (the system root partition is attached to the MNT directory)
#cp/ufsboot/mnt
#installboot/lib/fs/ufs/bootblk/dev/rdsk/c0t1d0s0 (Install boot module)
#umount/mnt (remove hook)
#reboot (reboot)

Now that the format of the hard drive has been completed, we can use the hard drive.
2) Repartition
The format command can also repartition the hard disk. After the partition is partitioned, all files on the affected partition will be purged, so before doing so, we should be careful to make a backup of the file system first. The specific ways to repartition are as follows:
First we go into single-user form, log in with root, and then enter at the command line:
#format
The system will display all the hard drives and let us select the hard drive: we choose 0 and return, the system will display the following menu:
Input partition, then enter modify, carriage return, the system prompts the user to select the partition base (partitioning base), select 1, enter, the system will show:

We have partitioned 6 as a free partition, which means that free partition 6 is used as an accumulation or reduction of hard disk space if other partition sizes change. Then enter the desired partition values as required by the system, and format automatically adjusts the partition cylinder boundaries so that there is no gap between the partitions. Enter confirm the partition table, name the partition table, and exit the format command after confirming.
After the partition is over, we'll use the NEWFS command to create the file system for the changed partition.
# NEWFS/DEV/RDSK/C0T0D0S6
Then copy back the backed-up files to complete the hard drive partition changes.

Again, the format command is extremely destructive and can easily lead to data loss and even system crashes, so be careful when using it.

5. fsck command
The fsck command is also a frequently used command that is used to check the file system and repair the damaged file system.

The syntax for fsck is as follows:
Fsck (-F Fstype) (-V) (-M) (-special ...)
Fsck (-F Fstype) (-V) (-y| y|n| N) (-O fstype options) (Special ...)
which
-F Fstype: Description of the type of file system being checked
-V: Returns the completed command line, but does not run
-y| Y: Answer yes to all questions
-n| N: Answer No to all questions
-M: Check the file system, do not repair the file system, if the file system is checked to install
, the UFS fsck:sanity check:/dev/rdsk/c0t0d0s0 okay is displayed.
-O: File system type options, options are separated by commas, and the most commonly used options are two:
P: Finishing (preen) mode
F: Force check mode, this option ignores file system status flags.

After running fsck, the command checks the file system in 6 stages, which are:
Phase 1: Check the size of blocks and blocks
Phase 2: Check the path name
Phase 3: Check connectivity
Phase 4: Check reference count
Phase 5: Check the free block list
Stage 6: Recovery free Block List

When fsck checks for each phase, if an error is found, the user is prompted to modify it, and some common errors are:
1 Remove a directory entry with no related files

The user can then answer yes or Y to delete the directory entry.
2 Reconnect a file that has been assigned but cannot be accessed:
Fsck found an assigned I node, but it was inaccessible (the node is not connected to any directory), and then the fsck "reconnect?" "Answer yes, that is, connect the I node to the Lost+found directory, the file name is the I node number, then the administrator should check the file type, identify the purpose of the file, and then copy the file to the appropriate directory."


3) Connection Number adjustment
In interactive mode, if Fsck finds that the number of connections is inconsistent, it asks the user what action to take, and this example finds that the number of I nodes in a directory does not match the true number of connections to the directory.


The user should then answer yes or Y to correct the number of connections.

4) Free Block table inconsistency
Fsck finds that the number of unallocated blocks is inconsistent with the free block table given in the Super block.


The user should then answer yes or Y to correct the super block.

From the above error information and processing methods can be found, for the problem of FSCK asked in most cases can be answered with Yes, so in the actual application, you can use the "-y" option to execute the command on the hard drive to check
Check and repair.
6. Route command
The route command is primarily used to manually configure a static routing table. For example, we want to add a route through the gateway to the order subnet, as follows:
#route Add net remote_net_ip gateway_ip 1
Where add represents an increase in routing, net means that the route arrives at a network rather than a host, and 1 represents a remote network that needs to be reachable through a gateway, rather than directly connected to it (0 when connected directly through a network interface).

In Solaris 2.6, you can also use the following command:
#route add-net remote_net_ip gateway_ip-netmask netmask
#route add-host host_ip Local_interface_ip-interface
The first command completes the same task as the command described above, while the second command represents a route to a different host through the network interface.

Of course, we use the "delete" command parameter to delete and modify routing information in the routing table.
After executing the route command, we can quot;netstat-rn the command to view the current routing information:


You can tell from the routing table that there are currently 5 routes, where the routes to 224.0.0.0 and 127.0.0.1 are broadcast routes and local routes, which are set by the system defaults. The route to the host 202.77.111.22 is connected through the native network interface, and the route to the network 202.77.112.0 is connected through the gateway 202.77.111.1.
After the routing table is configured through route, the routing information is saved until the next system reboot. After the system restarts, reconfigure the routing table. By modifying file/etc/defaultrouter You can set up default routes that are added to the routing table every time the system starts, without having to configure the routing table with the route command every time you start. The format of the/etc/defaultrouter file is as follows:
$cat/etc/defaultrouter
202.77.111.1
The file now has only one default route, the IP address is 202.77.111.1, which means the system will send all packets that are not local to the gateway 202.77.111.1.
Sometimes when a UNIX system is installed, there is no Defaultrouter file in the/etc directory, and then we can create the file manually, edit the default route, and then reboot. When the system is started, the configured default routing information is automatically used.

Three. Unix System Management FAQ and Solutions
1. Forget root password

Root is also known as Superuser, it is the most privileged users, once its password has been forgotten, will give the system maintenance and management of a lot of difficulties, the following is forgotten root password processing method:

First, we need to start the system from the CD-ROM, the command is:
#boot cdrom-s

After the system starts, we'll hook the hard disk root partition to the/MNT directory on the CD file system and execute:
#mount/dev/dsk/c0t0d0s0/mnt
(This example assumes that the root file system is/c0t0d0s0)
Edit the shadow file for the root partition of the hard disk and set the password entry location to null for root.
#cd/mnt/etc
#vi Shadow

Note that some systems want to edit the/etc/passwd file instead of the/etc/shadow file.

After the file is changed, remove the attached root file system.
#umount/mnt

Reboot the system and set the new root password.
2. The system does not start
The reason the system cannot be started is as follows:
1 The wrong boot device
If the system is not booted because the wrong boot device is specified, we can use the "Probe-scsi", "Probe-scsi-all" and "Probe-ipi" commands under the prom monitoring level to see what devices are connected
To the system and get the Devalias name of the boot device. The method to enter the prom is when the system starts, press the "STOP" Key and "a" key at the same time, the system appears prompt Ok&gt, that is, the system is currently in the prom
Monitoring level.

Displays the current configuration with printenv, and if the boot device is found to be incorrect, use setenv to reset:
Ok>setenv Boot-device Devalias

Reboot the system with the Reset command, or restore the default value set-defaults.

2 lack of important system files, or invalid files
You can then use the "-a" option to boot the system and the system will provide an interactive boot process if there is no
To the file, the user is prompted to give the appropriate file name.

3 lack of critical system files, or invalid files
For example, a/etc/passwd file is missing, and the system may boot, but no user can register. The fix is to start with a CD-ROM, hook up the root file system, and edit the/etc/passwd file.

4 Unable to hook up the remote file system
When the system starts, the/etc/vfstab file is automatically executed, and if there are remote file systems in the file that cannot be hooked up, the system will remain in a standby and retry state and cannot enter the login interface. The solution is to start with a single user, edit the/etc/vfstab file, and delete the wrong hooks.
3. Keyboard failure

If there is a keyboard failure, that is, the user entered information on the keyboard and there is no response on the screen, first check the hardware connection, that is, to see whether the keyboard and host connection is intact, connecting the wire is broken or damage.
If there is no problem with the hardware connection, check to see if the lock Screen command was accidentally used. The method is to press the "CTRL+Q" key and if the system is responding, it is because the user pressed the "ctrl+s" key to temporarily lock the screen. The locked screen will not display information that the user entered from the keyboard, but the information entered can still be performed.
If the system is still not responding, we will reboot the system, enter the prom state, enter the Printenv command, and view the value of the input device item, if its value is not keyboard, use
Ok>setenv InputDevice Keyboard
Make the keyboard an input device and then reboot the system again, and the system will respond to user input.

4. Cron or AT commands cannot be executed

UNIX systems do not allow any user to use cron for job scheduling, and there are two files for user restrictions, which are/etc/cron.d/cron.allow and/etc/cron.d/cron.deny.
If the user name is added to the/etc/cron.d/cron.allow file, the user is allowed to use cron, and the user who is not in the file is not allowed to use it if the user is added to the/etc/cron.d/ Cron.deny, the user cannot use Cron, and other users can use Cron. Usually we have to configure one of these files as needed.
If the user is allowed to use cron, you can use the command
$crontab Mycronfile
Install your own job scheduling control files in the system's/var/spool/cron/crontabs directory.
At and cron alike, to use at, you need to configure/etc/cron.d/at.allow or/etc/cron.d/at.deny files.

5. Cannot log in with root when Telnet

By default, UNIX systems are not allowed to log on with Root at a terminal other than the system console (console) for security reasons, so sometimes when we log in by Telnet with root, we return
"Not on system console"
Such a mistake, we can then modify the/etc/default/login file to allow root to log in by Telnet. To do this, edit the login file and locate the following line:
Console=/dev/console
Comment out this line, that is, add the "#" character at the beginning of the row, save the exit, and use Telnet again, root can log in.
6. About access to the directory

We all know that every file in a UNIX system has access rights, the system Controls access to files based on that permission, and the directory in the UNIX system has access rights, but its definition is somewhat different from the file.

Read permission:
Read permissions on the directory indicate that the user can view the contents of the directory, that is, commands such as "LS" can be used on the directory.

Write permission:
Write permission on the directory indicates that the user can create a new file or delete the file in the directory, regardless of whether the user has write permission to the file at this time.

Execute permissions:
Execution permission means that a user can search for a file in that directory, or you can use a file with the appropriate access rights under that directory.

Four. Summary
The management maintenance commands described above are only a very small part of the UNIX system's maintenance management commands, and UNIX offers many other useful commands that require constant learning and research in our work.
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.