Linux-정시 작업(백업) - 프로세스 관리 - 백엔드 화면 관리 - ssh
32707 단어 linux 기반
crond
: , ,
: ,
타이밍 작업 관련 파일
[root@qls ~]#
[root@qls ~]# ll /etc/cron* -d
drwxr-xr-x. 2 root root 21 Aug 14 15:11 /etc/cron.d
drwxr-xr-x. 2 root root 42 Aug 14 15:12 /etc/cron.daily #
-rw-------. 1 root root 0 Apr 11 2018 /etc/cron.deny #
drwxr-xr-x. 2 root root 22 Aug 14 15:11 /etc/cron.hourly #
drwxr-xr-x. 2 root root 6 Jun 10 2014 /etc/cron.monthly #
-rw-r--r--. 1 root root 451 Jun 10 2014 /etc/crontab #
drwxr-xr-x. 2 root root 6 Jun 10 2014 /etc/cron.weekly #
/var/spool/cron/ #
[root@qls ~]# ll /var/log/cron #
[root@qls ~]# cat /etc/crontab
SHELL=/bin/bash #
PATH=/sbin:/bin:/usr/sbin:/usr/bin #
MAILTO=root #
# For details see man 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
* # ,
- # ,1-5
, # ,1,5
*/5 # 5
00 02 * * * # 2
00 02 1 * * # 1 2
00 02 14 2 * # 2 14 2
00 02 * * 7 # 2
00 02 * 6 5 # 6 2
00 02 14 * 7 # 14 2
00 02 14 2 7 # 2 14 2
*/10 02 * * * # 2
* * * * * #
00 00 14 2 * # 2 14 12
*/5 * * * *
00 02 * 1,5,8 *
00 02 1-8 * *
00 21 * * *
45 4 1,10,22 * *
45 4 1-10 * *
3,15 8-11 */2 * *
0 23-7/2 * * *
15 21 * * 1-5
crontab #
-e # vim /var/spool/cron/username
-l # cat
-r #
-u # ,
분당 정시 동기화 시스템 시간
#
[root@qls ~]# yum install ntpdate -y
#
[root@qls ~]# date
Wed Aug 21 09:17:11 CST 2019
[root@qls ~]# ntpdate ntp.aliyun.com
21 Aug 09:17:59 ntpdate[8071]: adjust time server 203.107.6.88 offset 0.031011 sec
[root@qls ~]# date
Wed Aug 21 09:18:04 CST 2019
[root@qls ~]# date -s 2019/08/01
Thu Aug 1 00:00:00 CST 2019
[root@qls ~]# ntpdate ntp.aliyun.com
21 Aug 09:18:39 ntpdate[8074]: step time server 203.107.6.88 offset 1761503.866272 sec
[root@qls ~]# date
Wed Aug 21 09:18:45 CST 2019
#
[root@qls ~]# crontab -l
#sync time
* * * * * ntpdate ntp.aliyun.com
# ,
[root@qls ~]# tailf /var/log/cron
Aug 21 09:20:43 qls crontab[8077]: (root) REPLACE (root)
Aug 21 09:20:43 qls crontab[8077]: (root) END EDIT (root)
Aug 21 09:20:49 qls crontab[8080]: (root) LIST (root)
Aug 21 09:21:01 qls CROND[8083]: (root) CMD (ntpdate ntp.aliyun.com)
Aug 1 00:00:47 qls CROND[8095]: (root) CMD (ntpdate ntp.aliyun.com)
# ,
[root@qls ~]# date
Thu Aug 1 00:00:58 CST 2019
#
[root@qls ~]# tailf /var/mail/root
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
Message-Id: <[email protected]>
Date: Thu, 1 Aug 2019 00:02:01 +0800 (CST)
/bin/sh: ntpdate: command not found #
#
[root@qls ~]# crontab -e
#sync time
* * * * * /usr/sbin/ntpdate ntp.aliyun.com
# ,
[root@qls ~]# date
Wed Aug 21 09:26:32 CST 2019
# ,
[root@qls ~]# ll /var/mail/root
-rw-------. 1 root mail 10447 Aug 21 09:30 /var/mail/root
You have new mail in /var/spool/mail/root
#
[root@qls ~]# systemctl stop postfix
#
[root@qls ~]# ll /var/spool/postfix/maildrop/
total 12
-rwxr--r--. 1 root postdrop 600 Aug 21 09:32 2250C400DE75
-rwxr--r--. 1 root postdrop 599 Aug 21 09:33 4D709400DE76
-rwxr--r--. 1 root postdrop 599 Aug 21 09:31 E884E400DE61
#
[root@qls ~]# crontab -e
#sync time
* * * * * /usr/sbin/ntpdate ntp.aliyun.com &>/dev/null
#
#
[root@qls ~]# systemctl start postfix
# 。
[root@qls ~]# ll /var/mail/root
-rw-------. 1 root mail 14945 Aug 21 09:36 /var/mail/root
:
시간에 따라 파일에 시간 정보를 추가합니다.
[root@qls ~]# crontab -l
#sync time
* * * * * /usr/sbin/ntpdate ntp.aliyun.com &>/dev/null
#
* * * * * /usr/bin/date +%F_%T >> /root/time.txt
# , +
[root@qls ~]# tailf /var/log/cron
Aug 21 10:03:01 qls crond[7032]: (root) RELOAD (/var/spool/cron/root)
Aug 21 10:03:01 qls CROND[8583]: (root) CMD (/usr/bin/date +)
Aug 21 10:03:01 qls CROND[8586]: (root) CMD (/usr/sbin/ntpdate ntp.aliyun.com &>/dev/null )
#
[root@qls ~]# crontab -e
#sync time
* * * * * /usr/sbin/ntpdate ntp.aliyun.com &>/dev/null
#
* * * * * /usr/bin/date +\%F_\%T >> /root/time.txt
#
[root@qls ~]# tailf /var/log/cron
Aug 21 10:05:01 qls crond[7032]: (root) RELOAD (/var/spool/cron/root)
Aug 21 10:05:01 qls CROND[8614]: (root) CMD (/usr/sbin/ntpdate ntp.aliyun.com &>/dev/null )
Aug 21 10:05:01 qls CROND[8615]: (root) CMD (/usr/bin/date +%F_%T >> /root/time.txt )
:
, , %,
정시 백업 데이터
/etc/
etc_2019-08-21_10-09.tar.gz
var_2019-08-21_10-09.tar.gz
[root@qls ~]# vim back.sh
#!/bin/bash
Time=$(date +%F_%H-%M)
mkdir -p /backup
cd /
tar czPf /backup/etc_${Time}.tar.gz etc/
find /backup -type f -mtime +3 -delete
[root@qls ~]# for i in {15..21} ;do date -s "2019/08/$i" && sh back.sh ;done
[root@qls ~]# crontab -e
#sync time
* * * * * /usr/sbin/ntpdate ntp.aliyun.com &>/dev/null
#
* * * * * /usr/bin/date +\%F_\%T >> /root/time.txt
#backup /etc
* * * * * /bin/sh /root/back.sh &>/dev/null
[root@qls ~]# ll /backup/
total 9980
-rw-r--r--. 1 root root 10215613 Aug 21 10:25 etc_2019-08-21_10-25.tar.gz
#
[root@qls ~]# vim back.sh
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
Time=$(date +%F_%H-%M)
mkdir -p /backup
cd /
tar czPf /backup/etc_${Time}.tar.gz etc/
find /backup -type f -mtime +3 -delete
정해진 시간에 임무를 어떻게 백업합니까
/var/spool/cron/root # , ,
사용자가 정해진 시간 작업을 사용하는 것을 어떻게 금지합니까
echo 'oldboy' >>/etc/cron.deny
연습 문제
1. oldboy.txt 。
#
* * * * * command
2. 8 12 , /scripts/test.sh 。
#
00 8-12 * * 6 command
3. 1 , /scripts/oldboy.sh
00 01 1 * * command
4. 10 1 7 , /scripts/holiday.sh
00 01 1-7 10 * command
5. 9 11 , /scripts/test.sh
00 9,11 * * * command
정시에 어린 언니에게 사랑의 편지를 보내다.
#
yum install -y mailx
# vi /etc/mail.rc
set from=[email protected]
set smtp=smtp.qq.com
set smtp-auth-user=[email protected]
set smtp-auth-password=' '
set smtp-auth=login
set smtp=smtps://smtp.qq.com:465
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb/
#
echo ' ' |mail -s 'Hello' [email protected]
프로세스 관리
[root@qls ~]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
:
: pid
: CPU
:
:
:
:
:
:
: CPU
11 :
[root@qls ~]# top
top - 11:46:57 up 3:14, 2 users, load average: 0.68, 0.24, 0.12 # 1 5 15
Tasks: 106 total, 1 running, 105 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 5.4 sy, 0.0 ni, 94.6 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 2028088 total, 1097584 free, 113832 used, 816672 buff/cache
KiB Swap: 2097148 total, 2097148 free, 0 used. 1709956 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
: 11:46:57 3:14, 2 users
: , ,
ps #
top #
htop # top
glances #
iotop
iostat
netstat -lntp #
ss #
#
[root@qls ~]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.0.0.2 0.0.0.0 UG 0 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
172.16.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
[root@qls ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.2 0.0.0.0 UG 100 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
172.16.1.0 0.0.0.0 255.255.255.0 U 101 0 0 eth1
# tcp 11
[root@qls ~]# netstat -ant
[root@qls ~]# ss -ant
#
[root@qls ~]# nmap -p1-100 10.0.0.100
[root@qls ~]# kill 10466 #kill pid -9 -1
,
[root@qls ~]# killall vim #killall
,
[root@qls ~]# pkill top # ,
백그라운드 관리
screen #
-S #
-r #
ctrl a +d
SSH
1.
2.
Telnet tcp/23 root
ssh tcp/22 root
Telnet
#
[root@qls ~]# yum install -y telnet-server
#
[root@qls ~]# systemctl start telnet.socket
#
[root@qls ~]# netstat -lntp |grep 23
#
[root@qls ~]# useradd test
[root@qls ~]# echo '123' |passwd --stdin test
Changing password for user test.
passwd: all authentication tokens updated successfully.
#
[root@qls ~]# telnet 10.0.0.100
Trying 10.0.0.100...
Connected to 10.0.0.100.
Escape character is '^]'.
Kernel 3.10.0-957.el7.x86_64 on an x86_64
qls login: root
Password:
Login incorrect
qls login: root
Password:
Login incorrect
qls login: test
Password:
Last login: Wed Aug 21 14:53:34 from ::ffff:10.0.0.1
[test@qls ~]$
ssh 관련 명령
scp #ssh
ssh #
ssh-keygen #
ssh-copy-id #
#
[root@qls ~]# scp -rp nginx-1.16.1.tar.gz [email protected]:/root
The authenticity of host '10.0.0.7 (10.0.0.7)' can't be established.
ECDSA key fingerprint is SHA256:UJfXPNHA1tsUI9NsyZWwf2/IF/NcEErY/iJ74f4NyR4.
ECDSA key fingerprint is MD5:c9:76:b4:5e:4f:51:5a:00:e0:ba:f0:d6:c5:17:b9:b5.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.7' (ECDSA) to the list of known hosts.
[email protected]'s password:
nginx-1.16.1.tar.gz
[root@qls ~]# ll
total 1016
-rw-------. 1 root root 1614 Aug 14 15:17 anaconda-ks.cfg
-rw-r--r--. 1 root root 1032630 Aug 14 01:01 nginx-1.16.1.tar.gz
#
[root@qls ~]# scp -rp [email protected]:/root/nginx-1.16.1 /root
#
[root@qls ~]# scp -P22 -rp nginx-1.16.1.tar.gz [email protected]:/root
[email protected]'s password:
nginx-1.16.1.tar.gz 100% 1008KB 92.8MB/s 00:00
# , kb
[root@qls ~]# scp -rp -l 8096 swap.txt [email protected]:/root
#
[root@qls ~]# hostnamectl set-hostname web01
[root@qls ~]# bash
[root@web01 ~]#
[root@web01 ~]#
[root@web01 ~]# cat /etc/hostname
web01
#
[root@qls ~]# ssh [email protected] -p22
#
[C:\~]$ ssh [email protected] 22
#
[root@web01 ~]# ssh [email protected] "ifconfig eth0"
[email protected]'s password:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.0.100 netmask 255.255.255.0 broadcast 10.0.0.255
inet6 fe80::52f8:a673:eea3:dc47 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:0d:42:09 txqueuelen 1000 (Ethernet)
RX packets 47639 bytes 43560570 (41.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 70530 bytes 131220281 (125.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
키 기반 연결
#1.
[root@qls ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:K/fUKgI3bNlQKbirzmPz3+UFWgHcr+j2OAiDBh8UghI root@qls
The key's randomart image is:
+---[RSA 2048]----+
|E... . ..o |
|o.. . . +.. |
|.. . o .. |
|. . . . .. |
| o o o +S.o. |
| + = * o+.o |
| . . *.++ o o |
| .= o+=* o |
| oo+...oo+= |
+----[SHA256]-----+
#2.
[root@qls ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.
#3.
[root@qls ~]# ssh [email protected]
Last login: Wed Aug 21 15:21:32 2019 from 10.0.0.1
[root@web01 ~]#
ssh 최적화
Port 6666 # SSH
PermitRootLogin no # root
PasswordAuthentication no #
UseDNS no # ssh dns , ssh
GSSAPIAuthentication no # GSS ,
o install the new keys [email protected]’s password:
Number of key(s) added: 1
Now try logging into the machine, with: “ssh ‘[email protected]’” and check to make sure that only the key(s) you wanted were added.
#3. 연결 테스트[root@qls ~]# ssh [email protected] Last login: Wed Aug 21 15:21:32 2019 from 10.0.0.1 [root@web01 ~]#
### ssh
```bash
Port 6666 # SSH
PermitRootLogin no # root
PasswordAuthentication no #
UseDNS no # ssh dns , ssh
GSSAPIAuthentication no # GSS ,
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Linux-정시 작업(백업) - 프로세스 관리 - 백엔드 화면 관리 - ssh타이밍 태스크 타이밍 작업 관련 파일 분당 정시 동기화 시스템 시간 시간에 따라 파일에 시간 정보를 추가합니다. 정시 백업 데이터 정해진 시간에 임무를 어떻게 백업합니까 사용자가 정해진 시간 작업을 사용하는 것을 어...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.