Common Management commands for UNIX systems

Source: Internet
Author: User
Tags disk usage nfsd


I. Introduction
As a powerful multi-user time-sharing operating system, UNIX systems have been applied in more and more scenarios. At the same time, more and more requirements are required for UNIX system management, however, there are not many books about UNIX system management commands. This document is intended for UNIX system administrators.
For example, it lists the usage of some common UNIX management commands and the Problems and Solutions encountered during use for your reference.

II. Introduction to common system management commands
1. share and mount commands

This is a commonly used command by the system administrator. The share command is used to share the local directory so that other UNIX systems can use it; the mount command is used to mount the directories shared by other UNIX systems to the local mount point, so that resources of other UNIX systems can be used. For example:
Enter machineA # share-F nfs-o rw/share-dir on machine.
On Machine B, enter machineB # mount-F nfs machineA:/share-dir/mount-point
The first command shares the share-dir directory of machine A and shares the read/write permission;
The second command mounts the shared directory of machine A to the mount-point directory of machine B.
After the two commands are completed, the user can operate
The share-dir directory is now available.

However, sometimes, after the mount command is executed on machine B
"RPC: Program not registered" is incorrect because mountd and nfsd daemon are missing on machine ). When a UNIX system is started, the system automatically checks the/etc/dfs/dfstab file. If there are resources to be shared in the file, the two daemon processes are started. Otherwise, the two daemon processes are not started. Therefore, if there is no content in/etc/dfs/dfstab, the system cannot start the mountd and nfsd daemon, and the shared directory with the share command cannot be truly shared by other systems.

The solution to this problem is very simple. We can put the directory to be shared into/etc/dfs/dfstab, And the directory will be automatically shared the next time the system starts. In addition, you can also manually start these two daemon by logging on to the Super User (root) and running the following command on the command line:
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 these two daemon processes.

After the daemon starts, the shared directory is shared. Then, run the mount command on machine B to mount the directory of machine A to machine B.

2. quota commands

UNIX is a multi-user system that allows multiple users to use system resources, including system memory, CPU, and hard disk. By default, the system does not limit the size of the hard disk space that each user can use. Therefore, if the user maliciously uses the hard disk, or the user is negligent, the hard disk space is fully occupied, other users may not be able to use the hard disk, resulting in a reduction in system performance or even a risk of crash.

In fact, the quota commands provided by UNIX can help us solve this problem. These Commands include:
Quota: displays the user's hard disk quota and usage.
Edquota: sets a hard disk quota for each user.
Quotaon: Enable the file system Hard Disk Quota Service
Quotaoff: Disable the file system Hard Disk Quota Service
Repquota: displays the current hard disk quota status
The method for configuring this service is simple. However, before using the hard disk quota service, we need to understand the two concepts: Hard limitation and soft limitation. The so-called hard limit refers to the absolute limit on Resource Nodes and data blocks. Under no circumstances can users exceed this limit; the soft limit refers to the amount that the user can set within a certain period of time (one week by default, in the/usr/include/sys/fs/ufs_quota.h file) beyond the soft limit, you can continue to apply for resources within the limits. At the same time, the system will give a warning when the user logs on and continue to apply for resources for the remaining time. If the time limit is reached and the user's hard disk usage exceeds the limit, the system will not allow the user to apply for hard disk resources.

After understanding these two concepts, we can configure the hard disk quota service. First, we must create a file named quotas under the root directory of the file system to be restricted, the owner of the file should be root, and other users cannot write the file. The method is:
# Cd/home (enter the root directory of the file system. Note that it is not the root directory of the system. In this example, it is the/home directory)
# Touch quotas (create an empty file named quotas)
# Chmod 644 quotas (change file attributes so that only root can perform write operations on it)

Then, edit the/etc/vfstab file, find the file system for Hard Disk Quota service, and set
Set the value of the mount option field to rq and save the disk and exit.

After completing these two steps, we use the edquota command to set the hard disk quota for each user. Run the following command under the root permission:
# Edquota username
At this time, the system will automatically generate a temporary file with the following content:
Fs/users blocks (soft = 0, hard = 0) inodes (soft = 0, hard = 0)
The fs Field indicates the file system that uses the hard disk quota. In this example, It is/users. block and inodes indicate the number of kilobytes of hard disks and the number of I nodes that can be used by users, that is, the user can use the hard disk space and the number of files that can be created, soft and hard respectively for the above mentioned soft restrictions and hard restrictions.

Edit this file, set the soft and hard limits to the appropriate values, and then save the disk and exit. At this time, we can see that the size of the quotas file has been changed, indicating that the user's quota has been stored. Repeat this command to configure the hard disk quota for each user. In addition, if the disk quota assigned to users is the same, we can use the "-p" parameter instead of editing a file for each user. The usage is as follows:
# Edquota-p reference-username

After editing the file, we can use quotaon to start the service and enter
# Quotaon/users
You can start the quota service. If you want to view the current usage of each user, you can use
Run the repquota command and enter:
# Repquota/users
The system displays:

From this, we can easily see the usage of users' hard disks and files, and the time when resources can still be applied after exceeding the soft limit.

Of course, we can use quotaoff to cancel the hard disk quota service. In addition, the system also provides the quotacheck command to check the quota consistency.

3. ifconfig command

The ifconfig command is used to view and change the IP address and parameters of a network interface. to display the IP address of a UNIX host, enter:
$ Ifconfig-
The system displays the network interface name, interface status (up or down), interface IP address and mask information.

If you want to change the IP address of the network interface, you can enter:
# Ifconfig hme0 down
# Ifconfig hme0 202.1.2.3 netmask limit 255.0 up
First, use the down command parameter to temporarily stop the hme0 service of the network interface, 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.

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

When the system starts, the network interface service is automatically started. You do not need to manually create the network interface service. However, after we change the network adapter or add a network interface, the system cannot automatically start this interface service. In this case, you need to manually create the network port service and enter:
# Ifconfig hme0 plumb
You can create a network port service for the interface le0.
Correspondingly, ifconfig with the unplumb parameter can be used to stop the service and disable the network interface. In this case, we can use the ifconfig-a command to disable the network interface.

4. format command
Format is also an important system management command, but because it is extremely destructive, you must be careful when using it. The format command is mainly used to format the hard disk and re-partition the hard disk:
1) format the hard disk
Like DOS, UNIX hard disks also need to be formatted before they are used. Before formatting them, we need to restart the system as a single user.
# Reboot-s
After the startup, log on as the root user and enter the following command line:
# Format
The System Displays all hard disks and allows us to select the hard disks to be formatted:

In this example, the system has two SUN2.1G hard disks. Select 1 and press Enter. The following menu is displayed:

Enter type at the prompt to select the hard disk type. The system will list the supported hard disk types, select the appropriate hard disk type, and enter the corresponding code (you can also enter 0 for the system to automatically detect ). After selecting the hard disk type, you can configure hard disk partitions. For details about partition operations, see "2) repartition.

After the configuration is complete, enter the format command for formatting, which takes a certain amount of time. The length of time is affected by the machine model and hard disk size. After formatting, you can enter the quit command to exit.

After the hard disk is formatted, it cannot be used immediately. We also need to create a file system on it and use the newfs command to create a file system for each partition:
# Newfs/dev/rdsk/c0t1d0s0
# Newfs/dev/rdsk/c0t1d0s1
...
The specific value of the parameter is set based on the partition.

In addition, if the hard disk contains a boot partition (root partition), we need to manually install the boot module. Before installation, we must first have a UNIX system installation disc. After we start the disk, mount the system root partition and install the boot module from the CD. The procedure is as follows:
# Reboot cdrom-s (starts from the disc and enters single-user mode)
# Mount/dev/dsk/c0t1d0s0/mnt (mount the system root partition to the mnt directory)
# Cp/ufsboot/mnt
# Installboot/lib/fs/ufs/bootblk/dev/rdsk/c0t1d0s0 (install the startup module)
# Umount/mnt (detach and attach)
# Reboot)

So far, the hard disk formatting operation has been completed, and we can use the hard disk.
2) repartition
The format command can also be used to repartition the hard disk. After partitioning, all files in the affected partition will be cleared. Therefore, before performing this operation, we must back up the file system first. The method for re-partitioning is as follows:
First, we need to enter the form of a single user and use the root user to log on, and then enter in the command line:
# Format
The system displays all the hard disks and allows us to select a hard disk: Select 0 and press Enter. The system displays the following menu:
Enter partition, then enter modify, and press Enter. The system prompts you to select partitioning base, select 1, and press Enter. The system will display:

We use partition 6 as a free partition, which means that if the size of other partitions changes, free partition 6 is used as the accumulation or reduction of hard disk space. Enter the expected partition value as required by the system. format automatically adjusts the cylindrical boundary of the partition so that there is no gap between each partition. Press enter to confirm the partition table, name the partition table, and then exit the format command.
After the partition is complete, run the newfs command to create a file system for the changed partition.
# Newfs/dev/rdsk/c0t0d0s6
Copy the backup file back to complete the change of the hard disk partition.

Once again, the format command is extremely destructive and can easily cause data loss or even system crashes. Therefore, be careful when using it.

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

The fsck syntax is as follows:
Fsck (-F fstype) (-v) (-m) (-special ...)
Fsck (-F fstype) (-v) (-y | Y | n | N) (-o fstype options) (special ...)
Where:
-F fstype: specifies the type of the file system to be checked.
-V: returns the completed command line, but does not run it.
-Y | Y: Yes for all questions
-N | N: No for all questions
-M: checks the file system and does not repair the file system. If the file system has been checked, it can be installed.
Ufs fsck: sanity check:/dev/rdsk/c0t0d0s0 okay.
-O: Specifies the file system type options. The options are separated by commas. The most common options are:
P: Sorting (preen) Mode
F: force check mode. This option ignores the file system status flag.

After running fsck, the command checks the file system in six phases:
Phase 1: Check the block size and block size
Phase 2: Check the path name
Phase 3: Check connectivity
Phase 4: Check the reference count
Phase 5: Check the free Block List
Phase 6: Free block remediation list

When fsck checks each stage, if an error is found, the user is prompted to modify it. Common Errors include:
1) Remove a directory entry with no relevant files

In this case, you can answer Yes or Y to delete the directory entry.
2) reconnect an allocated but inaccessible file:
Fsck finds an allocated I node, but it is not accessible (this node is not connected to any directory). In this case, the "RECONNECT? "Answer Yes: 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 and determine the purpose of the file, copy the file to the corresponding directory.

3) connections Adjustment
In the interactive mode, if The fsck finds that the number of connections is inconsistent, it will ask the user what action to take. In this example, the number of I node connections in a directory is different from the actual number of connections in the directory.

In this case, the user should answer Yes or Y to correct the number of connections.

4) The free block table is inconsistent.
Fsck finds that the number of unallocated blocks is inconsistent with the number of free block tables in the super block.

In this case, the user should answer Yes or Y to correct the superblock.

From the above error information and handling methods, we can find that you can use Yes to answer questions asked by fsck in most cases. Therefore, in actual application, you can run the "-y" option to check the hard disk.
Query and repair.
6. route command
The route command is mainly used to manually configure static route tables. For example, if you want to add a route entry to the sub-network through the gateway, the command is as follows:
# Route add net remote_net_ip gateway_ip 1
"Add" indicates that a route is to be added. "net" indicates that the route is sent to a network instead of a host. "1" indicates that the remote network can only be reached through the gateway, instead of directly connecting to it (this parameter is 0 when it is directly connected through a network interface ).

In Solaris 2.6, you can also use the following command:
# Route add-net remote_net_ip gateway_ip-netmask
# Route add-host host_ip local_interface_ip-interface
The first command is the same as the preceding command to complete the same task, and the second command is to create a route to reach another host through a network interface.

Of course, we can use the "delete" and "change" command parameters to delete and modify route information in the route table.
After executing the route command, can we? Quot; netstat-rn "command to view the current route information:

The routing table shows that there are currently five routes. The routes that reach 224.0.0.0 and 127.0.0.1 are both broadcast routes and local routes, which are set by default by the system. The route to host 202.77.111.22 is connected through the local network interface. The route to network 202.77.112.0 is connected through the gateway 202.77.111.1.
After the route table is configured through route, the route information will be saved until the next system restart. After the system restarts, You need to reconfigure the route table. You can set some default routes by modifying the/etc/defaultrouter file. These routes are added to the routing table each time the system starts, rather than using the route command to configure the route table at each start. The format of the/etc/defaultrouter file is as follows:
$ Cat/etc/defaultrouter
202.77.111.1
This file now has only one default route, and the IP address is 202.77.111.1. This means that the system will send all packets that do not belong to the local network through the gateway 202.77.111.1.
Sometimes the defaultrouter file does not exist in the/etc directory after the UNIX system is installed. In this case, you can manually create the file, edit the default route, and restart it. After the system starts, the configured default route information is automatically used.

Iii. UNIX System Management FAQs and Solutions
1. Forget the root password.

The root user is also called a Super User. It is the user with the highest permissions. Once its password is forgotten, it will bring many difficulties to system maintenance and management, the following describes how to handle root Password loss:

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

After the system starts, we need to mount the root partition of the hard disk to the/mnt directory of the CD file system and execute:
# Mount/dev/dsk/c0t0d0s0/mnt
(Assume that the root file system is/c0t0d0s0)
Edit the shadow file in the root partition of the hard disk and set the location of the root password item to null.
# Cd/mnt/etc
# Vi shadow

Note: Some systems need to edit the/etc/passwd file instead of the/etc/shadow file.

After changing the file, remove the mounted root file system.
# Umount/mnt

Restart the system and set a new root password.
2. The system cannot be started.
The reason why the system cannot be started is roughly as follows:
1) wrong boot device
If the system cannot be booted because an incorrect boot device is specified, we can use probe-scsi at the PROM monitoring level ", run the "probe-scsi-all" and "probe-ipi" commands to check whether a device is connected.
Go to the system and get the devalias name of the Startup Device. When the system starts, press the "STOP" key and "a" key at the same time. Then, the system prompts OK>, indicating that the system is currently in the PROM
Monitoring level.

Use printenv to display the current configuration. If the boot device is incorrect, use setenv to reset the settings:
OK> setenv boot-device devalias

Use the reset command to restart the system or set-defaults to restore the default value.

2) Missing Important system files or invalid files
In this case, you can use the "-a" option to guide the system. The system will provide an interactive boot process.
When the file is reached, the system prompts the user to give the appropriate file name.

3) The key system file is missing or the file is invalid.
For example, if the/etc/passwd file is missing, the system may guide the file, but no user can register it. The solution is to start with a CD, mount the root file system, and edit the/etc/passwd file.

4) remote file systems cannot be mounted.
When the system starts, the/etc/vfstab file will be automatically executed. If there is a remote file system that cannot be mounted in the file, the system will remain in the waiting and retry status and cannot enter the logon interface. The solution is to start it with a single user, edit the/etc/vfstab file, and delete the wrong mounting content.
3. Invalid keyboard

If the keyboard fails, that is, the user enters information on the keyboard and the screen does not respond, first check the hardware connection, that is, check whether the connection between the keyboard and the host is complete, whether the connection wire is broken or damaged.
If the hardware connection is correct, check whether the screen lock command is accidentally used. Press Ctrl + q. If the system responds, the reason is that the screen is temporarily locked by pressing ctrl + s. After the screen is locked, the user's input information from the keyboard is not displayed, but the entered information can still be executed.
If the system still does not respond, restart the system, enter the PROM status, enter the printenv command, and view the value of the input device item. If the value is not a keyboard, use
OK> setenv inputdevice keyboard
To make the keyboard an input device, and then restart the system again, then the system will respond to user input.

4. cron or at commands cannot be executed.

The UNIX system does not allow any user to use cron for Job Scheduling. There are two files restricted to the user:/etc/cron. d/cron. allow and/etc/cron. d/cron. deny.
If the user name is added to/etc/cron. d/cron. the user is allowed to use cron in the allow file, but not in the file. If the user is added to the/etc/cron file. d/cron. in deny, the user cannot use cron. Other users can use cron. You can configure a file as needed.
If you are allowed to use cron, you can use the command
$ Crontab myCronFile
Install your job scheduling control file in the/var/spool/cron/crontabs directory of the system.
At is similar to cron. To use at, you must configure the/etc/cron. d/at. allow or/etc/cron. d/at. deny file.

5. root logon is not allowed during Telnet.

By default, for security reasons, UNIX systems are not allowed to log on to terminals other than the console as root. Therefore, sometimes, when we use Telnet to log on as root
"Not on system console"
In this case, you can modify the/etc/default/login file to allow the root user to log on via Telnet. The specific method is to edit the login file and find the following line:
CONSOLE =/dev/console
Comment out this line, that is, add the "#" character at the beginning of the line, save the disk and exit. When you use Telnet again, the root user can log on.
6. Directory Access Permissions

We all know that every file in a UNIX system has the corresponding access permission. The system controls the user's access to the file based on this permission, and the directory in the UNIX system also has the corresponding access permission, however, its definition is somewhat different from that of a file.

Read Permission:
The read permission on the directory indicates that you can view the contents of the Directory, that is, you can use commands such as "ls" for the directory.

Write Permission:
The write permission on the directory indicates that you can create a new file or delete the file in the directory, regardless of whether the user has the write permission on the file.

Execution permission:
The execution permission indicates that you can search for files in the directory, that is, you can use the files in the directory with the corresponding access permissions.

Iv. Summary
The management and maintenance commands described above are only a small part of the UNIX system maintenance and management commands. UNIX also provides many other useful commands, which requires constant learning and research at work.

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.