自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

關(guān)于Linux網(wǎng)絡(luò)管理,軟件安裝,進(jìn)程管理總結(jié)

系統(tǒng) Linux
在Linux中經(jīng)常使用ifconfig,route和netstat查看網(wǎng)絡(luò)狀態(tài),它們就是. net-tools工具,下面我來(lái)使用下。

[[353269]]

 1、網(wǎng)絡(luò)管理

1.1 網(wǎng)絡(luò)狀態(tài)查看

在Linux中經(jīng)常使用ifconfig,route和netstat查看網(wǎng)絡(luò)狀態(tài),它們就是. net-tools工具,下面我來(lái)使用下。

我就說(shuō)下ifconfig和route

在我們的linux中有很多網(wǎng)卡接口,比如eth0第一塊網(wǎng)卡網(wǎng)絡(luò)接口,eno1板載⽹網(wǎng)卡, ens33 PCI-E⽹網(wǎng)卡 。CentOS 7 使⽤用了⼀致性⽹絡(luò)設(shè)備命名,以上都不匹配,則使⽤ eth0

  1. [root@node01 ~]# ifconfig eth0 
  2. eth0: error fetching interface information: Device not found 
  3. [root@node01 ~]# ifconfig ens33 
  4. ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500 
  5.         inet 192.168.92.90  netmask 255.255.255.0  broadcast 192.168.92.255 
  6.         inet6 fe80::b889:1772:c306:ef8f  prefixlen 64  scopeid 0x20<link> 
  7.         ether 00:0c:29:07:43:5A  txqueuelen 1000  (Ethernet) 
  8.         RX packets 910  bytes 954985 (932.6 KiB) 
  9.         RX errors 0  dropped 0  overruns 0  frame 0 
  10.         TX packets 450  bytes 38942 (38.0 KiB) 
  11.         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0 

1.2 網(wǎng)絡(luò)配置文件

vim /etc/hosts網(wǎng)絡(luò)配置文件

在配置hadoop,elasticsearch集群的時(shí)候需要在/etc/hosts配置集群IP和主機(jī)名,有時(shí)候你ping不了百度,可能域名解析不了,需要在/etc/sysconfig/network-scripts/ifcfg-eth0配置

  1. [root@node01 ~]# vim /etc/sysconfig/network 
  2. ######### 
  3. HOSTNAME=node01 
  4. [root@node01 ~]# vim /etc/hosts 
  5. ######### 
  6. 192.168.92.90 node01 
  7. 192.168.92.91 node02 
  8. 192.168.92.92 node03 
  9.  
  10. [root@node01 ~]# 配置DNS,域名解析服務(wù) 
  11. [root@node01 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 
  12. DNS1=202.106.0.20 
  13. DNS2=8.8.8.8 

1.3 網(wǎng)絡(luò)故障排除命令

第一,ping百度:查看目標(biāo)機(jī)器的網(wǎng)絡(luò)是否可通

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

nslookup 工具就可以對(duì)域名解析, 格式是nslookup空格+域名

比如nslookup www.baidu.com 。Server即為域名對(duì)應(yīng)的ip

  1. maoli@ubuntu:~$ nslookup www.baidu.com 
  2. Server:  127.0.1.1 
  3. Address: 127.0.1.1#53 
  4.  
  5. Non-authoritative answer: 
  6. www.baidu.com canonical name = www.a.shifen.com. 
  7. Name: www.a.shifen.com 
  8. Address: 182.61.200.6 
  9. Name: www.a.shifen.com 
  10. Address: 182.61.200.7 

tcpdump是一個(gè)用于截取網(wǎng)絡(luò)分組,并輸出分組內(nèi)容的工具。憑借強(qiáng)大的功能和靈活的截取策略,使其成為類UNIX系統(tǒng)下用于網(wǎng)絡(luò)分析和問題排查的首選工具

比如tcpdump -i any -n port 80 抓取所有網(wǎng)卡(any)80端口數(shù)據(jù)包,并且以ip形式顯示(-n)

  1. maoli@ubuntu:~$ sudo tcpdump -i any -n port 80 -n 
  2. tcpdump: verbose output suppressed, use -v or -vv for full protocol decode 
  3. listening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes 
  4. 10:28:11.003675 IP 192.168.92.1.53951 > 192.168.92.135.80: Flags [S], seq 185886164, win 64240, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0 
  5. 10:28:11.003875 IP 192.168.92.135.80 > 192.168.92.1.53951: Flags [S.], seq 2863640054, ack 185886165, win 64240, options [mss 1460,nop,nop,sackOK,nop,wscale 7], length 0 
  6. 10:28:11.004114 IP 192.168.92.1.53951 > 192.168.92.135.80: Flags [.], ack 1, win 4106, length 0 
  7. 10:28:11.010472 IP 192.168.92.1.53951 > 192.168.92.135.80: Flags [P.], seq 1:476, ack 1, win 4106, length 475: HTTP: GET /sqli-labs/ HTTP/1.1 

比如tcpdump -i any -n host 10.0.0.1 and port 80 抓取所有網(wǎng)卡的80端口和10.0.0.1之間的數(shù)據(jù)包,并且以ip形式顯示

netstat命令用于顯示與IP、TCP、UDP和ICMP協(xié)議相關(guān)的統(tǒng)計(jì)數(shù)據(jù),一般用于檢驗(yàn)本機(jī)各端口的網(wǎng)絡(luò)連接情況。netstat是在內(nèi)核中訪問網(wǎng)絡(luò)及相關(guān)信息的程序,它能提供TCP連接,TCP和UDP監(jiān)聽,進(jìn)程內(nèi)存管理的相關(guān)報(bào)告。

netstat 查看服務(wù)監(jiān)聽端口狀態(tài)是否正確

-n 顯示ip地址-t tcp協(xié)議-p 顯示端口對(duì)應(yīng)的進(jìn)程-l tcp的監(jiān)聽狀態(tài)(listen)-ntpl 查看端口開放情況

  1. maoli@ubuntu:~$ sudo netstat -ntlp 
  2. 激活I(lǐng)nternet連接 (僅服務(wù)器) 
  3. Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name 
  4. tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1111/sshd        
  5. tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      14200/cupsd      
  6. tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1148/mysqld      
  7. tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      1165/redis-server 1 
  8. tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN      1285/dnsmasq     
  9. tcp6       0      0 :::22                   :::*                    LISTEN      1111/sshd        
  10. tcp6       0      0 ::1:631                 :::*                    LISTEN      14200/cupsd      
  11. tcp6       0      0 :::9000                 :::*                    LISTEN      2234/docker-proxy 
  12. tcp6       0      0 :::80                   :::*                    LISTEN      1842/apache2  

1.4 網(wǎng)絡(luò)服務(wù)管理

網(wǎng)絡(luò)服務(wù)管理程序分為兩種,分別為SysV和systemd。現(xiàn)在Systemd已經(jīng)基本取代了SysV的Init。

1.5 設(shè)置靜態(tài)ip

在搭建任何集群,都是要設(shè)置靜態(tài)ip的。

  1. [root@node01]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 
  2.  
  3. ################ 
  4. BOOTPROTO=static 
  5. ONBOOT="yes" 
  6. # 網(wǎng)關(guān)地址根據(jù)系統(tǒng)的網(wǎng)絡(luò)而定 
  7. GATEWAY=192.168.92.2 
  8. # 設(shè)置的靜態(tài)ip 
  9. IPADDR=192.168.92.92 
  10. NETMASK=255.255.255.0 
  11. # 配置DNS服務(wù)器 
  12. DNS1=8.8.8.8 
  13. DNS2=8.8.4.4 

2. 軟件安裝

2.1 rpm安裝

在 Linux 操作系統(tǒng)下,幾乎所有的軟件均通過RPM 進(jìn)行安裝、卸載及管理等操作。RPM 的全稱為Redhat Package Manager ,是由Redhat 公司提出的,用于管理Linux 下軟件包的軟件,主要用于CentOS、RedHat等linux系統(tǒng),軟件安裝包格式為 rpm。

比如一個(gè)vim的rpm叫:vim-common-7.4.10-5.el7.x86_64.rpm 。vim-common是軟件名稱,7.4.10-5軟件版本,el7是Red Hat Enterprise Linux 指的是centos7系統(tǒng)版本,x86_64指的是系統(tǒng)平臺(tái)x86

rpm 命令常⽤參數(shù),-q 查詢軟件包,-i 安裝軟件包和-e 卸載軟件包

2.2 yum 包管理器

yum(全稱 Yellow dog Updater, Modified)是一個(gè)前端軟件包管理器,基于RPM包管理,能夠從指定的服務(wù)器自動(dòng)下載RPM包并且安裝,可以自動(dòng)處理依賴性關(guān)系。

下載阿里云的yum源到了/etc/yum.repos.d中

備份yum源

  1. mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 

下載新的CentOS-Base.repo 到/etc/yum.repos.d/,這里指的是centos7

  1. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 
  2. # 運(yùn)行yum makecache生成緩存 
  3. yum clean all 
  4. yum makecache 

這時(shí)候可以查看yum的base

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

由于yum中有的mirror速度是非常慢的。對(duì)此,我可以下載fastestmirror插件。

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

yum常用命令install 安裝軟件包,remove 卸載軟件包,list| grouplist 查看軟件包,update 升級(jí)軟件包

2.3 apt安裝

Ubuntu的高級(jí)打包工具(APT,Advanced Packaging Tool ),Debian、Ubuntu 使⽤ apt 包管理器,軟件安裝包格式為 deb。

apt安裝一個(gè)nginx

  1. maoli@ubuntu:~$ sudo apt-get install nginx 
  2. /usr/sbin/nginx:主程序 
  3. /etc/nginx:存放配置文件 
  4. /usr/share/nginx:存放靜態(tài)文件 
  5. /var/log/nginx:存放日志 

2.4 make install編譯源碼安裝源碼的安裝

一般由3個(gè)步驟組成:配置(configure)、編譯(make)、安裝(make install)。

configure文件是一個(gè)可執(zhí)行的腳本文件,它有很多選項(xiàng),在待安裝的源碼目錄下使用命令./configure –help可以輸出詳細(xì)的選項(xiàng)列表。

其中--prefix選項(xiàng)是配置安裝目錄,如果不配置該選項(xiàng),安裝后可執(zhí)行文件默認(rèn)放在/usr /local/bin,庫(kù)文件默認(rèn)放在/usr/local/lib,配置文件默認(rèn)放在/usr/local/etc,其它的資源文件放在/usr /local/share,比較凌亂。

如果配置了--prefix,如:./configure --prefix=/usr/local/python3安裝后的所有資源文件都會(huì)被放在/usr/local/python3目錄中,不會(huì)分散到其他目錄。如果刪除直接刪除這個(gè)文件就可以了。

比如centos7安裝Python3.6

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

3. 進(jìn)程管理

進(jìn)程 是 Unix 和 Linux 系統(tǒng)中對(duì)正在運(yùn)行中的應(yīng)用程序的抽象,通過它可以管理和監(jiān)視程序?qū)?nèi)存、處理器時(shí)間和 I / O 資源的使用。

3.1 殺進(jìn)程

很多時(shí)候需要?dú)⑦M(jìn)程,ps -ef可以查看所有的進(jìn)程,ps -ef|grep 查看具體的任務(wù)的進(jìn)程,

比如查看Mysql進(jìn)程

  1. [root@node01 ~]# ps -ef|grep mysql 
  2. 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 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+HeapDumpOnOutOfMemoryError -Xmx2G -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp -XX:OnOutOfMemoryError=kill -9 %p com.cloudera.server.cmf.Main 
  3. mysql      2745      1  0 15:16 ?        00:00:04 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 
  4. root       9864   4959  0 15:28 pts/0    00:00:00 grep --color=auto mysql 

查找與指定條件匹配的進(jìn)程 - 「pgrep」,,就是ps -ef|grep縮寫

  1. [root ~]$ pgrep mysqld 
  2. 3584 

查看端口的進(jìn)程,比如mysql的端口是3306

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

殺進(jìn)程使用kill -9命令,比如 kill -9 1726,就是殺Mysql進(jìn)程

3.2 守護(hù)進(jìn)程

守護(hù)進(jìn)程就是通常說(shuō)的daemon進(jìn)程,是linux后臺(tái)執(zhí)行的一種進(jìn)程,不會(huì)隨著終端的關(guān)閉而停止運(yùn)行,開Linux系統(tǒng)的會(huì)自動(dòng)打開。

不掛斷地運(yùn)行命令。no hangup的縮寫,意即“不掛斷”。和&聯(lián)用

  1. [root@node01 ~]# tail -f /var/log/messages 
  2. May  1 16:01:10 node01 kubelet: I0501 16:01:10.344757   26130 server.go:837] Client rotation is on, will bootstrap in background 
  3.  
  4. [root@node01 ~]# ps -ef|grep tail 
  5. root      26210  25353  0 16:01 pts/1    00:00:00 tail -f /var/log/messages 
  6. root      26555  25310  0 16:01 pts/0    00:00:00 grep --color=auto tail 
  7.  
  8. 關(guān)閉上面的tail -f /var/log/messages 
  9.  
  10. [root@node01 ~]# ps -ef|grep tail 
  11. [root@node01 ~]# ps -ef|grep tail 
  12. root      27353  25310  0 16:03 pts/0    00:00:00 grep --color=auto tail 

一般需要nohup和 &連用

  1. [root@node01 ~]# nohup tail -f /var/log/messages & 
  2. [1] 27718 
  3. nohup: 忽略輸入并把輸出追加到"nohup.out" 
  4.  
  5. [root@node01 ~]# ps -ef|grep tail 
  6. root      27718  25353  0 16:04 pts/1    00:00:00 tail -f /var/log/messages 
  7. root      29444  25310  0 16:07 pts/0    00:00:00 grep --color=auto tail 
  8. 關(guān)閉上面的nohup tail -f /var/log/messages & 
  9.  
  10. [root@node01 ~]# ps -ef|grep tail 
  11. root      27718      1  0 16:04 ?        00:00:00 tail -f /var/log/messages 
  12. root      29946  25310  0 16:08 pts/0    00:00:00 grep --color=auto tail 

3.3 查看進(jìn)程

ps -ef查看進(jìn)程

  1. [root ~]# ps -ef 
  2. UID        PID  PPID  C STIME TTY          TIME CMD 
  3. root         1     0  0 Jun23 ?        00:00:05 /usr/lib/systemd/systemd --switched-root --system --deserialize 21 
  4. root         2     0  0 Jun23 ?        00:00:00 [kthreadd] 
  5. ... 
  6. [root ~]# ps -ef | grep mysqld 
  7. root      4943  4581  0 22:45 pts/0    00:00:00 grep --color=auto mysqld 
  8. mysql    25257     1  0 Jun25 ?        00:00:39 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 

本文已收錄 GitHub,傳送門~[1] ,里面更有大廠面試完整考點(diǎn),歡迎 Star。

Reference

[1]傳送門~:https://github.com/MaoliRUNsen/runsenlearnpy100

 

責(zé)任編輯:姜華 來(lái)源: Python之王
相關(guān)推薦

2011-01-11 13:47:27

Linux管理進(jìn)程

2011-08-11 11:37:34

iPhone內(nèi)存

2023-03-05 16:12:41

Linux進(jìn)程線程

2012-07-04 10:47:56

軟件項(xiàng)目項(xiàng)目管理項(xiàng)目流程

2010-02-25 10:28:43

Linux進(jìn)程管理

2009-10-23 17:35:16

linux進(jìn)程管理

2023-03-02 23:50:36

Linux進(jìn)程管理

2014-08-01 15:38:37

Linux進(jìn)程管理

2011-03-10 15:34:21

網(wǎng)絡(luò)管理

2023-03-03 00:03:07

Linux進(jìn)程管理

2013-10-11 14:51:16

Linux進(jìn)程管理

2021-04-22 07:47:46

Linux進(jìn)程管理

2021-04-15 05:51:25

Linux

2009-03-05 09:43:32

Linux系統(tǒng)進(jìn)程管理命令

2017-01-15 20:58:04

Linux進(jìn)程作業(yè)管理

2021-03-17 21:34:44

Linux內(nèi)存管理

2021-06-15 08:02:55

Linux 進(jìn)程管理

2022-11-09 08:12:07

2010-01-13 09:33:53

CentOS安裝

2015-07-21 16:06:49

Linux進(jìn)程管理命令
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)