2018-04-25 "Bird Brother's Linux private cuisine Basic Study (fourth Edition)" 20th chapter basic System setting and backup strategy

Source: Internet
Author: User
Tags bz2 time zones locale session id set time time zone names rsync

Command directory
1, Ifconfig-a #列出所有网卡
2, Nmcli #设定网络参数
3, Timedatectl [COMMAMD] #时区的显示与设定
4, the time server on the Ntpdate network #手动网络校时
4, Hwclock-w #订正 the time of the BIOS record
5. Locale #查询目前的语系数据与变量
5, Localectl #查询目前的语系数据与变量
6, Firewall #防火墙的操作命令
7. DMIDECODE-T Type #解析硬件配备
8, Lspci [-VVN] #列出整个 PC System of the PCI interface device
9, Lsusb [-t] #USB端口状态
10, Iostat [-c|-d] [-k|-m] [-t] [interval seconds] [number of detections] #磁盘由开机到现在, how much data has been accessed
11, Smartctl #了解磁盘的健康状态.
Backup
Dd
Cpio
Tar
Xfsdump
Rsync



System basic settings and collection commands for server hardware data
1, Ifconfig-a #列出所有网卡


2, Nmcli #设定网络参数


2.1. NMCLI Connection Show #显示所有网卡
Show the meaning of the data column:
# NAME Online code, usually the same as the following Nic DEVICE.
# UUID Special device identification, keep it good ignore it.
# type of NIC, usually Ethernet card.
# DEVICE NIC name.

2.2, NMCLI connection show [NIC code] #显示 "network card Code" corresponding to the networking parameters
At the bottom of the IP4, IP6 refers to the current actual use of the network parameters, the top connection the beginning of the part refers to the status of the online. Other more important parameters:
? Connection.autoconnect [Yes|no]: Whether to start this online at boot time, the preset is usually yes.
? Ipv4.method [auto|manual]: Automatically or manually set the meaning of network parameters
? Ipv4.dns [DNS_SERVER_IP]:D NS IP Address ~
? ipv4.addresses [Ip/netmask]: A collection of IP and Netmask, separated by a slash/
? Ipv4.gateway [GW_IP]: The IP address of the gateway.

2.3, [[email protected] ~]# nmcli connection modify eth0 \
> Connection.autoconnect yes \
> Ipv4.method manual \
> Ipv4.addresses 172.16.1.1/16 \
> Ipv4.gateway 172.16.200.254 \
> Ipv4.dns 172.16.200.254 #自定义网络参数
[Email protected] ~]# NMCLI connection up eth0
[Email protected] ~]# NMCLI connection show eth0

2.4, [[email protected] ~]# nmcli connection modify eth0 \
> Connection.autoconnect yes \
> Ipv4.method Auto #设置IP参数为自动获取
[Email protected] ~]# NMCLI connection up eth0


3, Timedatectl [COMMAMD] #时区的显示与设定
COMMAMD:
Empty: Displays information such as current time zones and times
List-timezones: Lists all supported time zone names on the system
Set-timezone: Setting the time zone location
Set-time "Yyyy-mm-dd hh:mm": Set time
SET-NTP: Setting up the network time-of-school system

4, the time server on the Ntpdate network #手动网络校时
Hwclock-w #订正 the BIOS recording time


5. Locale #查询目前的语系数据与变量
/etc/locale.conf #语系的配置文件LANG =ZH_CN. UTF8 (the universal Code of Chinese), En_us.utf8 (the Universal Code in English)
Localectl #查询目前的语系数据与变量
example, the entire system language is changed to English:
[Email protected] ~]# Localectl Set-locale Lang=en_us.utf8
[Email protected] ~]# Systemctl isolate Multi-user.target
[Email protected] ~]# Systemctl isolate Graphical.target


6, Firewall #防火墙的操作命令


7. DMIDECODE-T Type #解析硬件配备
Options and Parameters:
Detailed type project please man Dmidecode query more data, here only the more commonly used items are listed:
1: Detailed system data, including the motherboard model and hardware basic data, etc.
4:CPU related data, including octave, FSB, core number, nuclear mood number, etc.
9: Slot Specification for system related slot formats, including PCI, PCI-E, etc.
17: The size of each memory slot, if there is memory, then list the capacity and model of the memory

Collection and analysis of hardware resources
The hardware devices detected by the core will be recorded in/proc and/sys. including/proc/cpuinfo,/proc/partitions,/proc/interrupts, etc.
In addition to directly calling out the contents of the file in the/proc directory, Linux also provides other commands to display the hardware detected by the core:
? Gdisk: The seventh chapter has been discussed, you can use Gdisk-l to list the partition table;
? DMESG: The 16th chapter has discussed, observes the core operation process to display each information record;
? Vmstat: In the 16th chapter, the present state of the analytical System (CPU/RAM/IO) is discussed.
? LSPCI: Lists the PCI interface devices for the entire PC system. Very useful instructions;
? LSUSB: List the current system above the status of each USB port, with the connected USB device;
? Iostat: Similar to Vmstat, the input/output status of the entire CPU and interface device can be listed in real time.

8, Lspci [-VVN] #列出整个 PC System of the PCI interface device
Options and Parameters:
Null: Displays the PCI bus-related device within the system. The data under the/proc/bus/pci/directory.
-V: Shows more details of the PCI interface device;
-VV: More detailed details than-V;
-N: Direct view of PCI ID instead of vendor name
Instance:
[[email protected] ~]# lspci-s 00:03.0-vv #显示以太网络卡更详细的信息,-S is followed by the bus, socket and related function functions of each device, related to the/usr/share/hwdata/pci.ids file
[[email protected] ~]# update-pciids #更新/usr/share/hwdata/[[email protected] ~]# pci.ids file


9, Lsusb [-t] #USB端口状态
Options and Parameters:
Null: Lists the current host USB ports port status
-T: Use a tree-like directory to display the correlation of individual USB port ports

10, Iostat [-c|-d] [-k|-m] [-t] [interval seconds] [number of detections] #磁盘由开机到现在, how much data has been accessed
Options and Parameters:
Null: Displays the current state of the CPU and storage device for the entire system
-C: Show only the state of the CPU
-D: Displays only the status of the storage device and cannot be used with-C
-K: block is displayed by default and can be changed to the size of K bytes to show
-M: Similar to-K, only displays the results in MB units
-T: Show date out
# Display data is divided into two parts, the upper part shows the current information of the CPU;
# The data below is the data that shows the storage device including the/dev/vda, his data meaning:
# TPs: Average number of transfers per second. Related to data transfer "number of times", non-capacity.
# kb_read/s: The average reading unit is switched on to the present;
# KB_WRTN/S: Power on to the current average write unit;
# Kb_read: Power up to now, a total of read out of the file units;
# Kb_wrtn: Power up to now, total written file units;
Instance:
[[email protected] ~]# iostat-d 2 3 SDA #仅针对 SDA, detected every two seconds, and a total of three storage devices detected

11, understand the health status of the disk. SMART is primarily used to monitor the current common ATA and SCSI interface disks. Abbreviation for "self-monitoring, analysis and Reporting technology System"
[Email protected] ~]# smartctl-a/DEV/SDA #显示完整的/DEV/SDA Information
[Email protected] ~]# smartctl-t SHORT/DEV/SDA #命令磁盘进行一次自我检测的动作


Third, backup
Backup reason: Due to the computer (especially the current computer, the operating frequency is too high, the hardware yield is too poor, the user's operating habits are bad, "some" operating system when the probability is too high ...) stability is poor.
Backups can be categorized as "full backup" or "Critical data backup."
It can also be divided into "cumulative backup" and "differential backup". Differential backups use more disk capacity than cumulative backups, but the restore of differential backups is faster because you only need to restore the full backup and the last differential backup.
Backups can also be used to periodically transfer backed-up data to other locations through the offsite redundancy system.
3.1. Full backup: Back up the root directory (/) entire system.
Common tools for full backup:
Tool 1, DD command. Ignoring the file system directly reads the disk sector (sector), a fairly good backup tool. The disadvantage is very slow.
# example: Use DD to fully back up the/DEV/SDA to a completely identical/dev/sdb hard drive:
[email protected] ~]# DD IF=/DEV/SDA of=/dev/sdb
# since DD is a read sector, the/DEV/SDB disk can not be formatted. It's very convenient!

Tool 2, Cpio command. Back up all file names, but you have to work with find or other instructions to find the file name to handle it properly.
# example: Use Cpio to fully backup and restore the entire system, assuming the storage media is a SATA tape drive:
[[email protected] ~]# Find/-print | Cpio-covb >/dev/st0 <== Backup to tape drive
[[email protected] ~]# Cpio-iduv </dev/st0 <== Restore

Tool 3, Tar command.
#实例:/backupdata is a standalone file system, does not back up unnecessary/proc,/MNT,/tmp directories, other data full backup:
[Email protected] ~]# tar--exclude/proc--exclude/mnt--exclude/tmp--exclude/backupdata-jcvp-f/backupdata/syste M.TAR.BZ2/
All of the above three are full backups, but a cumulative backup will have to be handled with additional scripting.

3.2, the full backup of the cumulative backup: The system after the first full backup, after a period of time operation, compare the system and backup files, the first cumulative backup is only the difference of files to backup. The second cumulative backup is compared to the data for the first cumulative backup, and only the data that has the difference is backed up. And so on
Assuming Monday is a good full backup, the system hangs in Friday. Cumulative backup Restore: You must restore the Monday full backup, then restore the Tuesday cumulative backup, and then restore the cumulative backup in Wednesday and Thursday in order to fully recover.
The Xfsdump command is backed up.
Xfsdump:usage:xfsdump [-A (Dump DMF dualstate files as offline)]
[-B <blocksize>]
[-C <media change alert program>]
[-D <dump media file size>]
[-E (Allow files to be excluded)]
[-f <destination> ...]
[-H (Help)]
[-L <level>]
[-m (Force usage of minimal RMT)]
[-O (Overwrite tape)]
[-P <seconds between progress reports>]
[-Q <use QIC tape settings>]
[-S <subtree> ...]
[-t <file> (use file mtime for dump time]
[-v <verbosity {silent, verbose, trace}>]
[-Z <maximum file size>]
[-A (don ' t dump extended file attributes)]
[-B <base dump session id>]
[-D (Skip unchanged directories)]
[-E (Pre-erase Media)]
[-F (Don ' t prompt)]
[-I (Display dump inventory)]
[-j (Inhibit inventory update)]
[-K (Generate Format 2 dump)]
[-L <session label>]
[-M <media label> ...]
[-O <options file>]
[-R (Resume)]
[-T (don ' T timeout dialogs)]
[-y <i/o buffer ring length>]
[-(STDOUT)]
[<source (Mntpnt|device) >]
instance,/home is a standalone file system, and/backupdata is also a standalone file system for backup, using the dump to make a full backup of/home to/backupdata:
[[email protected] ~]# xfsdump-l 0-l ' full '-m ' fully '-f/backupdata/home.dump/home <== complete backup
[[email protected] ~]# xfsdump-l 1-l ' full-1 '-M ' full-1 '-f/backupdata/home.dump1/home <== first time cumulative backup

3.3, the full backup of the differential backup: After the first full backup, after a period of operation, each backup is compared with the original full backup results. The longer the system works, the longer it takes to complete the backup, the larger the differential backup data will be.
Restore: Restores the full backup and restores the last differential backup.
Backup tool:
Tool 1, the Xfsdump command. The difference between the cumulative backup and the full backup is that the level is 1 for each backup.
Tool 2, backup through the Tar-n option.
[Email protected] ~]# tar-n ' 2015-09-01 '-jpcv-f/backupdata/home.tar.bz2/home
# only files that are newer than 2015-09-01 will be packaged into home.bz2.
What's strange is that the directory will still be recorded, but the old files in the directory are not backed up.
Tool 3, a mirrored backup via rsync. Rsync can mirror two directories (mirror), a very fast backup tool!
rsync syntax: Rsync-av source Directory destination Directory
[Email protected] ~]# rsync-av/home/backupdata/#完整备份. Mirroring the/home/to/backupdata/home/, this will produce the home directory under/backupdata.
[Email protected] ~]# rsync-av/home/backupdata/#再次备份. It will be much quicker to do it again. If the data is not changed, almost no action is made.

3.4. Backup of critical data
Recommended directories to back up:
? /etc
? /home
? /root
? /var/spool/mail/,/var/spool/cron/,/var/spool/at/
? /var/lib/
Directories that do not need to be backed up:
? /dev: This is whatever you want to back up.
? /proc,/sys,/run: Record the current system above the running program, this really does not need to backup.
? /MNT,/media: Mounts other hard disk devices, optical drives, floppy disks, etc., and does not need to be backed up if you do not place your own system in this directory.
? /tmp: Save temporary archive, no backup required.
Tools: Use tar for critical data backup, with the date directive to categorize different services at different times and use different filenames.
Instance to back up the MARIADB database by date:
[[email protected] ~]# tar-jpcvf mysql. ' Date +%y-%m-%d '. Tar.bz2/var/lib/mysql
Restore: Catch the latest Linux distribution, install, the system data (such as account/password and home directory, etc.) with the service data (such as WWW/EMAIL/CRONTAB/FTP, etc.) one of the fill back.

3.5, bird Brother's "bird Station" backup strategy:
1. Host hardware: Use a separate filesystem to store the backup data, this filesystem mount to/backup;
2. Daily: Only the MySQL database is currently backed up;
3. Weekly: Including/home,/Var, etc,/boot,/usr/local directory and special services directory;
4. Automatic Processing: This aspect uses the/etc/crontab to provide the backup;
5. Offsite Backup: Periodically burn the data (a) to the disc (b) on a regular basis and transfer it to another machine using the network.

3.6, the need to restore the system classification and solutions.
Type 1, hardware is damaged, and has a full backup of the data.
Type 2: Compromised security events due to software issues.
1. First unplug the network cable, it is best to complete the system backup to other media for future inspection. And if you're being traced to a host that has attacked someone, you can take backup data to testify that you are an attacker, not a bad person who is actively attacking someone.
2. Check the log file to try to find a variety of possible problems
3. Install the new system (best to find the latest distribution)
4. Upgrade the system and make a firewall-related mechanism
5. Based on the 2 error, after the installation completes the new system, the bug fixes
6. Recovery of various services and related data
7. Officially on-line to provide services, and start testing

2018-04-25 "Bird Brother's Linux private cuisine Basic Study (fourth Edition)" 20th chapter basic System setting and backup strategy

Related Article

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.