Linux Base Seventh Day (NFS service, scheduled task Crond service)

Source: Internet
Author: User
Tags log log parent directory crontab example

NFS Services

=============== Service Side

Introduced:

NFS is the abbreviation for the network file system, which is the web filesystem. A contract for the decentralized file system, developed by Sun, was announced in 1984. The function is to enable different machines, different operating systems to share individual data with each other, so that the application can access the data on the server disk through the network, and it is a way to implement disk file sharing among Unix-like systems.

The basic principle of NFS is to "allow different clients and services to share the same file system through a set of RPC", which is independent of the operating system, allowing different hardware and operating systems to share files together.

NFS relies on the RPC protocol during file transfer or information transfer. RPC, remote procedure invocation (Procedure call) is a mechanism that enables clients to perform programs in other systems. NFS itself does not provide the protocol and functionality for transmitting information, but NFS allows us to share information over the network, because NFS uses some other transport protocols. And these transport protocols are used for this RPC function. It can be said that NFS itself is a program that uses RPC. Or, NFS is also an RPC SERVER. So whenever you use NFS, you start the RPC service, whether it's NFS server or NFS CLIENT. This allows the server and client to implement the program port correspondence via RPC. You can understand the relationship between RPC and NFS: NFS is a file system, and RPC is responsible for the transfer of information.

Installation:

Yum Install Rpcbind nfs-utils-y

Configuration:

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: 192.168.0.200
    • Specify all hosts in the subnet: 192.168.0.0/24 192.168.0.0/255.255.255.0
    • Host of the specified domain name: david.bsmart.cn
    • Specify all hosts in the domain: *.bsmart.cn
    • 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, the NFS server does not check the permissions of its parent directory, which can improve efficiency;

Modify Configuration

[Email protected] nginx]# Cat/etc/exports
/share 192.168.31.0/24 (rw,sync,fsid=0)

Open Permissions (NFS does not open the W permission, others also need to have W permissions to the/share directory)

Chmod-r O+w/share

Start booting for Rpcbind and NFS first:

[Email protected] nginx]# Systemctl enable Nfs-server.service
[Email protected] nginx]# Systemctl enable Rpcbind.service

Start (Rpcbind service must be started first)

[Email protected] nginx]# systemctl start Rpcbind.service
[Email protected] nginx]# systemctl start Nfs-server.service

Confirm that the NFS server started successfully

[Email protected] nginx]# rpcinfo
[Email protected] nginx]# Exportfs
/share 192.168.31.0/24

[[email protected] nginx]# showmount-e #默认查看自己共享的服务, if the DNS can resolve their own, otherwise prone to error
Export list for miwifi-r3-srv:
/share 192.168.31.0/24

[Email protected] nginx]# showmount-a #显示已经与客户端连接上的目录信息
All mount points on Miwifi-r3-srv:

===================== Client

Yum Install Rpcbind nfs-utils-y

Systemctl Enable Rpcbind.service && systemctl start Rpcbind.service

SHOWMOUNT-E NFS Server IP #检查 NFS server-side directory sharing
Mount-t NFS 192.168.31.106:/share/var/www/html/

===================== Test
Based on the Nginx load Balancer configuration, open the backend is Proxy service Access.log log, tail-f Access.log to observe access, Access lb refresh page to find content consistency, but each agent machine's Access.log log has new content come in

Scheduled Task Crond Service

What is a scheduled task:
Running in the background, the task will be performed automatically at the scheduled time, provided that the scheduled task is manually set up beforehand. This is where the Crond service is used.

Crond Service-related packages
[Email protected] ~]# Rpm-qa |grep cron
Cronie-anacron-1.4.11-14.el7.x86_64
Crontabs-1.11-6.20121102git.el7.noarch
Cronie-1.4.11-14.el7.x86_64

These packages are installed when the system is minimized, and are powered on from the Crond service and provide us with crontab commands for writing 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 #查看全局计划任务
Shell=/bin/bash
Path=/sbin:/bin:/usr/sbin:/usr/bin
Mailto=root

# 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

Parameters
-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.

Attention:

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 210.72.145.44 #每半小时同步一下时间

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


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

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

* * * */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 210.72.145.44 #每半小时同步一下时间

Linux Base Seventh Day (NFS service, scheduled task Crond service)

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.