Linux Operating System Fundamentals (vii)

Source: Internet
Author: User
Tags parent directory crontab example

Linux Service (ii) 1.NFS service construction


Yum Install Rpcbind nfs-utils-y


The NFS service configuration file is/etc/exports, which is the primary NFS configuration file, but the system does not have a default value, so this file does not necessarily exist, it may be created manually using Vim, and then write the configuration content in the file.

/etc/exports File Content format:

< output directory > [Client 1 options (access rights, user mappings, others)] [Client 2 options (access rights, user mappings, others)]

A. Output directory:

The output directory is the directory that the NFS system needs to share with the client;

B. Client:

A client is a computer in the network that can access this NFS output directory

Common ways for clients to specify

    • Specify the IP address of the host:
    • Specify all hosts in the subnet:
    • Host of the specified domain name:
    • Specify all hosts in the domain: *
    • All hosts: *

C. Options:

option to set the access permissions, user mappings, and so on for the output directory.

There are 3 main types of NFS options:

Access Permissions Options

    • Set output Directory read-only: RO
    • Set output directory Read/write: RW

User mapping Options

    • All_squash: Maps all normal users and groups that are accessed remotely to anonymous users or user groups (Nfsnobody);
    • No_all_squash: Reverse with All_squash (default setting);
    • Root_squash: The root user and the owning group are mapped to anonymous users or groups of users (default setting);
    • No_root_squash: Reverse with Rootsquash;
    • ANONUID=XXX: Maps All remote access users to anonymous users and specifies that the user is a local user (uid=xxx);
    • ANONGID=XXX: Maps All remote Access user groups to anonymous user group accounts and specifies that the anonymous user group account is a local user group account (GID=XXX);

Other options

    • Secure: Restrict clients from connecting to Server for NFS (default setting) only from TCP/IP ports less than 1024;
    • Insecure: Allow clients to connect to the server from TCP/IP ports greater than 1024;
    • Sync: It is inefficient to write data synchronously to memory buffer and disk, but it can guarantee the consistency of data;
    • Async: Save the data in the memory buffer first, and write to disk if necessary;
    • Wdelay: Check if there is a related write operation, if any, then perform these writes together, which can improve the efficiency (default setting);
    • No_wdelay: If a write operation is performed immediately, it should be used in conjunction with sync;
    • Subtree: If the output directory is a subdirectory, the NFS server will check the permissions of its parent directory (default setting);
    • No_subtree: Even if the output directory is a subdirectory, Server for NFS does not check the permissions of its parent directory, which can improve efficiency

Modifying a configuration file


/share (rw,sync,fsid=0)

Mkdir-p/share Creating a shared directory

chmod +r o+w/share Add Read permissions for other people in shared directory

Systemctl Restart NFS Restart service

SHOWMOUNT-E Viewing shared Lists

Client Configuration

Mount-t (local directory) #共享目录挂载到本地目录

2.crontab Configuration of Scheduled Tasks

Scheduled tasks fall into two categories: system-level and user-level

The first thing to know is that both the system level and the user-level cron program are text files, and the system's plan files are stored under the/etc/crontab path. The user's plan file is placed in the/var/spool/cron/user name, either of which can meet the needs of our custom scheduled tasks.

Root users can modify files directly to write scheduled tasks or use the CRONTAB-E command, which is only available to ordinary users. In addition, the definition of tasks in the system Crontab file is different, and a "user" section is inserted after the first five sections.

[Email protected] ~]# Cat/etc/crontab #查看全局计划任务

# for details see Mans 4 Crontabs

# Example of Job definition:
#.----------------Minute (0-59)
# |.-------------Hour (0-23)
# | |.----------DAY of Month (1-31)
# | | |.-------month (1-12) OR jan,feb,mar,apr ...
# | | | |.----DAY of Week (0-6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * * user-name command to be executed
* * * * * * root run-parts/test #run-parts command, you can execute all the executable files in a directory, the file must have Execute permission

You have new mail in/var/spool/mail/root

[Email protected] ~]# crontab-u tom-l #通过命令查看用户tom的计划任务
*/1 * * * * echo 123213123213

[Email protected] ~]# Cat/var/spool/cron/tom #从文件中查看用户tom的计划任务
*/1 * * * * echo 123213123213

Crontab commands to write scheduled tasks

Syntax: crontab [-u < user name >][profile] or crontab [-u < user name >][-ELR]

Crontab task Configuration Basic format:
* * * * * command
Minutes (0-59) hours (0-23) Date (1-31) month (1-12) week (0-6, 0 for Sunday) command

The 1th column represents minutes 1~59 per minute with * or */1
The 2nd column represents the hour 1~23 (0 means 0 points)
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
5th Column Identification Number Week 0~6 (0 = Sunday)
6th List of commands to run

-e Edit the user's timer settings.
-l lists the user's timer settings.
-R removes the user's timer settings.
-u< User name > Specifies the user name to set the timer.


1 Viewing the execution of scheduled tasks: Tail-f/var/log/cron

2 when writing a scheduled task, the command must be accompanied by an absolute path, otherwise this situation occurs: from the log, it does trigger the execution of the scheduled task, but the command does not succeed, such as * * * * * Reboot this situation, need to write reboot/usr/sbin/reboot

crontab Example:

* * * */usr/local/etc/rc.d/apache restart #每晚的21:30 restart Apache

4 1,10,22 * */usr/local/etc/rc.d/apache restart #每月1, 10, 22nd 4:45 Restart Apache

1 * * 6,0/usr/local/etc/rc.d/apache restart #每周六, Sunday 1:10 restart Apache

0,30 18-23 * * */usr/local/etc/rc.d/apache restart #每天18:00 to 23:00 restart Apache every 30 minutes

0 * * 6/usr/local/etc/rc.d/apache Restart #每星期六的11: PM Restart Apache

* 23-7/1 * * * */usr/local/etc/rc.d/apache restart #晚上11点到早上7点之间, restart Apache every one hours

0 */1 * * */usr/local/etc/rc.d/apache restart #每一小时重启apache

0 4 * Mon-wed/usr/local/etc/rc.d/apache restart #每月的4号与每周一到周三的11点重启apache

0 4 1 Jan */usr/local/etc/rc.d/apache restart #一月一号的4点重启apache

*/30 * * * * */usr/sbin/ntpdate #每半小时同步一下时间

0 */2 * * * www/usr/bin/somecommand >>/dev/null 2>&1 #以用户www的身份每两小时就运行某个程序:

0 1 * * */home/testuser/ #每天1点调用/home/testuser/

*/10 * * * * */home/testuser/ #每10钟调用一次/home/testuser/

* * * */usr/local/etc/rc.d/lighttpd restart #每天的21:30 Restart LIGHTTPD

4 1,10,22 * */usr/local/etc/rc.d/lighttpd restart #每月1, 10, 22nd, 4:45 restart LIGHTTPD

1 * * 6,0/usr/local/etc/rc.d/lighttpd Restart # 1:10 restarts per Saturday, Sunday lighttpd

0,30 18-23 * * */usr/local/etc/rc.d/lighttpd restart #上面的例子表示在每天18:00 to 23:00 restart Apache every 30 minutes.

0 * * 6/usr/local/etc/rc.d/lighttpd Restart #上面的例子表示每星期六的11: PM Restart LIGHTTPD

* */2 * * * */usr/local/etc/rc.d/lighttpd restart #每两小时的每分钟重启lighttpd

0 23-7/1 * * */usr/local/etc/rc.d/lighttpd restart #晚上11点到早上7点之间, restart every hour lighttpd

0 4 * mon-wed/usr/local/etc/rc.d/lighttpd restart #每月的4号与每周一到周三的11点重启lighttpd

0 4 1 Jan */usr/local/etc/rc.d/lighttpd restart #一月一号的4点重启lighttpd

*/30 * * * * */usr/sbin/ntpdate #每半小时同步一下时间

For some common time formats, you can replace them in a @yearly way.

@reboot represents the meaning of run once, at startup.
@yearly the meaning of the delegate run once a year, "0 0 1 1 *".
@annually the same meaning as @yearly
@monthly the meaning of the delegate run once a month, "0 0 1 * *".
@weekly the meaning of the delegate run once a week, "0 0 * * 0".
@daily the meaning of the delegate run once a day, "0 0 * * *".
@midnight is the same as @daily's meaning
@hourly the meaning of the delegate run once an hour, "0 * * * * *".
In addition to this, the system also has some of its own scheduled tasks

Cron is configured by default to schedule tasks: hourly, daily, weekly, mouthly, default configuration file is/etc/anacrontab

Put the scripts that need to be executed in the appropriate directory, and the directories are:





See if the Cron service works:

If we want to see if the timed task is on time call the run information that can be/var/log/cron


You can also use the Tail-f/var/spool/mail/user name to view the normal user's scheduled task execution status

Here are two points to remember:

First: The cron daemon examines changes in/etc/crontab files, etc/cron.d/directories, and/var/spool/cron directories every minute. If a change is found, they will be loaded into memory. This way, you do not have to restart the daemon when a crontab file changes.

Second: Crontab's user manual recommends that each command use an absolute path, such as writing when calling the RM command:/BIN/RM, which prevents the command from being found because of a different PATH environment variable for each user.

The information crontab on the Internet is not implemented:

Transferred from:

First, the reason for the script: In most cases, we have to believe in science, believe that computers, not ghosts, is the problem of our script, this problem caused crontab can not execute the probability of more than 70%. Since the execution of the program to a certain step resulted in crontab terminating execution, I ran into the wrong database when I migrated the code. Causing the inability to access and died there.

Second, the implementation of environmental issues, when we encounter the first case, the general can be manually executed by the program to kill the problem in the cradle, in general, the master should not make the first mistake. The problem is that when we perform the manual execution successfully and the crontab cannot execute, the author encounters the problem of the execution environment, such as the setup problem of the related path. Solution: Execute source/home/user/.bash_profile at the front of the code

Thirdly, the system time is not correct. This problem is best understood, is also a more common and covert problem, solution: Date-s ********

The four is whether our script has executable permissions. You must ensure that the user executing the script has permission to perform the file change.

Five, the crontab daemon died. This is rarely the case, but it does not rule out that we can use it when we are unable to find other reasons. Solution: Restart the process.

Six, the problem that crontab does not carry on for a long time, the script writes is correct, but is not executed, the final solution is as follows:
Crontab-u Root/var/spool/cron/root
So the root user's crontab is in effect.
Service Crond Restart
Just restart the service.

VII, Crond did not start.

The script coding problem, script is written under window, to the Linux post-report "Nobelium?!" /bin/bash ", create a new shell script with the VI editor and save after entering the content.

Linux Operating System Fundamentals (vii)

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.