常操:Java开发常用操作记录

开发常用操作

个人学习总结:
链接:【Java基础、springboot、springcloud、docker 等,学习目录

一、nginx 相关

Windows下Nginx命令

命令均在 nginx 安装目录下执行:
在这里插入图片描述

启动:start nginx 或者 ./nginx.exe
停止:./nginx.exe -s stop./nginx.exe -s quit
注:stop是快速停止nginx,可能并不保存相关信息;quit是完整有序的停止nginx,并保存相关信息。
重载:./nginx.exe -s reload

Linux下Nginx命令

1、查找 nginx/配置文件 位置的方法

进程号(master process)

[csp@localhost government-data]# ps -ef | grep nginx
nobody 23474 24577 0 1月07 ? 00:00:00 nginx: worker process
csp 23862 18375 0 09:57 pts/0 00:00:00 grep --color=auto nginx
csp 24577 1 0 1月07 ? 00:00:00 nginx: master process ./sbin/nginx -c ./conf/nginx.conf

find 搜索

[csp@localhost government-data]# find / -name nginx

2、测试配置文件

修改配置文件后,重载需做测试。

[csp@localhost nginx-server]# ./sbin/nginx -t
nginx: the configuration file /home/nginx/nginx-server/conf/nginx.conf syntax is ok
nginx: configuration file /home/nginx/nginx-server/conf/nginx.conf test is successful

3、启动、重启、停止

[csp@localhost nginx-server]# ./sbin/nginx -c ./conf/nginx.conf

重启一般是修改了配置文件,使用 nginx -t 测试后执行

[csp@localhost nginx-server]# ./sbin/nginx -s relaod

[csp@localhost nginx-server]# ./sbin/nginx -s stop

二、docker相关

启动、重启、关闭命令

启动 systemctl start docker
守护进程重启 sudo systemctl daemon-reload
重启docker服务 systemctl restart docker
重启docker服务 sudo service docker restart
关闭docker service docker stop
关闭docker systemctl stop docker

文件远程拷贝(nginx为例)

将容器名称为nginx01 的nginx配置文件夹拷贝到本机用户目录下的nginx_volum文件夹中

[root@ron ~]# docker cp nginx01:/etc/nginx/conf.d ~/nginx_volum/

安装容器(nginx为例)

注:先将需要挂载的数据卷,拷贝(或新建)到本地数据卷,再挂载。不然容器启动出错。

1、nginx配置文件路径:

[root@ron ~]# docker cp nginx01:/etc/nginx/conf.d ~/nginx_volum/conf/
[root@ron ~]# docker cp nginx01:/etc/nginx/nginx.conf ~/nginx_volum/conf/
nginx.conf 引用了 conf.d文件夹下的默认文件。

2、安装容器:

docker run -d --name nginx01 -p 9002:80 -v /root/nginx_volum/conf/conf.d/default.conf:/etc/nginx/conf.d/default.conf -v /root/nginx_volum/conf/nginx.conf:/etc/nginx/nginx.conf -v /root/nginx_volum/html/html:/usr/share/nginx/html nginx

三、Linux 防火墙

centos7 firewall

1、状态

[csp@localhost ~]# systemctl status firewalld

[csp@localhost ~]# firewall-cmd --state

2、开启、重启、关闭、firewalld.service服务

[csp@localhost ~]# service firewalld start

[csp@localhost ~]# service firewalld restart

[csp@localhost ~]# service firewalld stop

3、端口

# 已开放端口

[csp@localhost ~]# firewall-cmd --zone=public --list-ports

# 端口是否开放

[csp@localhost ~]# firewall-cmd --zone=public --query-port=9000/tcp

# 开放9000端口 permanent 设置为持久 不加机器重启后失效

firewall-cmd --zone=public --add-port=9000/tcp --permanent

# 批量开放

firewall-cmd --zone=public --add-port=9000-9005/tcp --permanent

# 移除端口

firewall-cmd --zone=public --remove-port=9000/tcp --permanent

# 重启防火墙(修改配置后要重启防火墙)

firewall-cmd --reload

4、IP限制

# 已经设置的规则
firewall-cmd --zone=public --list-rich-rules
# 限制IP为192.168.0.200的地址禁止访问80端口即禁止访问机器
firewall-cmd --permanent --add-rich-rule=“rule family=“ipv4” source address=“192.168.0.200” port protocol=“tcp” port=“80” reject”
# 解除刚才被限制的192.168.0.200
firewall-cmd --permanent --add-rich-rule=“rule family=“ipv4” source address=“192.168.0.200” port protocol=“tcp” port=“80” accept”
# 重新载入一下防火墙设置,使设置生效

四、GitBook

简单使用gitbook + nginx 建立在线文档。

1、gitbook 不需要登录。点击 do that later.
2、创建项目并编写。
3、使用 gitbook build 命令生成 _book 文件。
4、gitbook serve 命令可预览(localhost:4000,不需要预览省略此步)。在这里插入图片描述
5、将 _book 目录下的文件拷贝到 nginx html 目录下。
此处我使用的是 docker 数据卷映射到 nginx 中
在这里插入图片描述
6、访问nginx即可
在这里插入图片描述

五、通过 jstack 堆栈信息排查代码

案例代码:

	@GetMapping(value = "getValue")
    public int getValue(int num){
        while (num < 100){
            num = num * 100;
        }
        return num;
    }

问题:当num入参小于等于 0 时,while 会死循环。
访问接口:
http://ip:9009/review/test/getValue?num=0

排查代码步骤:
1、查到java程序的进程号(日志第一行或者通过端口号都可以查询)。
在这里插入图片描述在这里插入图片描述
2、java -Hp $pid 查看CPU中负载最大的线程。
在这里插入图片描述
找到最耗CPU的线程为24019
3、转换为十六进制(在线转换、python转换等)
Linux 默认带有 python2.7。使用 hex 可转换
在这里插入图片描述
4、通过 jstack 查看堆栈信息
jstack pid :所有的堆栈信息。此处通过线程ID nid 筛选。
-A 10 后 10行、-B 10 前10行、-C 10 前后各10行
在这里插入图片描述
prio : java 内线程优先级
os_prio : 操作系统级别的优先级
tid : Java内的线程ID
nid:操作系统级别的线程ID的16进制形式
线程状态为:RUNNABLE
出现问题的代码:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值