rookie-Linux

Basis

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 查询 java 进程
$ jps

$ ps -ef| grep java

# 销毁进程
$ kill [PID]

# 运行 jar
$ nohup java -jar xxx.jar &

# 查看日志
$ tail -n 1000 -f nohup.out

# 删除文件
$ rm -i [filename]
$ rm -rf [filename]

Advance

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
# 查看 class md5
$ md5sum xxx.class

# 非 FatJar 启动
$ java -cp ./lib/*:./classes/ com.rookie.Application

# 监听端口
$ netstat -ant| grep 3306
# 外部地址
Proto Recv-Q Send-Q Local Address Foreign Address State

# 查看 hosts
$ cat /etc/hosts

# 查看网络服务
$ telnet PATH [端口]

# 查找文件 当前目录及其子目录
$ find . -iname "hello.jar"

# 复制到 /tmp 便于运维删除
$ cp hello.jar /tmp

# 查看端口/进程相关信息
$ ss -tnlp| grep [端口/进程]
$ netstat -tnlp| grep [端口/进程]

# 生成文件夹
$ mkdir foldername

# 生成文件
$ touch filename

# 查看工作目录下的内容
$ ls -ltr

# 使用指定的JDK运行 jar
$ nohup [openjdk]/bin/java -jar xxx.jar &

# 远程服务器文件复制 将本机目录下的所有内容拷贝到远程目录下
$ scp -r /home/local_directory/* username@server_ip:/home/remote_directory/

# 添加执行权限
$ chmod +x startup.sh

# 文件权限设置为 -rwxr-xr--
$ chmod u=rwx,g=rx,o=r [文件名]

# 更改文件属主、文件属组
$ chown user:user install.log

# 查看全局环境变量
$ cat ~/.bash_profile

# 查看个人环境变量
$ cat /etc/profile

# 清空 nohup.out
$ echo "" > nohup.out

# 远程 Debug 启动
$ nohup java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5000 -jar xxx.jar &

# 启动 Eureka
$ nohup java -Dserver.port=[端口] -jar eureka.jar &
$ nohup java -Dserver.port=[端口] -Dds.ip=[双机互备另一节点IP地址] -jar eureka.jar &

Firewall

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
# 查看防火墙状态
$ systemctl status firewalld.service

# 开启防火墙
$ systemctl start firewalld.service

# 关闭防火墙
$ systemctl stop firewalld.service

# 禁用防火墙
$ systemctl disable firewalld.service

# 查看防火墙已开放端口列表
$ firewall-cmd --list-all
$ firewall-cmd --list-ports

# 防火墙添加端口
$ firewall-cmd --permanent --add-port=8080/tcp

# 刷新
$ firewall-cmd --reload

# 防火墙关闭端口
$ firewall-cmd --permanent --remove-port 8080/tcp
$ firewall-cmd --reload
$ firewall-cmd --list-all

Curl

curl 的用法指南

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
# 显示通信过程
$ curl -v www.ip.com
$ curl --trace output.txt www.ip.com
$ curl --trace-ascii output.txt www.ip.com

# GET请求
$ curl -v https://www.example.com

# POST请求 "-X POST"可以省略 Content-Type: application/x-www-form-urlencoded
$ curl -X POST -d "captcha=abcd&phone=13687654321" http://www.example.com/api

# POST请求 json传参 RequestBody
$ curl -v -H "Content-Type: application/json" -d '{"captcha": "abcd", "phone": "13687654321"}' http://www.example.com/login

$ curl -v -H "Content-Type: application/json" -d @login.json http://www.example.com/login

$ cat login.json
{
"captcha": "abcd",
"phone": "13687654321"
}

# GET请求 发送OAuth2身份验证 PathVariable
curl -v -H "Authorization: OAuth <ACCESS_TOKEN>" http://www.example.com/getInfo/{id}

# POST请求 发送OAuth2身份验证 Content-Type: application/x-www-form-urlencoded
curl -v -H "Authorization: OAuth <ACCESS_TOKEN>" -d "username=yee" -d "phone=13687654321" http://www.example.com/user/list

# POST请求 发送OAuth2身份验证 json传参 RequestBody
curl -v -H "Authorization: OAuth <ACCESS_TOKEN>" -H "Content-Type: application/json" -d '{"username": "yee", "phone": "13687654321", "password": "123456"}' http://www.example.com/user/add


rookie-Linux
https://arloyee.github.io/2023/09/07/rookie-Linux/
作者
YaYee
发布于
2023年9月7日
许可协议