Linux常用命令

本文最后更新于:2 个月前

一 、Linux常用命令

1. 常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
cd /home/test  
删缓存 rm -rf cache/ data/ logs/ tmp/
启动脚本 sh start.sh
看日志:tail -1000f out.log
grep -C 2000 --color 26201901360202000000000049 cxcb40_8714.out
获取进程端口号:fuser -n tcp 8081
kill -9 端口号
启动:
cd /home/weblogic/Oracle/Middleware/user_projects/domains/test_domain
nohup sh startWebLogic.sh &

测试环境redis
cd /home/tomcat/redis/bin
命令 : ./redis-server redis.conf

zip -q -r test20200904.zip test/
## 解压乱码问题 CP936 / GBK / GB18030
# 大写O 0oO
unzip -O CP936 xxx.zip
unzip -O GBK xxx.zip
unzip -O gbk xxx.zip

## 服务启动命令
systemctl start fail2ban

# 查看报错信息
journalctl -xe


# 创建日志文件
sudo touch /var/log/dropbear.log
# 赋权
sudo chmod 600 /var/log/dropbear.log
chmod 664 /etc/fail2ban/filter.d/banit.conf

# iptables命令
iptables -I INPUT -p tcp --dport 80 -j DROP

2. tcp服务监听

linux查看tcp络连接日志,Linux监控TCP连接数并触发日志记录

https://blog.csdn.net/weixin_31642733/article/details/116861430

linux tcp连接数分析,查看linux中的TCP连接数

https://blog.csdn.net/weixin_39606177/article/details/116970221

在Linux系统中,可以使用一些工具来排查TCP连接并进行分析。以下是一些常用的方法和工具:

  1. 使用netstat命令:netstat命令可以显示当前系统上的网络连接信息。通过使用不同的选项,可以获取TCP连接的状态、本地和远程IP地址、端口号等信息。例如,使用netstat -an | grep ESTABLISHED可以列出所有处于ESTABLISHED状态的TCP连接。
  2. 使用ss命令:ss命令是netstat的替代工具,提供更快速和更详细的网络连接信息。可以使用ss -t state established命令来列出所有处于ESTABLISHED状态的TCP连接。
  3. 使用tcpdump命令:tcpdump是一个强大的网络抓包工具,可以捕获和分析网络数据包。可以使用tcpdump命令来捕获TCP连接的数据包,并进行进一步的分析。例如,使用tcpdump -i eth0 tcp port 80可以捕获通过端口80的TCP连接的数据包。
  4. 使用Wireshark:Wireshark是一个流行的网络协议分析工具,可以用于捕获和分析网络数据包。它提供了图形化界面和丰富的过滤和分析功能,可以帮助你更详细地分析TCP连接。
1
2
3
4
5
# 监测请求的命令
tcpdump -i eth0 tcp port 80
sudo tcpdump -i eth0 -nn -vv -s0 -l -A tcp
netstat -an | grep ESTABLISHED
ss -t state established

查看规则列表:

sudo iptables -L

启动脚本

1
2
3
4
5
[root@iZ2zeb7ybli3zzdll6airpZ files]# pwd
/home/files
[root@iZ2zeb7ybli3zzdll6airpZ files]#
[root@iZ2zeb7ybli3zzdll6airpZ files]# nohup sh capture.sh &
[root@iZ2zeb7ybli3zzdll6airpZ ~]# tail -1000f /var/log/auth.log

使用 ps 命令查看进程列表:

ps aux | grep your_script_name.sh

3. fail2ban安装配置

Fail2ban安装以及配置 - __都非拉得 - 博客园 (cnblogs.com)

fail2ban封IP之Http_梵境心生的技术博客_51CTO博客

自动IP拦截工具fail2ban使用教程 | 洞香春 (wdd.js.org)

CentOS安装Fail2ban之小白攻略 (haoqi.org)

Fail2Ban安全配置与应用 - 高度可定制化/支持多种服务-腾讯云开发者社区-腾讯云 (tencent.com)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# 服务启动命令
systemctl daemon-reload
systemctl start fail2ban.service
systemctl status fail2ban.service
systemctl restart fail2ban.service
systemctl stop fail2ban.service
sudo systemctl restart dropbear
#开机启动
systemctl enable fail2ban

# fail2ban运行状态
[root@iZ2zeb7ybli3zzdll6airpZ fail2ban]# fail2ban-client status
Status
|- Number of jail: 7
`- Jail list: nginx-cc, ssh, ssh-iptables, sshd, sshd-ddos, sshd-ddos-tcp, sshd-ddos-udp
[root@iZ2zeb7ybli3zzdll6airpZ fail2ban]#
[root@iZ2zeb7ybli3zzdll6airpZ fail2ban]# fail2ban-client status banit
[root@iZ2zeb7ybli3zzdll6airpZ fail2ban]# pwd
/etc/fail2ban
[root@iZ2zeb7ybli3zzdll6airpZ fail2ban]# fail2ban-client reload


#查看被ban IP,其中sshd为名称,比如上面的[wordpress]
fail2ban-client status sshd

fail2ban-client status nginx-cc

fail2ban-client status wordpress-cc
#删除被ban IP
fail2ban-client set sshd delignoreip 192.168.111.111
#查看日志
tail /var/log/fail2ban.log

测试配置:
fail2ban-regex /var/log/nginx/access.log /etc/fail2ban/filter.d/nginx-cc.conf
sudo /usr/local/bin/fail2ban-regex /var/log/tcpdump.log /etc/fail2ban/filter.d/tcp-rst.conf



# 查看报错信息
journalctl -xe

# fail2ban配置文件
cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
vim /etc/fail2ban/jail.local



#查看日志
tail /var/log/fail2ban.log


#停止开机自启动fail2ban
systemctl disable fail2ban.service

#查看开机启动项
systemctl list-unit-files | grep enable

#查看fail2ban当前版本
fail2ban-server -V

#验证fail2ban成功运行
fail2ban-client ping
正常运行会显示:Server replied: pong


#释放被特定监狱屏蔽的IP(注意规则名称与你的保持一致)
fail2ban-client set sshd unbanip 192.168.111.111

fail2ban-client set nginx-cc unbanip 192.168.111.111

fail2ban-client set wordpress-cc unbanip 192.168.111.111

#在SSH监护服务忽略IP列表(白名单)中添加IP
fail2ban-client set sshd addignoreip 192.168.111.111

#在SSH监护服务忽略IP列表(白名单)中删除IP
fail2ban-client set sshd delignoreip 192.168.111.111


# 示例
fail2ban-client set banit unbanip 117.133.51.5
fail2ban-client set banit addignoreip 117.133.51.5

fail2ban-client set nginx-cc unbanip 111.196.243.13
fail2ban-client set nginx-cc addignoreip 111.196.243.13

1) 配置文件

vim /etc/fail2ban/jail.local

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
[DEFAULT]
# 忽略的IP列表,不受设置限制
ignoreip = 127.0.0.1/8

# 被封IP禁止访问的时间,单位是秒
bantime = 86400

# 检测时间,在此时间内超过规定的次数会激活fail2ban,单位是秒
findtime = 300

# 允许错误登录的最大次数
maxretry = 3

# 日志修改检测机制(gamin、polling和auto这三种)
backend = auto

# 定义日志级别,默认
loglevel = 3

# 定义 fail2ban 日志文件
logtarget = /var/log/fail2ban.log

# sock 文件存放位置,默认
socket = /var/run/fail2ban/fail2ban.sock

# pid 文件存放位置,默认
pidfile = /var/run/fail2ban/fail2ban.pid

# 邮件通知参数
sendmail-whois[name=SSH, dest=you@example.com, sender=fail2ban@example.com, sendername="Fail2Ban"]
# 收件人地址 ## 发件人地址

[sshd]
# 激活
enabled = true
# 规律规则名,对应filter.d目录下的sshd.conf
filter = sshd
banaction = firewallcmd-new
# 检测的系统的登陆日志文件。这里要写sshd服务日志文件
logpath = /var/log/secure
# 禁止用户IP访问主机1小时
bantime = 3600
# 在5分钟内内出现规定次数就开始工作
findtime = 300
# 3次密码验证失败
maxretry = 3
port = 22

[sshd-ddos]
enabled = true

2) fail2ban nginx拦截配置

参考:使用 Fail2Ban 保护 Nginx、WordPress 简单又高效 - 知乎 (zhihu.com)

网站建设 - 明月登楼的博客 (imydl.com)

1
2
3
4
5
6
# vim nginx-http-auth.conf
# 这个规则是存在的,我们在规则中加一行配置,来过滤除了账号密码错误外,空白账号或者密码的错误:添加的是加粗的那一行。
[Definition]
failregex = ^ \[error\] \d+#\d+: \*\d+ user "\S+":? (password mismatch|was not found in ".*"), client: , server: \S+, request: "\S+ \S+ HTTP/\d+\.\d+", host: "\S+"\s*$
^ \[error\] \d+#\d+: \*\d+ no user/password was provided for basic authentication, client: , server: \S+, request: "\S+ \S+ HTTP/\d+\.\d+", host: "\S+"\s*$
ignoreregex =
1
2
#  cp apache-badbots.conf nginx-badbots.conf
# 过滤爬虫的规则是有现成的,所以我们只需要改个名就可以了;
1
2
3
4
# vim nginx-nohome.conf  这是过滤获取目录的:
[Definition]
failregex = ^ -.*GET .*/~.*
ignoreregex =
1
2
3
4
# vim nginx-noproxy.conf  这是过滤反代的:
[Definition]
failregex = ^ -.*GET http.*
ignoreregex =
1
2
3
4
# vim xmlrpc.conf 这是防止 WordPress 受到 xmlrpc.php 请求的 CC 攻击:
[Definition]
failregex = ^ .*POST .*xmlrpc\.php.*
ignoreregex =
1
2
3
4
# vim wp-login.conf 防范 WordPress 暴力破解登录请求
[Definition]
failregex = ^ -.* /wp-login.php.* HTTP/1\.."
ignoreregex =

4. 监测命令

1) sudo ngrep -q -d eth0 ‘’ port 80

1
2
3
4
5
6
7
8
9
10
[root@iZ2zeb7ybli3zzdll6airpZ ~]# sudo ngrep -q -d eth0 '' port 80
T 203.205.249.108:44955 -> 172.17.113.163:80 [A] #305
......

T 120.233.43.201:23525 -> 172.17.113.163:80 [A] #306
......

T 218.68.91.40:9830 -> 172.17.113.163:80 [A] #307
......
[root@iZ2zeb7ybli3zzdll6airpZ ~]#

写入文件:

1
sudo ngrep -q -d eth0 -W byline 'pattern' port 80 >> /var/log/auth.log

正则表达式:

1
#failregex = T <HOST>:\d+ -> <HOST>:80 \[A\]

2) tcpdump -i eth0 tcp port 80

1
2
3
4
5
6
7
8
9
[root@iZ2zeb7ybli3zzdll6airpZ ~]# tcpdump -i eth0 tcp port 80
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
13:35:43.140810 IP 122.192.132.180.19928 > iZ2zeb7ybli3zzdll6airpZ.http: Flags [.], ack 501558382, win 65535, length 0
13:35:43.150729 IP 222.189.172.50.10783 > iZ2zeb7ybli3zzdll6airpZ.http: Flags [.], ack 1323468332, win 65535, length 0
13:35:43.184075 IP 42.81.188.120.11358 > iZ2zeb7ybli3zzdll6airpZ.http: Flags [.], ack 2074920146, win 65535, length 0
13:35:43.203123 IP 43.152.156.102.54839 > iZ2zeb7ybli3zzdll6airpZ.http: Flags [.], ack 996434190, win 65535, length 0
13:35:43.212869 IP 43.152.156.108.41658 > iZ2zeb7ybli3zzdll6airpZ.http: Flags [.], ack 605313205, win 65535, length 0

写入文件:

(1) 使用tcpdump捕获HTTP流量并写入到文件中:

1
sudo tcpdump -i eth0 -w /tmp/http_traffic.pcap tcp port 80

这个命令将捕获来自eth0接口的所有TCP端口为80的流量,并将结果保存到名为http_traffic.pcap的文件中。

(2) 使用tcpdump读取捕获的文件并转换成文本格式:

1
sudo tcpdump -r /tmp/http_traffic.pcap -A > /var/log/auth.log

这个命令将读取之前保存的http_traffic.pcap文件,并使用 -A 选项将ASCII格式的数据输出到日志文件中。

请注意,这种方法仅适用于暂时性的捕获和记录HTTP流量。如果你需要持续监控HTTP流量并将结果记录到日志文件中,你可能需要考虑其他工具,如ngrep或者使用类似Wireshark的GUI工具。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@iZ2zeb7ybli3zzdll6airpZ files]# pwd
/home/files
[root@iZ2zeb7ybli3zzdll6airpZ files]#
[root@iZ2zeb7ybli3zzdll6airpZ files]# cat capture.sh
#!/bin/bash

# Run tcpdump to capture network traffic and write to stdout,
# then use tcpdump to read from stdin, parse it as human-readable format,
# and write to /var/log/auth.log
sudo tcpdump -i eth0 -w - tcp port 80 | sudo tcpdump -r - -A > /var/log/auth.log &

[root@iZ2zeb7ybli3zzdll6airpZ files]#
[root@iZ2zeb7ybli3zzdll6airpZ files]# ./capture.sh &
[root@iZ2zeb7ybli3zzdll6airpZ files]# nohup sh capture.sh &
[root@iZ2zeb7ybli3zzdll6airpZ ~]# tail -1000f /var/log/auth.log

正则表达式匹配:

1
#failregex = ^\S+ IP <HOST>\.\d+ > \S+\.http: Flags

5. linux清空文件内容的三种方法

https://www.cnblogs.com/zqifa/p/linux-vim-4.html

linux系统中清空文件内容的三种方法

1.使用vi/vim命令打开文件后,输入”%d”清空,后保存即可。但当文件内容较大时,处理较慢,命令如下:
vim file_name
:%d
:wq

2.使用cat命令情况,命令如下:
cat /dev/null > file_name

3.使用echo命令清空,此时会在文件中写入一个空行“\n”,命令如下:
echo “”>file_name

echo “”>/var/log/auth.log

推荐使用cat命令。

6. vim粘贴格式乱解决办法

https://blog.csdn.net/Liu_jalon/article/details/88657513

  1. paste 模式

运行如下命令,进入 paste 模式:

:set paste
进入 paste 模式后,按 i 键进入插入模式,然后再粘帖,文本格式不会错乱了。但粘帖后还需要按 进入普通模式并执行如下命令结束 paste 模式:

:set nopaste
显然,这样非常麻烦。下面我们进行改进。

  1. 快捷键一

我们可以利用设置快捷键来简化上面的两个命令。在 ~/.vimrc 中加入如下两行:

map :set paste
map :set nopaste
这样,在普通模式下按 F10 (你也可以用自己喜欢的按键)就会进入 paste 模式,按 i 进入插入模式后粘帖,然后按 回到普通模式,再按 F11 结束 paste 模式。

7. 记录所有用户的登录和操作日志

Linux操作系统加固-阿里云帮助中心 (aliyun.com)

  1. 运行 [root@xxx /]# vim /etc/profile打开配置文件。

  2. 在配置文件中输入以下内容:

  3. 运行 [root@xxx /]# source /etc/profile 加载配置生效。

    注意: /var/log/history 是记录日志的存放位置,可以自定义。

通过上述步骤,可以在 /var/log/history 目录下以每个用户为名新建一个文件夹,每次用户退出后都会产生以用户名、登录IP、时间的日志文件,包含此用户本次的所有操作(root用户除外)。

同时,建议您使用OSS服务收集存储日志。

8. CentOS 镜像 - 阿里镜像

centos镜像_centos下载地址_centos安装教程-阿里巴巴开源镜像站 (aliyun.com)

1
2
# 替换镜像源 有效! 2024年3月9日
baseurl=http://mirrors.aliyun.com/epel-archive/8/Everything/$basearch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@iZ2zeb7ybli3zzdll6airpZ yum.repos.d]# pwd
/etc/yum.repos.d
[root@iZ2zeb7ybli3zzdll6airpZ yum.repos.d]# ls
CentOS-Base.repo epel-archive-8.repo epel.repo mysql-community nginx.repo
Centos-vault-8.5.2111.repo epel-modular.repo epel-testing-modular.repo mysql-community.repo
epel-7.repo epel-playground.repo epel-testing.repo mysql-community-source.repo
[root@iZ2zeb7ybli3zzdll6airpZ yum.repos.d]#
[root@iZ2zeb7ybli3zzdll6airpZ yum.repos.d]# vim nginx.repo
[nginx]
name=nginx repo
#baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
baseurl=http://mirrors.aliyun.com/epel-archive/8/Everything/$basearch
gpgcheck=0
enabled=1

参考文章:https://blog.csdn.net/wenmingma/article/details/126706532

https://blog.csdn.net/inrgihc/article/details/105960463

9. Centos8防火墙设置

Centos8防火墙设置 - john_yong - 博客园 (cnblogs.com)

1) centos中firewalld与iptables

centos7以前的版本默认使用iptables服务进行管理防火墙规则。centos7以及其以上版本默认使用firewalld服务管理防火墙。所以在centos8中,就使用其默认的firewalld配置防火墙。

firewalld和iptables的官方说明可以参照https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/7/html/security_guide/sec-using_firewalls#sec-Comparison_of_Firewalld_to_system-config-firewall_and_iptables

2) firewalld相关命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#进程与状态相关
systemctl start firewalld.service #启动防火墙
systemctl stop firewalld.service #停止防火墙
systemctl status firewalld #查看防火墙状态
systemctl enable firewalld #设置防火墙随系统启动
systemctl disable firewalld #禁止防火墙随系统启动
firewall-cmd --state #查看防火墙状态
firewall-cmd --reload #更新防火墙规则
firewall-cmd --list-ports #查看所有打开的端口
firewall-cmd --list-services #查看所有允许的服务
firewall-cmd --get-services #获取所有支持的服务

#区域相关
firewall-cmd --list-all-zones #查看所有区域信息
firewall-cmd --get-active-zones #查看活动区域信息
firewall-cmd --set-default-zone=public #设置public为默认区域
firewall-cmd --get-default-zone #查看默认区域信息


#接口相关
firewall-cmd --zone=public --add-interface=eth0 #将接口eth0加入区域public
firewall-cmd --zone=public --remove-interface=eth0 #从区域public中删除接口eth0
firewall-cmd --zone=default --change-interface=eth0 #修改接口eth0所属区域为default
firewall-cmd --get-zone-of-interface=eth0 #查看接口eth0所属区域

#端口控制
firewall-cmd --query-port=8080/tcp # 查询端口是否开放
firewall-cmd --add-port=8080/tcp --permanent #永久添加8080端口例外(全局)
firewall-cmd --remove-port=8800/tcp --permanent #永久删除8080端口例外(全局)
firewall-cmd --add-port=65001-65010/tcp --permanent #永久增加65001-65010例外(全局)
firewall-cmd --zone=public --add-port=8080/tcp --permanent #永久添加8080端口例外(区域public)
firewall-cmd --zone=public --remove-port=8080/tcp --permanent #永久删除8080端口例外(区域public)
firewall-cmd --zone=public --add-port=65001-65010/tcp --permanent #永久增加65001-65010例外(区域public)

3) iptables

Linux系统防火墙iptables-CSDN博客

Linux命令–iptables–使用/实例

Linux命令–iptables–使用/实例_linux iptable限制ip访问-CSDN博客

添加新的规则

  1. -A 在filter表的INPUT链末行添加拒绝icmp的规则
    [root@localhost1 ~]#iptables -t filter -A INPUT -p icmp -j REJECT

  2. -I 不指定行,是在指定链首行插入规则(允许tcp 22端口)
    [root@localhost1 ~]#iptables -t filter -I INPUT -p tcp –dport 22 -j ACCEPT

  3. -I 指定行,是在指定链的指定行上插入规则
    [root@localhost1 ~]#iptables -t filter -I INPUT 2 -p tcp –dport 22 -j ACCEPT

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//1.查看指定表的规则(不加链名显示所有链的所有规则)
[root@localhost1 ~]#iptables -t filter -L
//2.-nL 以数字形式显示
[root@localhost1 ~]#iptables -t filter -nL
//3.-nvL 以数字形式显示,并显示详细信息
[root@localhost1 ~]#iptables -t filter -nvL
//4. --line-numbers 显示规则序号(指定链名,就显示指定链的规则)
[root@localhost1 ~]#iptables -t filter -nvL INPUT --line-numbers

# 允许某个IP访问
iptables -I INPUT -s 111.196.241.132 -j ACCEPT

# 仅允许来自172.27.8.0/22的用户连接ssh服务
iptables -I INPUT -s 172.27.8.0/22 -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j REJECT

# 通过iptables配置防火墙立即生效。iptables防火墙配置在重启后就失效了,解决方法如下:
将配置写入文件
sudo iptables-save > /etc/iptables.rules
2.网卡启动和关闭时自动加载和保存配置
编辑/etc/network/interfaces文件,添加如下内容:
pre-up iptables-restore < /home/user/iptables.rules
post-down iptables-save > /home/user/iptables.rules

解封某个IP访问
iptables -D INPUT -s 192.168.0.232 -j DROP

查看当前IP规则表(带编号) 。
iptables -L -n --line-numbers

此命令会在第1列添加编号,此编号可以用于删除规则
iptables -D INPUT NUM
iptables -D f2b-banit 154

清空iptables的所有规则(默认规则除外)
iptables -F

在修改 iptables 规则后,可以使用以下命令立即生效:

  • 使用 service iptables save 命令来保存规则,然后使用 service iptables restart 重启 iptables 服务。

    1
    2
    service iptables save
    service iptables restart
  • 使用 /etc/init.d/iptables restart 命令重启 iptables 服务。

注意:使用这些命令时需要 root 权限。

另外,如果想永久保存 iptables 规则,可以在修改完成后使用 service iptables save 命令来保存规则,这样在下次重启机器时规则仍然生效。

1
2
3
4
5
iptables -L -n --line-numbers
iptables -D INPUT 2
iptables -I INPUT -s 111.196.243.97 -j ACCEPT
iptables -D f2b-banit 64
iptables -D f2b-banit 75

10. nvm管理工具

参考:node 和 npm 如何进行版本升级 - 掘金 (juejin.cn)

源码地址:https://github.com/coreybutler/nvm-windows/releases

window下安装并使用nvm(含卸载node、卸载nvm、全局安装npm)_window安装nvm-CSDN博客

nvm 是一个node的版本管理工具,可以在win系统下使用,类似的还有 gnvm 等。

1
2
3
4
5
6
7
8
9
10
nvm ls                ## 查看已安装的所有node版本
nvm install node ## 安装最新版本
nvm install version ## 安装指定版本
nvm use version ## 使用指定版本
nvm current ## 查看当前版本

作者:jimojianghu
链接:https://juejin.cn/post/7198626211031187516
来源:稀土掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

11. Python下载源

1
2
pip install opencv-python
pip install opencv-python -i https://mirrors.aliyun.com/pypi/simple/

其他常用源

参考:https://blog.csdn.net/fyc300/article/details/135459049

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
清华:
https://pypi.tuna.tsinghua.edu.cn/simple

阿里云:
http://mirrors.aliyun.com/pypi/simple/

中国科技大学
https://pypi.mirrors.ustc.edu.cn/simple/

华中理工大学:
http://pypi.hustunique.com/

山东理工大学:
http://pypi.sdutlinux.org/

豆瓣:
http://pypi.douban.com/simple/

12. Jupyter

参考:搭建人工智能开发环境 第02节_初识Jupyter环境_哔哩哔哩_bilibili

1
2
PS E:\pydemo\jupyter> pip install jupyter
PS E:\pydemo\jupyter> jupyter notebook

http://localhost:8888/tree

13. Elasticsearch

Linux环境下安装Elasticsearch,史上最详细的教程来啦~_linux elasticsearch-CSDN博客

官网下载地址: https://www.elastic.co/cn/downloads/elasticsearch

(1) 安装目录

1
2
3
4
5
[root@iZ2zeb7ybli3zzdll6airpZ elasticsearch-8.14.3]# pwd
/usr/local/elasticsearch-8.14.3
[root@iZ2zeb7ybli3zzdll6airpZ elasticsearch-8.14.3]# ls
bin config data jdk lib LICENSE.txt logs modules NOTICE.txt plugins README.asciidoc
[root@iZ2zeb7ybli3zzdll6airpZ elasticsearch-8.14.3]#

(2) 配置用户及端口

配置文件:

1
2
3
4
5
6
7
8
9
[root@iZ2zeb7ybli3zzdll6airpZ bin]# pwd
/usr/local/elasticsearch-8.14.3/bin
[root@iZ2zeb7ybli3zzdll6airpZ bin]# ls
elasticsearch elasticsearch-create-enrollment-token elasticsearch-geoip elasticsearch-reconfigure-node elasticsearch-setup-passwords elasticsearch-syskeygen
elasticsearch-certgen elasticsearch-croneval elasticsearch-keystore elasticsearch-reset-password elasticsearch-shard elasticsearch-users
elasticsearch-certutil elasticsearch-env elasticsearch-node elasticsearch-saml-metadata elasticsearch-sql-cli
elasticsearch-cli elasticsearch-env-from-file elasticsearch-plugin elasticsearch-service-tokens elasticsearch-sql-cli-8.14.3.jar
[root@iZ2zeb7ybli3zzdll6airpZ bin]#
[root@iZ2zeb7ybli3zzdll6airpZ bin]# vim ./elasticsearch

核心配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
#核心配置信息
[root@iZ2zeb7ybli3zzdll6airpZ config]# pwd
/usr/local/elasticsearch-8.14.3/config
[root@iZ2zeb7ybli3zzdll6airpZ config]# ls
certs elasticsearch.keystore elasticsearch.yml jvm.options.d role_mapping.yml users
certs.1720796820.tmp elasticsearch-plugins.example.yml jvm.options log4j2.properties roles.yml users_roles
[root@iZ2zeb7ybli3zzdll6airpZ config]#
[root@iZ2zeb7ybli3zzdll6airpZ config]# vim elasticsearch.yml

#http.port: 9200
http.port: 19300

1
2
3
4
5
6
7
8
9
10
11
12
13
14
创建用户
useradd es

创建所属组:
chown es:es -R /usr/local/elasticsearch-8.14.3

切换到es用户
su es

进入bin目录
cd /usr/local/elasticsearch-8.14.3/bin

启动elasticsearch
./elasticsearch

(3) 运行

1
2
3
4
[root@iZ2zeb7ybli3zzdll6airpZ bin]# pwd
/usr/local/elasticsearch-8.14.3/bin
[root@iZ2zeb7ybli3zzdll6airpZ bin]#
[root@iZ2zeb7ybli3zzdll6airpZ bin]# ./elasticsearch

访问:http://8.140.195.191:19300/

14. Kibana

Kibana | Kibana在Linux下的安装和启动、访问-腾讯云开发者社区-腾讯云 (tencent.com)

下载地址:https://www.elastic.co/cn/downloads/kibana

安装目录:/home/dev/kibana-8.14.3/

配置文件:
[root@iZ2zeb7ybli3zzdll6airpZ config]# pwd
/home/dev/kibana-8.14.3/config
[root@iZ2zeb7ybli3zzdll6airpZ config]#

[root@iZ2zeb7ybli3zzdll6airpZ config]# vim kibana.yml
[root@iZ2zeb7ybli3zzdll6airpZ config]#

端口:server.port: 5701

运行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@iZ2zeb7ybli3zzdll6airpZ bin]# pwd
/home/dev/kibana-8.14.3/bin
[root@iZ2zeb7ybli3zzdll6airpZ bin]# ls
kibana kibana-encryption-keys kibana-health-gateway kibana-keystore kibana-plugin kibana-setup kibana-verification-code
[root@iZ2zeb7ybli3zzdll6airpZ bin]#

# 方式一:
# 后台运行
nohup ./kibana &
或者
nohup ./kibana >/dev/null &

# 方式二:
./kibana

# - 查看进程号 jps 或者 ps -ef|grep kibana 或者 ps -ef|grep 5601
# - 杀死进程 kill -9 进程号
# ctrl + C

# 远程访问,开启端口号
/sbin/iptables -I INPUT -p tcp --dport 5601 -j ACCEPT

访问:http://8.140.195.191:5701

15. SSH配置

1
2
3
4
5
6
7
https://zhuanlan.zhihu.com/p/636254277?utm_id=0
# 编辑默认的 SSH 配置文件。
sudo vim /etc/ssh/sshd_config
# 将PasswordAuthentication参数设置为no如图所示。
PasswordAuthentication no
# 然后保存文件并重新加载 SSH 以应用更改。
sudo systemctl reload sshd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ssh-keygen -t rsa #-t表示加密方式
#之后会出现保存路径和短密码确认,一路回车即可
cd /root/.ssh
mv id_rsa.pub authorized_keys #重命名

## 修改/etc/ssh/sshd_config
#禁用密码验证
PasswordAuthentication no
#启用密钥验证
RSAAuthentication yes
PubkeyAuthentication yes

重启ssh服务
service sshd restart #centos系统
service ssh restart #ubuntu系统
/etc/init.d/ssh restart #debian系统

99. 文章收藏

springboot项目中,读取 resources 目录下的文件的几种方式 - 知乎 (zhihu.com)


Linux常用命令
https://chris-z-su.github.io/2024/01/11/linux/Linux常用命令/
作者
Chris
发布于
2024年1月11日
许可协议