1. Install

  • Ari CentOS image
  • Use Virtual Box (free) or VMWare (registration code)
  • Set the IP address and gateway DNS
  1. Creating a VM
  2. Custom (Advanced)
  3. Select virtual machine hardware compatibility – default next step
  4. Installation cd-rom image file ISO
  5. Processor configuration is irrelevant
  6. 1GB of allocated memory is enough
  7. Use a bridge network (representing your Linux network over the host)
  8. The last two steps are ok by default
  9. Disk capacity 20GB is enough to split multiple files

Start the installation

  1. Arrow key select the first one (CTRL + Alt to cut out the mouse)
  2. Select Chinese (the language used during the installation)
  3. Software selection GNOME desktop
  4. Installation position need to enter view click finish
  5. You can set the root password and create a user during the installation

Restart after installation

  1. Enter to view the license and accept the agreement
  2. Open Ethernet
  3. Choose Chinese
  4. Time zone Shanghai

After the yum command is installed, you should change the installation source of the yum command to a domestic image. Otherwise, the installation of the software is slow. However, the CentOS7 network (not minimized but not enabled Ethernet) is not configured

  1. Check whether the network is normal (ping). If yes, see the yum domestic mirror
  2. Otherwise,Need to configure the/etc/sysconfig/network-scripts/ifcfg-ens33(At this time, you can also configure the nic name. For details, see below: Modifying network Interface Naming Rules.)
  3. First, the backup/etc/yum.repos.d/CentOS-Base.repoFile (cp command or mv), back up and proceed to the next step
  4. Using curl (or wget) to download the repO file, see aliyun CentOS
  5. Run after downloading the image fileyum makecacheRebuild the cache (yum clean allCan clear the cache), at this time, the output prompt display source is changed to Ali Cloud.
  6. Then use yum to install software using the domestic mirror source

Character system to change the terminal font, in /lib/ KBD /consolefonts file corresponding to various fonts, using setfont sun12x22 command can be temporarily setfont, Run the echo ‘setfont sun12x22’ >> /etc/bashrc command to continuously set the bashrc parameter.

Commands in the bashrc file are executed when the shell is logged in. Yum -Y Update allows you to update all software packages and kernels. use with caution in production environments

Centos 7 No route to host, host unreachable, and so on. This is because the value of the ifcfg-eth0 file needs to be quoted

Basis of 2.

Init 0 Power off init 1 Single user mode init 5 GUI init 3 CLI init 6 Restart touch XXX Create a file XXX mkdir Create a directory man help help distinguish between external and internalCopy the code

3. The file

Df -h View memory lSCPU view CPU PWD View current directory name CD Change directory ls [OPTION]... [FILE]... View the files in the directory, You can view multiple ls plus parameters (write in combination) -l To display files in long format -h to display file sizes and units -r to display files in reverse order -A to display hidden files -t to display files in event sequence -r to display recursively/Root directory /root user's home directory su - XXX Switch to user XXXCopy the code

4. The directory

CD CD - Back to the last directory CD /path/to/... Absolute CD. / path/to /... Relative to (current) CD.. /path/to/... Relative (parent) rmdir Delete an empty directory rm -r -f Delete a non-empty directory rm filename Delete a file. You can add the -f parameter without remindingCopy the code
Cp Copy directory and file parameters -r Copy directory recursively mv Move (rename) Wildcard * single character?Copy the code
Cat Displays the text on the terminal. Head Displays the beginning of the file. Tail Displays the end of the file. -f Displays the information after the file is updated. Used to view log files) WC Statistics file contentCopy the code
To package and compress the media of early Linux backup files (mainly files in etc), use the tar command to package and compress the tape files for storage. The commands for compression are gzip and bzip2. -x table unpacking -f Specifies the operation type to be a file (not a folder). Bzip2 is the least compressed, but a little slow. Tbz2 and.tgz suffixes can be found on networks. This is the abbreviation of bzip2, gzip zip package form thereCopy the code
The decompression method depends on the compression method of the package. Xxx.tar is a layer of compression. Gz tar -xvf openResty-1.19.3.1.tar. xz z indicates that the original file is compressed, x indicates that the original file is unpacked, and f indicates that the specified file is decompressedCopy the code

5. Vim editor

The vi editor

Multi-mode editing: Normal mode (copy and paste), Insert mode (text input), command mode (save and exit), visual mode ()

Vim editor: added infinite step redo and rollback on the basis of VI

:set nu Displays the line number

5.1. Normal mode

Generally, the first mode to enter VIM is the normal mode. Enter I, I, A, A, O and O to enter the insert mode

I into insert mode in the current cursor position I first into insert mode in current line cursor a one under the cursor into insert mode a corresponding I, in the end into insert mode o a line under the cursor into insert mode (the original next line moves down) in turn o the cursor on a line into insert mode (similar to lowercase o) : Enter command mode (last line) V visual mode H Move the cursor left j move the cursor down K move the cursor up L Move the cursor right In the graphical interface system it is ok to use the arrow keys, but in the character system it may only be possible to use HJKL ESC to return to normal mode from other modes Y command indicates copy YY copy (multiple lines can be used)y$Copy the cursor position to the end of the contentD means cut dd cut the whole lined$Cut cursor position to endP paste u undo CTRL + R redo X Delete single character r replace single character :set nu display the number of lines after pressing the number, Shift + G then jumps cursor to specified line lowercase G (press twice to jump to first line) uppercase G jumps cursor to last line Shift + 6 (^) cursor to start shift + 4 ($) cursor to end lineCopy the code

5.2. Insert mode

5.3. Command Mode

Esc From other modes :w Save :q Exit :w path/file_name Save :wq Save and exit vim :q! Exit without saving :! Temporarily execute shell command (followed by command to be executed)/find character (followed by character to be found) and press Enter to match, Press N to move the cursor to the next matching character shift + N to move the cursor to the next matching character: S /old/new When replacing the old character in the previous text with new :% S /old/new To replace the entire text :% S /old/new to replace the matched old character in the entire text :x,ys/old/new then x to y to replace :set commandCopy the code

5.4. Visual mode

Three entry methods v character visual mode V line visual mode CTRL + V block visual mode with D and I can facilitate the block operation D is cut, I is inserted at the cursor position after using I insert only at the cursor position, to apply to the selected block you need to press ESC, this will be applied to the selected blockCopy the code

6. User management

Management of 6.1.

Useradd create a user userdel delete a useradd -r directly delete the user folder under home for example userdel -r hui passwd change the user password groupadd create a user group groupdel delete a user group After creating a user group, you can use the usermod -g group name user name to add an existing user to the user group. You can also add the user to the user group at the same time as the user is createdCopy the code

What if I forget my Ubuntu Root password? If the user has sudo permission, you can change the password to sudo su root. Su is only the root user with the same working environment. Sudo is the full access to root and root’s working environment.

You can run ls -a to view hidden files. Run tail -10 /etc/shadow to view password files. Run tail -10 /etc/passwd to view passwords. If no user group is specified, a user group with the same name as the user is createdCopy the code

Switch 6.2.

For example, to set a certain command permission for a common user, use Visudo, and then modify the file such as shutdown command. By default, only root user can use this command, but you may need to grant permission to other users. However, you cannot expose root's password, so you can grant this command to ordinary users, who often switch users temporarily. Otherwise, switching back to root (possibly) requires a password to su - tempUserNameCopy the code

7. Meaning of the file

The/etc/passwd formats: Username: switch do you want to password: userID: user groups: note: the home directory: user login command interpreter root: x: 0-0: root: / root: / bin/bash Yama: x: 1000-1000: yama: / home/yama: / bin/bash Linux identify users is not according to user's name, but according to the userID, so when you have the same user ID, such as yama ID 0, yama will become the root user; If the command interpreter is set to /sbin/nologin, users, such as the tcpump user, are not allowed to login.Copy the code
/etc/shadow Save user password file format: userName: encrypted password ::::: yama:$6$7LKCrS2L5rGfUCbw$rU1BXreBwFPF6To6q1NB7UPkvr2XTvWCh64QmVfgR Wu.J6yPcUDJZ4GUX1Xjkm0LEnHVy0y5g3AOiLaIrRWAz/::0:99999:7:::Copy the code
/etc/group format: Group name: Is password authentication required (x indicates yes?) Root :x:0: group gid: other group Settings root:x:0: group gid: other group Settings root:x:0: group gid: other group Settings root:x:0: group gid: other group SettingsCopy the code

/bin is a set of system instructions. Bin, short for binary, is used to store the necessary executables of the system such as cat, cp, chmod df, dmesg, gzip, kill, ls, mkdir, more, mount, rm, su, tar, etc.

/sbin generally refers to the superuser instruction. Cfdisk, DHCPCD, dump, e2fsck, fdisk, HALT, ifconfig, ifUP, Ifdown, init, Insmod, LILO, LSMOd, MKE2FS, Modprobe, Quotacheck, reboot, RMMOD, runlevel, shutdown, etc.

/usr/bin is the run script for some software you install later. C++, GCC, CHDRV, diff, dig, du, eject, elm, free, gnome*, Gzip, htpasswd, KFM, kTOP, last, less, locale, M4, make, man, McOpy, NCFTP, newaliases, NSLookup passwd, quota, SMB *, wget, etc.

/usr/sbin *d, inetd, LPD, named, netconfig, NMBD, samba, Sendmail, squid, swap, TCPD, tcpdump, etc.

Bash :command not found if you run normal commands like shutdown and fdisk on a newly installed system. The first thing to consider is whether root’s $PATH already contains these environment variables. Can look at the PATH, if it is: the PATH = $PATH: $HOME/bin needs to be added into the following: the PATH = $PATH: $HOME/bin, / sbin, / usr/bin: / usr/sbin

1 yama yama 52 12月 20 12:51 de. C Dr -xr-xr-x. 17 root root 224 12月 14 16:29.. Lrwxrwxrwx. 1 root root 7 May 11 2019 bin -> usr/bin Indicates the file permission. -rw-r-xr-- 1 userName groupName mTime fileName (It is easy to see that the permission on the left corresponds to the genus X on the right. The first character - indicates the file type) rw- Permission of the file owner r-x Permission of the file owner group r-- Permission of other users Directory permission Description x Enter a directory rx Display the file name in a directory wx Modify the file name in a directory Create a new file The default permission is calculated based on the umask value. The owner and owner group are specified according to the user of the current processCopy the code

Vim’s modification of the file is actually a replacement of the original file

Type: - Common file D directory file (everything is a file, directory is a file) B block special file C character special file L symbolic link F Named pipe S socket file character permissions: R read w write x execute (for example, ls, cat and other commands are actually executable files. For a file opened by vim, you also need execute permission.Copy the code

8. Modify the permission

Chmod Modifying file or directory permission A permission can be expressed in characters or digits. There are two methods for modifying a permission: chmod u+x fileName chmod 755 fileName

U, G, O, and A respectively represent to modify the pink, blue, green, and all in the figure above

Chmod u+ Add permission chmod u- Reduce permission chmod u= Directly set permissionCopy the code

Change the permissions on the de.c file as follows:

  • u-wExample Reduce the write permission of the owner
  • g+xExample Add the execution permission of the owner group
  • o=rwxSet read/write execution permissions for other users
[root@localhost]# ls -ld de.c-RW-RW-r --. 1 Yama yama 52 December 20 12:51 de.c
[root@localhost]# chmod u-w,g+x,o=rwx de.c
[root@localhost]# ls -ld de.c
-r--rwxrwx. 1 yama yama 52 12月 20 12:51 de.c
Copy the code
Another method is to use numbers. The number 467 represents read, read, and execute respectively, which is the addition of permission values. For example, chmod 446 de.c indicates that the owner, owner group, and other users can read and write the de.c file[root@localhost]# ls -ld de.c-RW-RW-r --. 1 Yama yama 52 December 20 12:51 de.c[root@localhost]# chmod 446 de.c
[root@localhost]# ls -ld de.c-r--r-- Rw --.1 yama yama 52 12月 20 12:51 de.c[root@localhost]# chmod 664 de.c
[root@localhost]# ls -ld de.c-RW-RW-r --. 1 Yama yama 52 December 20 12:51 de.cCopy the code

The default permission for creating a file in Linux is 666, but the umask file mask (0022) is subtracted, which is 022, so the default permission for creating a file is 644, which is rw-r–r–.

Chown Changes the owner group and owner

After centos8 tests, the owner group and owner of files whose owner is YAMA cannot be changed by yama users, which may be related to their own configuration. Root users are not restricted

Chown yama./de.c indicates that the owner of the de.c file is yama. To change the owner group, run chown :groupName fileName

CHGRP can change the genus group separately (not often)

In Terminal, press CTRL + R to search for previously used commands

Do not use the root user for permission modification, because it is not restricted, even if only the owner of a file has read permission, the root user can also write to it. Root is used throughout the tutorial to reduce misinterpretation due to inconsistent practice environments, and only practice environments, so root can be used, not in production.

8.1. Modify Permission Notice

Echo huidt > fileA redirects the original output 'huidt' to the fileA file>This symbol will wipe out everything in the original fileWhen file permissions conflict, for example: User1 belongs to group1 and has the permission to file fileA ----w----. That is to say, only users in group1 have the write permission to file fileA. User1 has no permission to file fileA, but user1 belongs to group1. In this case, the conflicting permissions are based on the owner, not the owner groupCopy the code
For directory files, the common permissions are x, rx, and wx. For system directories, the following directories may have different permissions, but the files are the same. For such permissions are called special permissions, and there are the following suids: used for binary executable files. Passwd SGID: for example, /usr/bin.passwd SGID: used for a directory. When a new file or directory is created in the changed directory, the permission of the new file or directory is automatically changed to the owner group of the directory. For example, / TMP: There is a special S permission for SUID, [yama@localhost demo]$ls -l /usr/bin/passwd -rwsr-xr-x. 1 root root 33600 April 7 2020 /usr/bin/passwdCopy the code

SUID means set user ID. For example, when a normal user executes the passwd command, 1 root root 1489 12月 20 13:52 /etc/shadow this file does not have permissions for any user (except root, whose owner is root). Therefore, s stands for when the ordinary user, such as yama execution, will automatically obtain the permission of the owner root, which makes the ordinary user also have part of the permission of the operating system file

SBIT, you can see that other users at the end have a t permission, because/TMP is a temporary directory, any user can operate here, but to prevent other users from deleting the current file, so t permission is set

[root@localhost demo]# ls -ld/TMP drwxrwxrwt. 31 root root 4096 12月 21 15:59 / TMPCopy the code

For example, s corresponds to 4 and t corresponds to 1. In this case, the permission of /usr/bin/passwd is 4755, and the permission of/TMP is 1777.

9. Network management

9.1. View network status

net-tools VS iproute2

9.1.1. net_tools

9.1.1.1. ifconfig

Ifconfig eth0 First nic (network interface) The first network interface may also be called by other names: Eno1 ONBOARD NIC ENS33 PCI-E NIC ENP0S3 PCI-E NIC that cannot obtain physical information CentOS 7 Uses a consistent network device name. If the preceding network devices do not match, eth0 is usedCopy the code

Ens33 is the nic name of my device, INET IP address, Netmask subnet mask, INET6 MAC address, RX and TX sent and received data. There is also an LO network card representing local loopback, always 127.0.0.1, used for development and testing. Virbr0 network cards are typically gateways virtualized from Linux

[yama@localhost demo]$ ifconfig ens33: Flags = 4163 < UP, BROADCAST, RUNNING, MULTICAST > mtu 1500 inet 192.168.43.127 netmask 255.255.255.0 BROADCAST 192.168.43.255 inet6 fe80::1744:b082:b9d8:f881 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:f4:9f:76 txqueuelen 1000 (Ethernet) RX Packets 47 bytes 9571 (9.3kib) RX errors 0 dropped 0 Overruns 0 Frame 0 TX packets 81 bytes 9273 (9.0kib) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: Flags =73<UP,LOOPBACK,RUNNING> MTU 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixLen 128 scopeid 0x10<host> loop Txqueuelen 1000 (Local Loopback) RX packets 48 bytes 4080 (3.9 KiB) RX errors 0 Dropped 0 Overruns 0 frame 0 TX packets 48 bytes 4080 (3.9 KiB) TX errors 0 Dropped 0 Overruns 0 carrier 0 collisions 0 virbr0: Flags =4099<UP,BROADCAST,MULTICAST> MTU 1500 INET 192.168.122.1 Netmask 255.255.255.0 BROADCAST 192.168.122.255 ether 52:54:00:02:6f:c5 TXQueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0b) RX errors 0 Dropped 0 Overruns 0 frame 0 TX Packets 0 bytes 0 (0.0b) TX errors 0 Dropped 0 Overruns 0 carrier 0 collisions 0Copy the code

9.1.1.2. Check network cable connections

Check the wiring [root @ localhost yama] # mii - tool eth0 eth0: negotiated baset FD - 1000 flow control, the link is okCopy the code

9.1.1.3. Viewing gateways

When the network needs to connect to other network address ranges, you need to configure the gateway, also known as configuring routes. Gateway The Gateway, also called the internetwork connector or protocol converter, connects networks at the upper network layer. A gateway is essentially an IP address from one network to other networks. When visiting a website, packets are sent to the IP address (this IP address is a gateway), and then the device at this IP address is responsible for distributing packets.

The route command does not resolve the host name with the n parameter

[root@localhost yama]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.43.1 0.0.0.0 UG 100 00 eth0 192.168.43.0 0.0.0.0 255.255.255.0 U 100 00 eth0 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 [root@localhost yama]# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default _gateway 0.0.0.0 UG 100 00 eth0 192.168.43.0 0.0.0.0 255.255.255.0 U 100 00 eth0 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0Copy the code

Default indicates the default gateway 192.168.43.1. In addition to the default gateway, you can also configure detailed routes, also called static routes

9.1.1.4. Network Configuration Commands

Ifconfig < interface > <IP address > [netmask] table Modify network configuration ifup < interface > enable network adapter, For example, ifup eth0 ifdown < interface > Disable nic Add Gateway Add default Gateway route add default GW <Gateway IP> Add specified Gateway route add -host < specified IP> gw <Gateway IP> Add the Gateway of the specified network segment route add-net < specified network segment > netmask < subnet mask > gw <Gateway IP address > Delete the route for accessing the specified network segment route del default gw <Gateway IP>Copy the code

Modifying a gateway usually involves deleting the old one and adding a new one

9.1.2. iproute2

Network command set: IP command

ip addr lsxxxx ...... Ifup eth0 and ifdown eth0 IP addr add 10.0.0.1/24 dev eth1 Ifconfig eth1 10.0.0.1 netmask 255.255.255.0 IP route add 10.0.0.1/24 via 192.168.0.1 Route add-net 10.0.0.0 netmask 255.255.255.0 GW 192.168.0.1Copy the code

9.2. Modify the naming rules of network interfaces

In the operation of a large number of network devices, if the device network card names are different, the batch operation will be more troublesome, so you need to change to a consistent network card name.

The nic naming rules are affected by two parameters: biosdevName and net.ifnames

The grub file for CentOS_8 contains the following contents, where GRUB_CMDLINE_LINUX indicates the contents required for Linux startup (boot the kernel). It is similar to the boot menu. Because this file is only for the user to read

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cl-swap rd    .lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true
Copy the code

Steps summary:

  • The editor/etc/default/grubFile, addbiosdevname=0,net.ifnames=0
  • Modify the original nic file: will/etc/sysconfig/network-scripts/ifcfg-ens33Change the values of NAME and DEVICE names in the file to eth0
  • Rename the original nic file: will/etc/sysconfig/network-scripts/ifcfg-ens33File name changed toifcfg-eth0
  • Update GRUB: Execute#grub2-mkconfig -o /boot/grub2/grub.cfg
  • Restart: Execute#reboot
biosdevname net.ifnames NIC name
default 0 1 ens33
Combination 1 1 0 em1
Combination 2 0 0 eth0

9.3. Network Configuration

See Network Configuration Commands

9.4. Routing Commands

See iproute2

9.5. Troubleshooting network faults

ping
traceroute
mtr
nslookup
telnet
tcpdump
netstat
ss
Copy the code

Traceroute w can be added. For example, traceroute -w 1 www.baidu.com indicates that if one IP address times out for a long time, the system waits for a maximum of 1s

[yama@localhost ~]$traceroute -w 1 yama.thdong. Top traceroute to yama.thdong. Top (47.103.10.22), 30 hops Max, 60 byte packets 1 _gateway (192.168.43.1) 6.442 ms 6.479 ms 7.087 ms 2 * * * 3 10.138.76.213 (10.138.76.213) 57.145 ms 57.087 ms 57.167 MS 4 * * * * indicates that the host does not support traceroute tracingCopy the code

MTR is executed directly, and more detailed information will be displayed when hosts communicate with each other than Traceroute.

Nslookup obtain IP from domain name [yama@localhost ~]$nslookup yama.thdong.top Server: 192.168.43.1 Address: Authoritative answer: Name: yama.thdong. Top Address: authoritative answer: Name The default server is DNS [root@centos8 demo]# nslookup> server172.18.6.89 Address: 172.18.6.89#53 Default server: 114.114.114.114 Address: Address: 172.18.6.88#53 Default server: 172.18.6.88#53Copy the code
Telnet can be used to check whether a port on the target host is accessible. It is a common method to control the remote server. CTRL +] Stop Quit Telnet [yama@localhost ~]$Telnet www.baidu.com 80 Trying 36.152.44.95... Connected to www.baidu.com. Escape character is '^]'. ^]telnet> quit
Connection closed.
[yama@localhost ~]$ 
Copy the code
[root@localhost demo]# tcpdump -i any -n port 80 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on any, link-type LINUX_SLL (Linux cooked), Capture size 262144 bytes ^C 0 packets Captured 0 packets received by filter 0 packets dropped by kernel -i any -n indicates that the domain name is not parsed (displayed in IP address). Port 80 indicates that port 80 can also capture a host. Run the host parameter tcpdump -i any -n host 10.0.0.1. Run the host and port tcpdump -i any -n host 10.0.0.1 and port 80 command to save the captured result using -w, the file path, and the file nameCopy the code
Netstat is used to display various network related information, such as network connections, routing tables, Interface Statistics, Masquerade connections, Multicast Memberships etc. [root@localhost Demo]# netstat - NTPL Active Internet Connections (only Servers) Proto Recv -q Send -q Local Address Foreign Address State PID/Program name TCP 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd TCP 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 1705/ dnSMasq TCP 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1118/ SSHD TCP 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1115/cupsd tcp6 0 0: :111 ::* LISTEN 1/systemd tcp6 0 0: :22 ::* LISTEN 1118/ SSHD tcp6 0 0: :1:631 :::* LISTEN 1115/cupsd n Display IP t table in TCP mode P table process L table TCP status (LISTEN)Copy the code
The ss command is basically the same as the netstat command. Different display formats [root@localhost demo]# ss - NTPL State Recv -q Send -q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:111 Rpcbind 0.0.0.0: * users: ((" ", pid = 879, fd = 4), (" systemd pid = 1, fd = 37)) LISTEN 0 32 192.168.122.1:53 0.0.0.0: * Users :(("dnsmasq",pid=1705,fd=6)) LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:((" SSHD ",pid=1118,fd=5)) LISTEN 05 127.0.0.1:631 0.0.0.0: * users: ((cupsd "", pid = 1115, fd = 10)) LISTEN 0 128 [: :] : [: :] : 111 * users:(("rpcbind",pid=879,fd=6),("systemd",pid=1,fd=39)) LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=1118,fd=7)) LISTEN 0 5 [::1]:631 [::]:* users:(("cupsd",pid=1115,fd=9))Copy the code

9.6. Network service Management

There are two kinds of network service managers: Sysv and Systemd

  • Service network start | stop | restart (are older, I use in centos8 tired)
  • chkconfig -list network
  • Systemctl list-unit-files networkManager.service systemctl list-unit-files networkManager.service
  • systemctl start|stop|restart NetworkManager
  • systemctl enable|disable NetworkManager

The configuration files are /etc/sysconfig/network-scripts/ifcfg-eth0 and /etc/hosts

In centos7, run the service network status command to check the network status. In centos7, run the service network status command to check the network status. Centos8 has replaced network with NetworkManager. Use systemctl status NetworkManager to check the network status. However, NetworkManager service is completely controlled by systemctl.

Check the network status as follows

[root@localhost demo]# systemctl status NetworkManager ● NetworkManager. Service - NetworkManager Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled; vendor pr> Active: active (running) since Fri 2020-12-25 16:56:47 CST; 35min ago Docs: man:NetworkManager(8) Main PID: 5109 (NetworkManager) Tasks: 3 (Limit: 11154) Memory: 4.5m CGroup: / system. Slice/NetworkManager service └ ─ 5109 / usr/sbin/NetworkManager - no - daemon on December 25 17:26:49 centos8. Yama101 NetworkManager[5109]: <info> [1608888409.6276] DHCP > 12月 25 17:26:49 centos8.yama101 NetworkManager[5109]: <info> [1608888409.6276] DHCP > 12月 25 17:26:49 centos8.yama101 NetworkManager[5109]: <info> [1608888409.6276] DHCP > 12月 25 17:26:49 centos8.yama101 NetworkManager[5109]: <info> [1608888409.6276] DHCP > 12月 25 17:26:49 centos8.yama101 NetworkManager[5109]: <info> [1608888409.6276] DHCP > 12月 25 17:26:49 centos8.yama101 NetworkManager[5109]: <info> [1608888409.6276] DHCP > 12月 25 17:26:49 centos8.yama101 NetworkManager[5109]: <info> [1608888409.6276] DHCP > 12月 25 17:26:49 centos8.yama101 NetworkManager[5109]: <info> [1608888409.6276] DHCP > 12月 25 17:26:50 centos8.yama101 NetworkManager[5109]: <info> [1608888410.7571] AGEN > 12月 25 17:30:49 centos8.yama101 NetworkManager[5109]: <info> [1608888649.6596] audi> [root@localhost demo]#Copy the code

View NetworkManager services

[yama@centos8 demo]$ systemctl list-unit-files NetworkManager.service
UNIT FILE              STATE  
NetworkManager.service enabled

1 unit files listed.
Copy the code

Network manager service is the default network management tool of centos6. Centos7 rewrote NetworkManage service, because network can only support service management. The default centos7 service management tool is systemctl (centos7 network and NetworkManager are implemented with it).

In centos7, if you need to use the old control mode, you need to disable the new control mode (NetworkManager). Otherwise, you are advised to disable the old control mode when using the new control mode. Don’t use both sets together.

Use chkconfig --list network in centos7 to view network usage at different runtime levels (not available in centos8). Then you can use the chkconfig - level XXXX (digital level) to enable or disable the network off | on Using systemctl enable | disable NetworkManager Enable or disable the NetworkManager serviceCopy the code

Ifconfig and IP are in the same situation. They can both query the network status and set IP, but the Settings can only be saved in the memory, and the configuration will be gone after the restart. To keep the configuration after restart, write the configuration file. Run the service network restart command to reload the configuration file for the network configuration to take effect. Remember that in centos8 only systemctl restart NetworkManager is available

9.7. Common network profiles

/etc/sysconfig/network-scripts/ifcfg-* and /etc/hosts, which are configuration files of each NIC

[root@localhost demo]# hostname centos8-101.yama temporarily change hostname [root@localhost demo]# hostnamectl set-hostname centos8.yama101 Remember to also change the mapping between the local address 127.0.0.1 in the /etc/hosts file, 127.0.0.1 localhost localhost.localdomain localhost4 localhost4. Localdomain4 ::1 localhost localhost.localdomain Localhost6 localhost6. Localdomain6 127.0.0.1 centos8 yama101Copy the code

10. Software installation

10.1. Package Manager

CentOS, RedHat, and Fedora use yum Package Manager and the software installation Package format is RPM. Debian and Ubuntu use apt Package Manager and the software installation format is deb

10.2. RPM packages and RPM commands

Wget - 1.14-18. The el7_6. 1. X86_64

The name of the software Software version System version platform
wget 1.14 to 18 El7_6. 1 x86_64

The software version is critical because software packages depend on each other. El7 is the version of CentOS7, RedHat7, and Fedora7. El6 can be installed on CentOS7, but may not be stable.

The RPM command parameters commonly used - q village package - I install package - e uninstall packages in the query and unload only need to use the package name can, but when installation requires a package complete file name query can be used to split screen - a | more, Such as RPM - qa | more Spaces after the split screen to see the next screen, q exitCopy the code

When installing the system, you can directly install the software from the cd-rom drive. If you want to use the files in the CD-ROM after installing the system, you need to mount the CD-ROM file in Linux (I understand the mount is to insert the USB disk like Win to manually identify and read). /dev/sr0: /dev/sr0: /dev/sr0: /dev/sr0: /dev/sr0: /dev/sr0: /dev/sr0: /dev/sr0: /dev/sr0

[yama@localhost ~]$ls /dev/sr0 -l brw-rw----+ 1 root cdrom 11, 0 1月 1 15:19 /dev/sr0Copy the code

Insert the cd-rom drive, and then in Linux, identify the block device in the /dev/folder and run dd if=/dev/file of=/ XXX /xxx.iso to make an image of the real CD-ROM.

Although cp and cat cannot be used, you can use the mount command to operate on this block special file, especially in the character interface, there is no drive letter pop-up prompt like Windows insert USB disk, so you must manually operate.

mount /dev/sr0 /mnt

For Linux, you are advised to mount the RPM Packages to the/MNT /Packages directory. Then you can run the RPM command to install these Packages. When using the RPM -i parameter to install yyy Packages, dependency detection may fail. If XXX is required by YYY, install the XXX package before installing YYY.

10.3. Yum repository

Yum is a repository, also known as a package manager, with two benefits:

  • You don’t have to deal with complex dependencies
  • Official software packages come from reliable sources

10.3.1. Configure the yum source

Official YUM source: : mirror.centos.org/

Image source: ali mirrors.aliyun.com/centos/

Repos. D/centos-base. Repo can be used to override the source file with the same name provided by the official CentOS image. Reference ali CentOS – Base. Repo file mirrors.aliyun.com/repo/Centos… :

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
Copy the code

After the file is downloaded, run yum Makecache

10.3.2. Common options

  • Install Install software package
  • Remove unload
  • The list | grouplist view
  • Update update (all updates without specifying the software name)

# yum Install # yum Install # yum Install # yum Install # yum Install # yum Install # yum Install # yum

10.4. Source code compilation and installation

If the version of the software does not meet the requirements, you need to compile and install it from source code (yum repository may not have the version you need). In the early days, there was no convenient tool like Yum that used this method often.

For example: compile and install OpenResty

  1. To downloadWget HTTP: / / https://openresty.org/download/openresty-1.19.3.1.tar.gz
  2. Unpack theThe tar - ZXF openresty - 1.19.3.1. Tar. Gz
  3. The decompressed folder is displayedCD openresty - 1.19.3.1
  4. Executing the configure file./configure --prefix=/usr/local/openresty
  5. compilemake -j2
  6. Compile the installationmake install

# yum install pcl-devel openSSL-devel # yum install pcl-devel openSSL-devel # yum install pcl-devel openSSL-devel

Gmake is cross-platform. After make, the build folder will appear. Then execute make install to install all files in the build directory. Openresty is already installed in the ls /usr/local/openresty/* folder.

10.5. Kernel upgrade

Kernel in 10.5.1. RPM format

Check the kernel version uname -r

There are three upgrade modes:

  • RPM package installed by yourself, please
  • Yum install the kernel - 3.10.0oryum updateThe kernel can also be upgraded and cannot use the latest stable version
  • Source code builds and installs, like openResty builds and installs, rely on complex dependencies

Reference links:

  • The Linux Kernel’s official website
  • Ali Linux Kernel image

Using source code compilation and installation is more complex, this installation is generally different software, as follows:

  1. Download the kernel file:Wget HTTP: / / https://mirrors.aliyun.com/linux-kernel/v5.x/linux-5.10.4.tar.xz
  2. Extract:Tar XVF linux-5.10.4.tar.xz -c /usr/src/kernels
  3. Enter the kernels folder:cd /usr/src/kernels
  4. Configure kernel build parameters (this can be done before installing dependencies in advance:yum install gcc gcc-c++ make ncurses-devel openssl-devel elfutils-libelf-devel -y) :
    1. make menuconfig | allyesconfig | allnoconfig
    2. Using the current system configuration:Cp/boot/config - kernelversion. Platform/usr/SRC/Linux kernels / - 5.10.4 / config
  5. make -j2 allStart compiling. I don’t know how many cpus are availablelscpuTo view
  6. Installing the kernel (both steps)
    1. make modules_install
    2. make install
  7. Finally, reboot the system bootstrap and the new kernel is optional

10.5.2. In field

Yum install epel-release-y install epel-release-y install epel-release-y install epel-release-y install epel-release-y install epel-release-y install epel. Yum install kernel can be used to install the latest version of the kernel.

Is it necessary to upgrade the kernel to 5? According to netizens, there is no need, the major cloud service manufacturers are also around 3.

10.6. Grub configuration file

System boot files, CentOS7 use grub2 (many convenient tools, can be modified with commands), before using grub1 (all files need to be manually edited)

List of relevant documents:

  • /etc/default/grub
  • /etc/grub.d/
  • /boot/grub2/grub.cfg
  • ` `

This is also how to change the kernel boot and forget the root password

10.7. View processes using PS and TOP

10.7.1. Process concept and Process View

A process is a running program, or expressed as an activity. The entire life cycle of a program from start to end is manageable. For example, C language starts from main function, but there is more than one way to terminate, including normal termination (return from main or call exit) and abnormal termination (call abort, receive signal, etc.), so we need to check the status of the process for management.

View commands:

  • ps
  • pstree
  • top

Processes are a tree structure and are closely related to permissions

Ps looks at the processes that are currently running, tty in the character system and PTS in the graphics system

[root@izuf6gv9wljzw8p0wgmnlvz yama]# ps
  PID TTY          TIME CMD
15834 pts/0    00:00:00 su
15835 pts/0    00:00:00 bash
15865 pts/0    00:00:00 ps
Copy the code

Add the argument e to show the other processes

[root@izuf6gv9wljzw8p0wgmnlvz yama]# ps -e | more
  PID TTY          TIME CMD
    1 ?        00:00:05 systemd
    2 ?        00:00:00 kthreadd
    3 ?        00:00:10 ksoftirqd/0
    5 ?        00:00:00 kworker/0:0H
    7 ?        00:00:00 migration/0
    8 ?        00:00:00 rcu_bh
    9 ?        00:01:24 rcu_sched
   10 ?        00:00:02 watchdog/0
Copy the code

The parameter f shows more information. The UID is not necessarily the user who started the process, because this can be changed. For example, nginx and OpenResty are both started by root, but the UID is nobody. PPID table parent process,

[root@izuf6gv9wljzw8p0wgmnlvz yama]# ps -ef | more
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Jan04 ?        00:00:05 /usr/lib/systemd/systemd --switc
hed-root --system --deserialize 21
root         2     0  0 Jan04 ?        00:00:00 [kthreadd]
root         3     2  0 Jan04 ?        00:00:10 [ksoftirqd/0]
root         5     2  0 Jan04 ?        00:00:00 [kworker/0:0H]
root         7     2  0 Jan04 ?        00:00:00 [migration/0]
root         8     2  0 Jan04 ?        00:00:00 [rcu_bh]
Copy the code

Use the eLf parameter to view lightweight processes, that is, threads

[root@izuf6gv9wljzw8p0wgmnlvz yama]# ps -eLf | more
UID        PID  PPID   LWP  C NLWP STIME TTY          TIME CMD
root         1     0     1  0    1 Jan04 ?        00:00:05 /usr/lib/systemd/syst
emd --switched-root --system --deserialize 21
root         2     0     2  0    1 Jan04 ?        00:00:00 [kthreadd]
root         3     2     3  0    1 Jan04 ?        00:00:10 [ksoftirqd/0]
root         5     2     5  0    1 Jan04 ?        00:00:00 [kworker/0:0H]
Copy the code

Pstree check the process tree, you can see that the first start process of CentOS is systemd, in CentOS6 is init

[yama@izuf6gv9wljzw8p0wgmnlvz ~]$pstREE Systemd ─┬─AliSecGuard─ 6*[{AliSecGuard}] Bass Exercises ──22*[{AliSecGuard}] ├ ─ AliYunDunUpdate ─ ─ ─ 3 * [{AliYunDunUpdate}] ├ ─ BT - a Panel ─ ─ ─ {BT - a Panel} ├ ─ BT - Task ─ ─ ─ 6 * [{BT - Task}] Exe ├ ─ CmsGoAgent. Linu ─ ┬ ─ ─ ─ ─ 8 * [} {exe] │ └ ─ 5 * [{CmsGoAgent. Linu}] ├ ─ 2 * [agetty] ├ ─ aliyun - service ─ ─ ─ 7 * [{aliyun - service}] Bass School - - 7*[{bass school}] Bass School - Bass School - bass School - Bass School - Bass School - Bass School - Bass School - - ├ ─ mysqld_safe ─ ─ ─ mysqld ─ ─ ─ 18 * [{mysqld}] ├ ─ nginx ─ ─ ─ 2 * / nginx ├ ─ NTPD ├ ─ PHP - FPM ─ ─ ─ 7 * / PHP - FPM ├ ─ polkitd ─ ─ ─ 5 * [{polkitd}] ├ ─ pure - FTPD ├ ─ rsyslogd ─ ─ ─ 2 * [{rsyslogd}] ├ ─ SSHD ─ ┬ ─ SSHD ─ ─ ─ SSHD ─ ─ ─ bash ─ ─ ─ su ─ ─ ─ bash │ └ ─ SSHD ─ ─ ─ SSHD ─ ─ ─ bash ─ ─ ─ pstree ├ ─ systemd - journal ├ ─ systemd - logind ├ ─ systemd - udevd └ ─ tuned ─ ─ ─ 4 * [{tuned}]Copy the code

Top Dynamically view the status of the computer, such as process, load, memory, etc. You can add parameters top -p XXX, XXX is the corresponding process PID

Top-14:15:20 up 5 days, 21:55, 3 Users, Load Average: 0.00, 0.01, 0.05 Tasks: 95 total, 1 running, 94 sleeping, 0 stopped, 0 zombie%Cpu(S): 0.7US, 0.3SY, 0.0Ni, 99.0ID, 0.0wa, 0.0HI, 0.0Si, 0.0STKiB Mem : 1883724 total, 421816 free, 656240 used, 805668 buff/cache KiB Swap: 1049596 total, 1049596 free, 0 used. 1036820 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1371 root 10 -10 141972 22716 10352 S 0.7 1.2 60:48.79 AliYunDun 3684 root 10-10 436896 4844 2328 S 0.3 0.3 4:32.92 AliSecGuard 1 root 20 0 43240 3636 2432 S 0.0 0.2 0:05.99 systemd 2 root 20 00 0 S 0.0 0.0 0:00.02 kthreadd 3 root 20 00 0 S 0.0 0.0 0:10.71 ksoftirqd/0 5 Root 0-20 00 S 0.0 0.0 0:00.00 kworker/0 0H 7 root rt 00 0 S 0.0 0.0 0:00 Rcu_bh 9 root 20 00 0 S 0.0 0.0 1:25.53 rcu_sched 10 root rt 00 0 S 0.0 0.0 0:02.78 watchdog/0 12 root 20 00 0 S 0.0 0.0 0:00.00 kdevtmpfs 13 root 0-20 00 S 0.0 0.0 0:00.00 netns 14 root 20 00 S 0.0 0.0 0:00.17 Khungtaskd 15 root 0-20 00 S 0.0 0.0 00.00 writeBack 16 root 0-20 00 S 0.0 0.0 00.00 khungTaskd 17 root 0 -20 00 S 0.0 0.0 0:00.00 bioset 18 root 0-20 00 S 0.0 0.0 0:00.00 kblockdCopy the code

10.7.2. Process Control commands

  • Prioritization of processes:
    • Nice ranges from -20 to 19. A smaller value indicates a higher priority and more resources are preempted
    • Renice resets the priority
  • Process job control
    • jobs
    • The & symbol
Xx Table -20 to 19 numbers, nice table common change priorities, renice used to change the running process priority nice-n xx renice -n xxCopy the code

Job control generally refers to the control of the running foreground and background of the process

Run demo.sh./demo.sh & to view the processes running in the backgroundjobsnjobsView the leading number and cut it back to the foregroundfgN CTRL + Z Cuts the currently running process to the background and pauses itfg, n stands for process, running in the backgroundbg n
Copy the code

10.7.3. Process communication mode

  • Pipe,|It is also a form of process communication
  • There’s also something called signaling, where the end user enters a shortcut control program, for examplectrl+c, such as the kill
  • Another kind is called a socket

Use kill -l to check the current support for the left and right signals, CTRL + C is 2 good SIGINT

[yama@izuf6gv9wljzw8p0wgmnlvz ~]$ kill -l 1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM 16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP 21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ 26) SIGVTALRM 27) SIGPROF 28)  SIGWINCH 29) SIGIO 30) SIGPWR 31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3 38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8 43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13 48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12 53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7 58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62)  SIGRTMAX-2 63) SIGRTMAX-1 64) SIGRTMAXCopy the code

If your program does not want someone to use CTRL + C to stop it, then you should use shell scripts to handle the corresponding SIGINT signal, where command 9 stops immediately without any blocking.

kill -9 PID
Copy the code

The process created on the current terminal is the parent process of the current terminal. If the terminal is killed but the child process continues to run with nohup, the parent process of the child process changes to systemd (init in CentOS 6).

10.7.4. Daemon and system logs

A daemon is a process that starts after startup. Compared with ordinary processes, it does not need a terminal to start, occupies the root directory, and its output is printed to special files.

  • Run a command with nohup and ampersand
    • The nohup command causes the process to ignore the hangup signal
  • The difference between daemons and normal processes
    • Boot from the rev.
    • You don’t need a terminal to start
    • Occupying the root directory
    • Its output is printed to a special file
  • Using the screen command
    • Screen enters the Screen environment
    • CTRL + A D Exit (detached) Screen environment
    • Screen-ls Displays screen sessions
    • Screen-r sessionID Restores the session

Nohup means that the program will not be affected even if the current terminal is closed, often with ampersand to allow other commands to be executed at the same time. At the same time, nohup ignores the input and appends the output to the nohup. TXT file in the current directory

Said back to the start of the daemon process, it will boot from the start, just as some of the Windows login authentication, network services, will be started before the user logs in, reason and nohup is one eye, actually after start killing the parent, and as a child of 1 process, and its output will print to the root directory of the log file. If you do not print to the file in the root directory, you will occupy some other folder. If this folder is a USB drive, you cannot pull it out because it is occupied and printing output. The root directory is also assumed to be a USB drive, but it will only be removed when the system is shut down or restarted.

In Linux, there is a special directory /proc, which does not exist by default. In fact, the operating system reads some information from the memory, and then presents some information in the file in the way of the memory, and you can view it. In /proc, there is a directory with the same name as the process id. The following directory contains some attributes of the process, such as CWD, which indicates the current location. It is a file that can be viewed using ls -l CWD. There is also a fd directory in the change directory, where log input and output are stored, ls -l fd view, where 0 represents input, 1 represents output, in /root/nohup.txt

Use Screen to avoid outages caused by network problems

10.7.5. Service Management tool Systemctl

This is also called the Service Centralization Management tool and provides a daemon for common functions.

CentOS 6 and earlier use service management. In CentOS 7, service and systemctl coexist. In fact, systemctl is an enhancement and simplification of Service

There are different levels of system startup. Use chkconfig –list to check

[yama@localhost ~]$chkconfig --list Note: This output only displays SysV services, not native Systemd services. SysV configuration data may be overwritten by the native Systemd configuration. To list systemd services, execute 'systemctl list-unit-files'. To view the services enabled at a specific target, run 'systemctl list-dependencies [target]'. Netconsole 0: off 1: off 2: off 3: off 4: off 5: Off 6: off Network 0: off 1: off 2: on 3: on 4: on 5: on 6: offCopy the code

If you want to kill a process, you cannot kill it. If you want to kill a process, you cannot kill it. If you want to kill a process, you cannot kill it. Init has been replaced by Systemd, the number 1 process in CentOS 7.

What does this level have to do with the service?

Network 0: off 1: off 2: on 3: on 4: on 5: on 6: Off. It is found that certain levels are on in some services, that is, when the running level reaches this level, the program will be opened or closed. For example, network opens this service at level 3, that is, character system. Init 6 shuts down the service on restart. For example, by opening the required services in the Init 5 graphical interface, you can control the required services by level.

Systemctl has the same function. Use systemctl list-dependencies [target] to check dependencies

[yama @ localhost ~] $systemctl list - dependencies | grep network low ├ ─ network. The serviceCopy the code

Service can also set the start-stop of services, such as common service network start | stop |,

Systemctl does the same thing, but with the service name at the end: Systemctl start | restart | stop | reload | enable | disable | status service name, enable boot operation table service, disable table with the boot operation, not the status table to check the service status

Timeline 11.5

10.7.6 SELinux profile

11. A Makefile

  • How do I debug MAKEFILE variables
  • Write the Makefile with me

10.8. Assignment

虚拟机软件可使用VirtualBox,免费,轻量

新建用户
[root@centos8 yama]# useradd 2017218049
useradd:无效的用户名“2017218049”
[root@centos8 yama]# useradd thd2017218049
[root@centos8 yama]# passwd thd2017218049
更改用户 thd2017218049 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@centos8 yama]# su thd2017218049
[thd2017218049@centos8 yama]$ 

常用指令
[thd2017218049@centos8 ~]$ cd /home/thd2017218049
[thd2017218049@centos8 ~]$ mkdir 2017218049
[thd2017218049@centos8 ~]$ touch index.c
[thd2017218049@centos8 ~]$ man vim
[thd2017218049@centos8 ~]$ vim index.c
[thd2017218049@centos8 ~]$ mv ./index.c ./buble.c
[thd2017218049@centos8 ~]$ ls
2017218049  buble.c
[thd2017218049@centos8 ~]$ ls -lhd ./*
drwxrwxr-x. 2 thd2017218049 thd2017218049   6 12月 28 12:14 ./2017218049
-rw-rw-r--. 1 thd2017218049 thd2017218049 566 12月 28 12:20 ./buble.c
[thd2017218049@centos8 ~]$ mv ./buble.c ./2017218049/buble.c
[thd2017218049@centos8 ~]$ cd 2017218049
[thd2017218049@centos8 2017218049]$ ls
buble.c
[thd2017218049@centos8 2017218049]$ chmod 754 buble.c
[thd2017218049@centos8 2017218049]$ ls -lh *
-rwxr-xr--. 1 thd2017218049 thd2017218049 566 12月 28 12:20 buble.c
[thd2017218049@centos8 2017218049]$ mii-tool ens33
SIOCGMIIPHY on 'ens33' failed: Operation not permitted
[thd2017218049@centos8 2017218049]$ su - root
密码:
上一次登录:一 12月 28 12:08:13 CST 2020pts/0 上
[root@centos8 ~]# mii-tool ens33
ens33: negotiated 1000baseT-FD flow-control, link ok
[root@centos8 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.43.1    0.0.0.0         UG    100    0        0 ens33
192.168.43.0    0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
[root@centos8 ~]# vim /etc/default/grub
[root@centos8 ~]# cd /etc/default
[root@centos8 default]# ls
grub  nss  useradd
[root@centos8 default]# cd /etc/sysconfig/network-scripts
[root@centos8 network-scripts]# ls
ifcfg-ens33  ifdown-ppp       ifup-ib      ifup-Team
ifcfg-lo     ifdown-routes    ifup-ippp    ifup-TeamPort
ifdown       ifdown-sit       ifup-ipv6    ifup-tunnel
ifdown-bnep  ifdown-Team      ifup-isdn    ifup-wireless
ifdown-eth   ifdown-TeamPort  ifup-plip    init.ipv6-global
ifdown-ib    ifdown-tunnel    ifup-plusb   network-functions
ifdown-ippp  ifup             ifup-post    network-functions-ipv6
ifdown-ipv6  ifup-aliases     ifup-ppp
ifdown-isdn  ifup-bnep        ifup-routes
ifdown-post  ifup-eth         ifup-sit
[root@centos8 network-scripts]# mv ./ifcfg-ens33 ./ifcfg-eth0
[root@centos8 network-scripts]# ls
ifcfg-eth0   ifdown-ppp       ifup-ib      ifup-Team
ifcfg-lo     ifdown-routes    ifup-ippp    ifup-TeamPort
ifdown       ifdown-sit       ifup-ipv6    ifup-tunnel
ifdown-bnep  ifdown-Team      ifup-isdn    ifup-wireless
ifdown-eth   ifdown-TeamPort  ifup-plip    init.ipv6-global
ifdown-ib    ifdown-tunnel    ifup-plusb   network-functions
ifdown-ippp  ifup             ifup-post    network-functions-ipv6
ifdown-ipv6  ifup-aliases     ifup-ppp
ifdown-isdn  ifup-bnep        ifup-routes
ifdown-post  ifup-eth         ifup-sit
[root@centos8 network-scripts]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1160.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-d7a82457455c4d0798c57d3f4632b8e8
Found initrd image: /boot/initramfs-0-rescue-d7a82457455c4d0798c57d3f4632b8e8.img
done
[root@centos8 network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.43.235  netmask 255.255.255.0  broadcast 192.168.43.255
        inet6 fe80::33fb:dc46:4fc0:7864  prefixlen 64  scopeid 0x20<link>
        inet6 2409:8930:b4d3:228b:b373:3115:8bc6:d393  prefixlen 64  scopeid 0x0<global>
        ether 00:0c:29:6b:6f:d6  txqueuelen 1000  (Ethernet)
        RX packets 2261  bytes 1891625 (1.8 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1041  bytes 81817 (79.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 323  bytes 28152 (27.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 323  bytes 28152 (27.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:2e:20:25  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@centos8 network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@centos8 network-scripts]# ls
ifcfg-eth0   ifdown-ppp       ifup-ib      ifup-Team
ifcfg-lo     ifdown-routes    ifup-ippp    ifup-TeamPort
ifdown       ifdown-sit       ifup-ipv6    ifup-tunnel
ifdown-bnep  ifdown-Team      ifup-isdn    ifup-wireless
ifdown-eth   ifdown-TeamPort  ifup-plip    init.ipv6-global
ifdown-ib    ifdown-tunnel    ifup-plusb   network-functions
ifdown-ippp  ifup             ifup-post    network-functions-ipv6
ifdown-ipv6  ifup-aliases     ifup-ppp
ifdown-isdn  ifup-bnep        ifup-routes
ifdown-post  ifup-eth         ifup-sit
[root@centos8 network-scripts]# vim ifcfg-eth0
[root@centos8 network-scripts]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1160.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-d7a82457455c4d0798c57d3f4632b8e8
Found initrd image: /boot/initramfs-0-rescue-d7a82457455c4d0798c57d3f4632b8e8.img
done
[root@centos8 network-scripts]# hostname
centos8.yama102
[root@centos8 network-scripts]# hostnamectl set-hostname centos7.yama102
[root@centos8 network-scripts]# hostname
centos7.yama102
[root@centos8 network-scripts]# cd /home/thd2017218049/2017218049
[root@centos8 2017218049]# ls
buble.c
[root@centos8 2017218049]# mv ./buble.c ./2017218049.c
[root@centos8 2017218049]# ls
2017218049.c
[root@centos8 2017218049]# gcc -v
bash: gcc: 未找到命令...
[root@centos8 2017218049]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
[root@centos8 2017218049]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2020-12-28 12:47:21--  http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 112.29.211.20, 112.28.200.242, 112.30.160.147, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|112.29.211.20|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”

100%[= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = >] 2523 -. - K/s when 0 sRepos. D/centos-base. Repo "[2523/2523]) [root@centos8 2017218049]# yum Fastestmirror, Langpacks, fastest paced * Base: mirrors.aliyun.com * Extras: mirrors.aliyun.com * updates: Mirrors.aliyun.com base | 3.6 kB 00:00 extras | 2.9 kB 00:00 updates | 2.9 kB 00:00 (1/10) : extras/7/x86_64/filelists_db | 224 kB 00:01 base/7/x86_64/primary_db FAILED http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/6d0c3a488c282fe537794b5946b01e28c7f44db79097bb06826e1c0c88 bad5ef-primary.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown Error "is trying another image. (2/10): extras/7/x86_64/primary_db | 222 kB 00:00 (3/10): base/7/x86_64/group_gz | 153 kB 00:02 (4/10): 7 / x86_64 / base/other_db | 2.6 MB 00:02 (5/10) : 7 / x86_64 / updates/other_db | 334 kB 00:00 (6/10) : 7 / x86_64 / updates/filelists_db | 2.7 MB 00:01onsaturday (UK time) (7/10) : Base/seven/x86_64 / primary_db | 6.1 MB 00:03 base/seven/x86_64 / filelists_db FAILED http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/d6d94c7d406fe7ad4902a97104b39a0d8299451832a97f31d71653ba982c955b -filelists.sqlite.bz2: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/d6d94c7d406fe7ad4902a97104b39a0d8299451832a97f31d71653ba982c955b -filelists.sqlite.bz2: (28, 'Connection timed out after 30000 milliseconds') extras/7/x86_64/other_db FAILED http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/2e9fd48ed164af0d6a80c2a07dc67c09d733ea94fbde75f81cc7076405c9 0124-other.sqlite.bz2: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/2e9fd48ed164af0d6a80c2a07dc67c09d733ea94fbde75f81cc7076405c9 0124-other.sqlite.bz2: (28, 'Connection timed out after 30000 milliseconds') (8/10) : 7 / base/x86_64 / filelists_db | 7.2 MB 00:03 (9/10) : extras/7/x86_64/other_db | 134 kB 00:01 updates/7/x86_64/primary_db FAILED http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/54834ed57c7c2b0259f68aa900001055256475f9349907045268aacc586 f0875-primary.sqlite.bz2: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/54834ed57c7c2b0259f68aa900001055256475f9349907045268aacc586 F0875-primary.sqlite.bz2: (28, 'Connection timed out after 30002 milliseconds') (10/10) : 7 / x86_64 / updates/primary_db | 4.7 MB metadata caching 00:01onsaturday (UK time) have been established [2017218049] root @ centos8 # RPM - q GCC not installed package GCC [root @ centos8 # fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: Mirrors.aliyun.com * extras: Mirrors.aliyun.com * updates: Mirrors.aliyun.com is resolving dependencies-->Checking transactions
--->The package GCC. X86_64.0.4.8.5-44.el7 will be installed
-->The dependency CPP = 4.8.5-44.el7 is being processed, which is required by the package gcc-4.8.5-44.el7.x86_64
-->The dependency glibc-devel >= 2.2.90-12 is being processed and is required by the package gcc-4.8.5-44.el7.x86_64
-->Checking transactions
--->The package cpp.x86_64.0.4.8.5-44.el7 will be installed
--->The package glibc-devel.x86_64.0.2.17-317.el7 will be installed
-->The dependency glibc-headers = 2.17-317.el7 is being processed, which is required by the package glibc-devel-2.17-317.el7.x86_64
-->Processing the glibc-HEADERS dependency, which is required by the package glibc-devel-2.17-317.el7.x86_64
-->Checking transactions
--->The package glibc-headers. X86_64.0.2.17-317. el7 will be installed
-->Kernel-headers >= 2.2.1, which is required by the package glibc-headers 2.17-317.el7.x86_64
-->Processing the kernel-headers dependency, which is required by the package glibc-headers 2.17-317.el7.x86_64
-->Checking transactions
--->The package kernel-headers. X86_64.0.3.10.0-1160.11.1.el7 will be installed
-->Resolve dependency completionDependencies to solve = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = source size Package framework version = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = are installing: GCC x86_64 4.8.5-44.el7 base 16 M CPP x86_64 4.8.5-44.el7 base 5.9m glibc-devel x86_64 2.17-317.el7 base 1.1m glibc-headers x86_64 2.17-317.el7 base 690 K kernel-headers x86_64 3.10.0-1160.11.1.el7 updates 9.0m = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 1 installation package (+ 4 relied on package) total downloads: 33 M installation size: 50 M Downloading packages: Downloading /var/cache/yum/x86_64/7/base/packages/ Cp-48.5-44.el7.x86_64. RPM: Downloading /var/cache/yum/x86_64/7/base/packages/ cp-48.5-44.el7.x86_64. RPM Key ID F4a80eb5: NOKEY CPP-4.8.5-44.el7.x86_64. RPM Public key not installed (1/5): CPP - 4.8.5-44. El7. X86_64. RPM | 5.9 MB 00:03 (2/5) : glibc - devel - 2.17-317. El7 x86_64. RPM | 1.1 MB 00:00 (3/5) : Glibc - headers - 2.17-317. El7. X86_64. RPM | 690 kB 00:00 (4/5) : GCC - 4.8.5-44. El7. X86_64. RPM | 16 MB 00:08 kernel headers - 3.10.0-1160.11.1. El7. X86_64. RPM public key has not been installed 32 MB 00:00 ETA (5/5) : The kernel - the headers - 3.10.0-1160.11.1. El7. X86_64. RPM 9.0 MB 00:04 | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- a total of 3.5 MB/s | from 33 MB 00:09 http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 to retrieve the key import GPG key 0 xf4a80eb5: user ID: "CentOS 7 Key (CentOS 7 Official Signing Key) <[email protected]>" 6341 AB27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 Running transaction check Running transaction test Transaction Test Succeeded Running Transaction Installing: cpP-4.8.5-44.el7.x86_64 1/5 Installing: Kernel-headers 3.10.0-1160.11.1.el7.x86_64 2/5 Installation: glibc-headers 2.17-317.el7.x86_64 3/5 Installation: glibc-headers 2.17-317.el7.x86_64 3/5 installation: glibc-headers 2.17-317.el7.x86_64 3/5 installation: Glibc-vel 2.17-317.el7.x86_64 1/5 gcc-4.8.5-44.el7.x86_64 1/5 gcc-4.8.5-44.el7.x86_64 1/5 glibc-vel 2.17-317.el7.x86_64 1/5 gcc-4.8.5-44.el7.x86_64 1/5 gcc-4.8.5-44.el7.x86_64 1/5 gcc-4.8.5-44.el7.x86_64 1/5 Kernel-headers 3.10.0-1160.11.1.el7.x86_64 3/5 verify that gcc-4.8.5-44.el7.x86_64 is valid. Glibc-headers 2.17-317.el7.x86_64 4/5: cpp-4.8.5-44.el7.x86_64 5/5: GCC. X86_64 0:4.8.5-44.el7 is installed as a dependency. Cpp.x86_64 0:4.8.5-44.el7 glibc-vel. X86_64 0:2.17-317.el7 glibc-headers. X86_64 0:2.17-317.el7 kernel-headers Finished 3-0. 10.0 1160.11.1. El7! [root@centos8 2017218049]# RPM -q GCC gcc-4.8.5-44.el7.x86_64 [root@centos8 2017218049]# RPM -q GCC gcc-4.8.5-44.el7.x86_64 [root@centos8 2017218049]# RPM /home/thd2017218049/2017218049 [root@centos8 2017218049]# ls 2017218049.c [root@centos8 2017218049]# touch Makefile [root@centos8 2017218049]# vim Makefile [root@centos8 2017218049]# vim Makefile [root@centos8 2017218049]# make clean rm -rf hello *.elf *.gdb *. O [root@centos8 2017218049]# make make: *** No rule can create the target "hello" required by "hello". Stop. [root@centos8 2017218049]# vim Makefile [root@centos8 2017218049]# make clean Makefile:1: *** omit delimiter. Stop. [root@centos8 2017218049]# vim Makefile [root@centos8 2017218049]# make clean Makefile:1: *** omit delimiter. Stop. [root@centos8 2017218049]# GCC -o 2017218049 2017218049.c 2017218049.c: Error: Only allowed in C99 mode with 'for' loop initializer declaration for(int I = 0; i < 10; I ++){^ 2017218049.c:14:5: Note: Use -std=c99 or -std=gnu99 to compile your code 2017218049.c:19:9: Error: 'I' restated as no external link int I; ^ 2017218049.c:14:13: note: for(int I = 0; i < 10; i++){ ^ [root@centos8 2017218049]# vim 2017219049.c [root@centos8 2017218049]# ls 2017218049.c Makefile [root@centos8 2017218049]# vim 2017218049.c [root@centos8 2017218049]# vim 2017218049.c [root@centos8 2017218049]# gcc -o 2017218049 2017218049.c [root@centos8 2017218049]# ls 2017218049 2017218049.c Makefile [root@centos8 2017218049]# ./2017218049 3 4 5 2 6 8 78 34 12 9 2 3 4 5 6 8 9 12 34 78 [root@centos8 2017218049]#Copy the code