springboot 以jar包形式在linux后台 运行命令,upload的controller和上传目录软连接

nohup java -jar xxxxx.jar >temp.txt &
nohup java -jar xxxxx.jar >temp.log 2>&1 &

第一个一直启动不成功,我用第二种启动.,我实际操作,第一种第二种都可以。第二个意思是将错误输出合并到标准输出,写入到temp.log 文件。

解释下 >temp.txt

command >out.file

command >out.file是将command的输出重定向到out.file文件,即输出内容不打印到屏幕上,而是输出到out.file文件中。

可通过jobs命令查看后台运行任务

jobs

那么就会列出所有后台执行的作业,并且每个作业前面都有个编号。
如果想将某个作业调回前台控制,只需要 fg + 编号即可。

fg 23

查看某端口占用的线程的pid

netstat -nlp |grep :9181
 
如果忘了进程号,可以通过如下命令来查看当前运行的jar包程序进程号
ps -ef|grep xxx.jar
或者 ps -aux | grep java
 
//关闭进程
kill -s 9 24204
24204代表上一步查出的进程ID
 

代号解释

/dev/null 代表空设备文件
> 代表重定向到哪里,例如:echo "123" > /home/123.txt
1 表示stdout标准输出,系统默认值是1,所以">/dev/null"等同于"1>/dev/null"
2 表示stderr标准错误
& 表示等同于的意思,2>&1,表示2的输出重定向等同于1

yiwiki的启动文件

#!/bin/sh
#chkconfig: 2345 80 90
#description: start yiwiki springboot project
time1=$(date "+%Y%m%d-%H%M%S")
nohup java -jar /root/www/8080/zhouyi3-0.0.1-SNAPSHOT.jar  1>/dev/null  2>/root/logs/zhouyi3-$time1-8080.log &
nohup java -jar /root/www/8090/zhouyi3-0.0.1-SNAPSHOT.jar --server.port=8090   1>/dev/null   2>/root/logs/zhouyi3-$time1-8090.log &
~

这段代码的意思:将标准输出,到空文件;将错误输出,到日志文件。1代表标准输出,2代表错误输出。

文件上传

在/root/www/下建立tempImag文件夹,然后在/root/www/8080/,和/root/www/8090/下分别建立软链接

ln -s /root/www/tempImag tempImag

修改nginx的上传大小限制


vim /usr/nginx/conf/nginx.conf

server {
        listen       80;
        server_name  localhost;
    client_max_body_size 10M;      //这段代码需要加到80 和 443 端口
    
         location /web {
            alias   D:/web;
            index main.html;            
        }

 在springboot上,修改upload的controller文件,集成的ck4.8

@RequestMapping("/imageUpload")
    public String imageUpload(@RequestParam("upload") MultipartFile file,
                            @RequestParam("CKEditorFuncNum") String CKEditorFuncNum,
                            HttpServletResponse response,
                            HttpServletRequest request) throws IOException {
        System.out.println("有文件想要上传");
        PrintWriter out = response.getWriter();
        String name = null;
        name = new String(file.getOriginalFilename().getBytes("iso-8859-1"), "UTF-8");
        String uploadContentType = file.getContentType();
        //处理文件后缀
        String expandedName = "";
        if (uploadContentType.equals("image/pjpeg")
                || uploadContentType.equals("image/jpeg")) {
            // IE6上传jpg图片的headimageContentType是image/pjpeg,而IE9以及火狐上传的jpg图片是image/jpeg
            expandedName = ".jpg";
        } else if (uploadContentType.equals("image/png")
                || uploadContentType.equals("image/x-png")) {
            // IE6上传的png图片的headimageContentType是"image/x-png"
            expandedName = ".png";
        } else if (uploadContentType.equals("image/gif")) {
            expandedName = ".gif";
        } else if (uploadContentType.equals("image/bmp")) {
            expandedName = ".bmp";
        } else {
            //文件格式不符合,返回错误信息
            out.println("<script type="text/javascript">");
            out.println("window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum
                    + ",''," +  "'文件格式不正确(必须为.jpg/.gif/.bmp/.png文件)');");
            out.println("</script>");
            return null;
        }
         
        //文件命名并保存到服务器
        DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        name = df.format(new Date()) +expandedName;
        String DirectoryName =new ApplicationHome(getClass()).getDir()+"/tempImag";
        //   String DirectoryName =request.getContextPath()+"/tempImag";
        System.out.println(DirectoryName);
        try {
//            File file1 = new File(request.getServletContext().getRealPath("/tempImag"),name);
            File file1 = new File(DirectoryName,name);
            System.out.println(file1.getPath());
            file.transferTo(file1);
        } catch (IOException e) {
            // TODO: handle exception
            System.out.println("IO exception");
            e.printStackTrace();
        }catch (IllegalStateException e) {
            System.out.println("Illegal exception");
            e.printStackTrace();
        }
 
       // String fileURL =DirectoryName +"/"+ name;
        String fileURL ="/tempImag/"+ name;
 
        //  返回"图像"选项卡和图像在服务器的地址并显示图片
        out.println("<script type="text/javascript">");
        out.println("window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ",'" +fileURL+"','')");
        out.println("</script>");
        out.close();
        System.out.println("fileUrl is ========="+ fileURL);
        return null;
    }

然后,修改application.yml 的static resource的目录

web:
    resources:
      static-locations:
      - classpath:/META-INF/resources/
      - classpath:/resources/
      - classpath:/static/ 
      - classpath:/public/
      - file:/root/www/

web目录 /root/www/8080,/root/www/8090 开两个线程

upload 目录  /root/www 下 tempImag

 软连接 /root/www/8080/tempImag   

cd /root/www/8080

ln -s /root/www/tempImag templmag

相同,8090,也这样配置软连接。

原文地址:https://www.cnblogs.com/sdgtxuyong/p/14437192.html