Unit 19th NFS Service
=============== 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
Unit 20th 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 #每半小时同步一下时间
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:
/etc/cron.hourly
/etc/cron.daily
/etc/cron.weekly
/ect/cron.mouthly
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
Cat/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: http://blog.csdn.net/jbgtwang/article/details/7995801
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.
Ninth
* * * * * tar czf/tmp/' date ' +%y '/etc The execution flow of the command in the scheduled task is the Crond->tar command, and Crond does not recognize the meaning of the wildcard% when executing the tar command (the shell can recognize), So the command is not performing properlyCorrection Result: * * * * * tar czf/tmp/' date ' +\%y '/etcusually the action to be performed is put into the file, and then/bin/bash a.sh to execute, * * * * * */bin/bash a.sh, the execution process becomes Crond->bash shell->a.sh, so a.sh even if the write %, can also be identified
Linux (8)