Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to perform network management, software installation and process management in Linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how Linux manages its network, installs software, and manages processes. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. Network management

1.1 Network status View

In Linux, ifconfig,route and netstat are often used to check the network status, which is. Net-tools tool, let me use it next.

I'm just talking about ifconfig and route.

There are many network card interfaces in our linux, such as eth0's first network card network interface, eno1 on-board "network card, ens33 PCI-E" network card. If CentOS 7 uses the "sex-causing" network device name, but none of the above matches, it will make eth0.

[root@node01 ~] # ifconfig eth0 eth0: error fetching interface information: Device not found [root@node01 ~] # ifconfig ens33 ens33: flags=4163 mtu 1500 inet 192.168.92.90 netmask 255.255.255.0 broadcast 192.168.92.255 inet6 fe80::b889:1772:c306:ef8f prefixlen 64 scopeid 0x20 ether 00:0c:29:07:43:5A txqueuelen 1000 (Ethernet) RX packets 910 bytes 954985 (932.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 450 bytes 38942 (38.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

1.2 Network profile

Vim / etc/hosts Network profile

When configuring a hadoop,elasticsearch cluster, you need to configure the cluster IP and hostname in / etc/hosts. Sometimes you can't ping Baidu, maybe the domain name cannot be resolved, and you need to configure it in / etc/sysconfig/network-scripts/ifcfg-eth0.

[root@node01 ~] # vim / etc/sysconfig/network # HOSTNAME=node01 [root@node01 ~] # vim / etc/hosts # 192.168.92.90 node01 192.168.92.91 node02 192.168.92.92 node03 [root@node01 ~] # configure DNS, domain name resolution service [root@node01 ~] # vim / etc/sysconfig/network-scripts/ifcfg-eth0 DNS1=202.106.0.20 DNS2=8.8.8.8

1.3 Network troubleshooting commands

First, ping Baidu: check whether the network of the target machine is reachable.

Maoli@ubuntu:~$ ping baidu.com PING baidu.com (220.181.38.148) 56 (84) bytes of data. 64 bytes from 220.181.38.148: icmp_seq=1 ttl=128 time=49.6 ms 64 bytes from 220.181.38.148: icmp_seq=2 ttl=128 time=48.2 ms ^ C-baidu.com ping statistics-2 packets transmitted, 2 received, 0% packet loss, time 1001ms rtt min/avg/max/mdev = 48.223 ms 49.673 ms

The nslookup tool can resolve domain names in the format of nslookup space + domain name.

Like nslookup www.baidu.com. Server is the ip corresponding to the domain name.

Maoli@ubuntu:~$ nslookup www.baidu.com Server: 127.0.1.1 Address: 127.0.1.1: 53 Non-authoritative answer: www.baidu.com canonical name = www.a.shifen.com. Name: www.a.shifen.com Address: 182.61.200.6 Name: www.a.shifen.com Address: 182.61.200.7

Tcpdump is a tool for intercepting network packets and outputting packet contents. With its powerful function and flexible interception strategy, it has become the preferred tool for network analysis and problem troubleshooting in UNIX-like systems.

For example, tcpdump-I any-n port 80 grabs all network card (any) port 80 packets and displays them in ip form (- n)

Maoli@ubuntu:~$ sudo tcpdump-I any-n port 80-n 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 10purge 28 tcpdump 11.003675 IP 192.168.92.1.53951 > 192.168.92.135.80: Flags [S], seq 185886164, win 64240, options [mss 1460 noprection wscale Length 0 10 seq 28 IP 11.003875 IP 192.168.92.135.80 > 192.168.92.1.53951: Flags [S.], seq 2863640054, ack 185886165, win 64240, options [mss 1460 Flags win 4114 IP 192.168.92.1.53951 > 192.168.92.135.80: Flags [.], ack 1, win 4106 Length 010: 28 seq 11.010472 IP 192.168.92.1.53951 > 192.168.92.135.80: Flags [P.], seq 1 Flags, ack 1, win 4106, length 475: HTTP: GET / sqli-labs/ HTTP/1.1

For example, tcpdump-I any-n host 10.0.0.1 and port 80 grabs packets between port 80 and 10.0.0.1 of all network cards and displays them in the form of ip

The netstat command is used to display statistics related to the IP, TCP, UDP, and ICMP protocols, and is generally used to verify the network connectivity of each port of the machine. Netstat is a program that accesses network and related information in the kernel. It can provide reports on TCP connection, TCP and UDP snooping, and process memory management.

Netstat to check whether the status of the service listening port is correct

-n display ip address-t tcp protocol-p display the process corresponding to the port-listening status of l tcp (listen)-ntpl to view port opening

Maoli@ubuntu:~$ sudo netstat-ntlp activates Internet connection (server only) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0 Internet 22 0.0.0 0 LISTEN 1111/sshd tcp 0 0 127.0.1 .0.0.0: * LISTEN 14200/cupsd tcp 00 127.0.0.1 tcp 3306 0.0.0.0 LISTEN 1148/mysqld tcp 00 127.0.0.1 LISTEN 1165/redis-server 1 tcp 0 0 127.0.1.1 LISTEN 53 0.0.0.0 LISTEN 1285/dnsmasq tcp6 0: 22:: * LISTEN 1111/sshd tcp6 0 0:: * LISTEN 14200/cupsd tcp6 00: 9000: * LISTEN 2234/docker-proxy tcp6 00: 80: * LISTEN 1842/apache2

1.4 Network service management

There are two kinds of network service management programs, SysV and systemd. Now Systemd has basically replaced SysV's Init.

1.5 set static ip

When building any cluster, you need to set up static ip.

[root@node01] # vim / etc/sysconfig/network-scripts/ifcfg-ens33 # BOOTPROTO=static ONBOOT= "yes" # Gateway address depends on the network of the system. Static ip IPADDR=192.168.92.92 NETMASK=255.255.255.0 # set by GATEWAY=192.168.92.2 # configures DNS server DNS1=8.8.8.8 DNS2=8.8.4.4

two。 Software installation

2.1 rpm installation

Under the Linux operating system, almost all software is installed, uninstalled and managed through RPM. The full name of RPM is Redhat Package Manager, which is proposed by Redhat Company and is used to manage the software package under Linux. It is mainly used in CentOS, RedHat and other linux systems. The format of the software installation package is rpm.

For example, a rpm of vim is called vim-common-7.4.10-5.el7.x86_64.rpm. Vim-common is the software name, 7.4.10-5 software version, el7 is Red Hat Enterprise Linux refers to the centos7 system version, x86x64 refers to the system platform x86

Rpm command common arguments,-Q query package,-I installation package and-e uninstall package

2.2 yum package Manager

Yum (full name Yellow dog Updater, Modified) is a front-end package manager, based on RPM package management, can automatically download and install RPM packages from specified servers, and automatically deal with dependency relationships.

Download the yum source of Aliyun to / etc/yum.repos.d

Backup yum sourc

Mv / etc/yum.repos.d/CentOS-Base.repo / etc/yum.repos.d/CentOS-Base.repo.backup

Download the new CentOS-Base.repo to / etc/yum.repos.d/, which refers to centos7

Wget-O / etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo # run yum makecache build cache yum clean all yum makecache

You can check the base of yum at this time.

[root@node01 ~] # vim / etc/yum.repos.d/CentOS-Base.repo [base] name=CentOS-$releasever-Base-mirrors.aliyun.com failovermethod=priority baseurl= http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey= http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

Because some mirror in yum is very slow. For this, I can download the fastestmirror plug-in.

[root@node01] # yum install yum-fastestmirror-y [root@node01 ~] # cat / etc/yum/pluginconf.d/fastestmirror.conf [main] enabled=1 verbose=0 always_print_best_host = true socket_timeout=3 # Relative paths are relative to the cachedir (and so works for users as well # as root). Hostfilepath=timedhosts.txt maxhostfileage=10 maxthreads=15 # exclude=.gov, facebook # include_only=.nl,.de,.uk,.ie

Yum commonly used commands install install package, remove uninstall package, list | grouplist view package, update upgrade package

2.3 apt installation

Ubuntu Advanced Packaging tool (APT,Advanced Packaging Tool), Debian, Ubuntu make the apt package manager, the software installation package format is deb.

Apt installs a nginx

Maoli@ubuntu:~$ sudo apt-get install nginx / usr/sbin/nginx: main program / etc/nginx: storing configuration files / usr/share/nginx: storing static files / var/log/nginx: storing logs

2.4 installation of make install compiler source code installation source code

Generally, it consists of three steps: configure, make, and make install.

The configure file is an executable script file with many options, and you can output a detailed list of options using the command. / configure-help in the source directory to be installed.

The-- prefix option is to configure the installation directory. If you do not configure this option, the executable files will be placed at / usr/local/ bin by default, the library files will be placed at / usr/local/lib by default, the configuration files will be placed at / usr/local/etc by default, and other resource files will be placed in / usr/local/ share, which is messy.

If-- prefix is configured, for example:. / configure-- all resource files after prefix=/usr/local/python3 installation will be placed in the / usr/local/python3 directory and will not be dispersed to other directories. If you delete it, just delete the file directly.

For example, centos7 installs Python3.6

[root@node01 ~] # yum install yum-utils [root@node01 ~] # yum install openssl-devel-y [root@node01 ~] # mkdir-p / usr/local/python3 [root@node01 ~] # cd / usr/local/python3/ [root@node01 python3] # wget https://www.python.org/ftp/python/3.6.7/Python-3.6.7.tgz [root@node01 python3] # tar-zxvf Python-3.6.7.tgz [root@node01 Python3] # cd Python-3.6.7 [root@node01 python3.6.7] #. / configure-- prefix=/usr/local/python3-- with-ssl [root@node01 python3.6.7] # make & & make install Installing collected packages: setuptools Pip Successfully installed pip-10.0.1 setuptools-39.0. [root@node01 python3.6.7] # cd.. [root@node01 Python3] # ln-s / usr/local/python3/bin/python3 / usr/bin/python3 [root@node01 Python3] # ln-s / usr/local/python3/bin/pip3 / usr/bin/pip3 [root@node01 Python3] # python3-V Python 3.6.7 [root@node01 Python3] # python3 Python 3.6.7 (default, Mar 5 2020, 11:00:15) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux Type "help", "copyright" "credits" or "license" for more information. > > exit ()

3. Process management

A process is an abstraction of running applications in Unix and Linux systems, through which you can manage and monitor the program's use of memory, processor time, and I / O resources.

3.1 killing process

In many cases, you need to kill processes. Ps-ef can view all processes. Ps-ef | grep to view the processes of specific tasks.

For example, check the Mysql process

[root@node01 ~] # ps-ef | grep mysql clouder+ 1726 1 38 15:16? 00:04:34 / usr/java/jdk1.8.0_241/bin/java-cp.: / usr/share/java/mysql-connector-java.jar:/usr/share/java/oracle-connector-java.jar:/usr/share/java/postgresql-connector-java.jar:lib/*-server-Dlog4j.configuration=file:/etc/cloudera-scm-server/log4j.properties-Dfile.encoding=UTF-8-Dcmf.root.logger=INFO LOGFILE-Dcmf.log.dir=/var/log/cloudera-scm-server-Dcmf.log.file=cloudera-scm-server.log-Dcmf.jetty.threshhold=WARN-Dcmf.schema.dir=/opt/cloudera/cm/schema-Djava.awt.headless=true-Djava.net.preferIPv4Stack=true-Dpython.home=/opt/cloudera/cm/python-Dpython.home=/opt/cloudera/cm/python-XX:+UseParNewGC-XX:+HeapDumpOnOutOfMemoryError-Xmx2G-XX:MaxPermSize=256m-XX:+HeapDumpOnOutOfMemoryError-XX:HeapDumpPath=/tmp-XX:OnOutOfMemoryError=kill-9% p com.cloudera.server.cmf.Main mysql 2745 10 15:16? 00:00:04 / usr/sbin/mysqld-- daemonize-- pid-file=/var/run/mysqld/mysqld.pid root 9864 4959 0 15:28 pts/0 00:00:00 grep-- color=auto mysql

| finds the process that matches the specified condition-"pgrep", which is ps-ef | grep abbreviation |

[root ~] $pgrep mysqld 3584

Check the process of the port, for example, the port of mysql is 3306

[root@node01] # lsof-iCOMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 3306 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 1726 cloudera-scm 285u IPv4 50625 0t0 TCP localhost:58292- > localhost:mysql (ESTABLISHED) mysqld 2745 mysql 27u IPv6 47164 0t0 TCP *: mysql (LISTEN) mysqld 2745 mysql 40u IPv6 54060 0t0 TCP localhost:mysql- > localhost:58296 (E

Killing a process using kill-9 commands, such as kill-9 1726, is killing the Mysql process.

3.2 Daemon

The daemon is commonly known as the daemon process, which is a process executed in the background of linux. It will not stop running with the shutdown of the terminal. Those who open the Linux system will open it automatically.

Run the command without hanging up. The abbreviation of no hangup means "don't hang up". And & combined

[root@node01 ~] # tail-f / var/log/messages May 1 16:01:10 node01 kubelet: I0501 16 var/log/messages May 01purl 10.344757 26130 server.go:837] Client rotation is on Will bootstrap in background [root@node01 ~] # ps-ef | grep tail root 26210 25353 0 16:01 pts/1 00:00:00 tail-f / var/log/messages root 26555 25310 0 16:01 pts/0 00:00:00 grep-- color=auto tail close the above tail-f / var/log/messages [root@node01 ~] # ps-ef | grep tail [root@node01 ~] # ps-ef | grep tail root 27353 25310 0 16:03 pts/0 00:00:00 grep-- color=auto tail

Nohup is generally required in conjunction with &

[root@node01] # nohup tail-f / var/log/messages & [1] 27718 nohup: ignore input and append output to "nohup.out" [root@node01 ~] # ps-ef | grep tail root 27718 25353 0 16:04 pts/1 00:00:00 tail-f / var/log/messages root 29444 25310 0 16:07 pts/0 00:00:00 grep-color=auto tail close nohup tail-f / var/log/messages & above [root@node01] # ps-ef | grep tail root 27718 10 16:04? 00:00:00 tail-f / var/log/messages root 29946 25310 0 16:08 pts/0 00:00:00 grep-- color=auto tail

3.3 View Progress

Ps-ef View process

[root] # ps-ef UID PID PPID C STIME TTY TIME CMD root 1 00 Jun23? 00:00:05 / usr/lib/systemd/systemd-- switched-root-- system-- deserialize 21 root 2 00 Jun23? 00:00:00 [kthreadd]. [root ~] # ps-ef | grep mysqld root 4943 4581 0 22:45 pts/0 00:00:00 grep-color=auto mysqld mysql 25257 10 Jun25? 00:00:39 / usr/sbin/mysqld-- daemonize-- pid-file=/var/run/mysqld/mysqld.pid Thank you for reading! This is the end of the article on "how Linux carries out network management, software installation, and process management operations". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report