樟木头镇做网站,网页设计兼职平台,新时代文明实践站网址,天津市城乡建设网部署SpringBoot项目
创建SpringBoot项目
先确保有一个可以运行的springboot项目#xff0c;这里就记录创建项目的流程了#xff0c;可以自行百度。
命令行启动
2.1、在linux中#xff0c;我是在data目录下新创建的一个project目录#xff08;此目录创建位置不限制…部署SpringBoot项目
创建SpringBoot项目
先确保有一个可以运行的springboot项目这里就记录创建项目的流程了可以自行百度。
命令行启动
2.1、在linux中我是在data目录下新创建的一个project目录此目录创建位置不限制根据自己的来定
mkdir project -- 创建目录命令2.2、进入project目录下,将springBoot项目的jar包上传进来
2.3、创建 nohup.out 日志文件,用于输出项目启动的日志输出
touch nohup.out -- 创建文件2.4、运行jar 文件
nohup java -jar xxx.jar -- 运行jar命令
nohup java -jar xxx.jar --server.port8080 -- 指定端口号启动
nohup java -jar xxx.jar --spring.profiles.activeprod -- 指定配置文件启动2.5、查看nohup.out文件
tail -f nohup.out脚本文件启动
3.1、创建 server.sh 脚本文件,并赋予所有者执行权限
touch server.sh -- 创建脚本文件
chmod ux server.sh -- 赋予所有者执行权限3.2、编辑 server.sh 内容
#!/bin/bash
#这里可替换为你自己的执行程序其他代码无需更改
APP_NAMEnav-0.0.1-SNAPSHOT.jar
DEPLOY_DIRpwd
#使用说明用来提示输入参 数
usage() {echo Usage: sh 脚本名.sh [start|stop|restart|status]exit 1
}#检查程序是否在运行
is_exist(){pidps -ef|grep $APP_NAME|grep -v grep|awk {print $2} #如果不存在返回1存在返回0 if [ -z ${pid} ]; thenreturn 1elsereturn 0fi
}#启动方法
start(){is_existif [ $? -eq 0 ]; thenecho ${APP_NAME} is already running. pid${pid} .elsenohup java -jar $DEPLOY_DIR/$APP_NAME --spring.profiles.activeprod $DEPLOY_DIR/nohup.out 21 echo ${APP_NAME} start successfi
}#停止方法
stop(){is_existif [ $? -eq 0 ]; thenkill -9 $pidelseecho ${APP_NAME} is not runningfi
}#输出运行状态
status(){is_existif [ $? -eq 0 ]; thenecho ${APP_NAME} is running. Pid is ${pid}elseecho ${APP_NAME} is NOT running.fi
}#重启
restart(){stopstart
}#根据输入参数选择执行对应方法不输入则执行使用说明
case $1 instart)start;;stop)stop;;status)status;;restart)restart;;*)usage;;
esac3.3、操作命令
./server.sh start -- 启动项目
./server.sh stop -- 停止项目
./server.sh status -- 查看项目运行状态
./server.sh restart -- 重启项目可能出现的问题
如果使用脚本启动报以下错误是因为对*.sh文件的读、写、运行权限不足
[rootCaptian blog]# ./server.sh start
-bash: ./server.sh: Permission denied则可以使用以下命令赋权限。
[rootCaptian blog]# chmod 777 ./*.sh部署Vue项目
初始工作
1、先确保vue项目可以在本地正常的运行
2、在linux中新建网站文件夹home
我们放到home文件中
/home/www/dist此时我们需要在服务器上新建www文件夹
cd /home
mkdir www[rootCaptian /]# cd home
[rootCaptian home]# ll
total 0
[rootCaptian home]# mkdir www
[rootCaptian home]# ll
total 4
drwxr-xr-x 2 root root 4096 Aug 13 14:04 www
[rootCaptian home]# 我们没有新建dist文件夹因为我们待会儿vue项目打包就会生成dist文件夹。
打包部署vue项目
1、打包网站
使用vue打包命令,生成dist文件夹
npm run build如果这个报错的话使用下面的
npm run build:prod你可以在你的项目中看到package.json文件中有设置。
2、上传到服务器
使用ftp工具将dist文件夹上传至/home/www目录下
3、修改nginx配置
进入到nginx文件中
[rootCaptian nginx]# cd conf
[rootCaptian conf]# ll
total 68
-rw-r--r-- 1 root root 1077 Aug 12 17:23 fastcgi.conf
-rw-r--r-- 1 root root 1077 Aug 12 17:23 fastcgi.conf.default
-rw-r--r-- 1 root root 1007 Aug 12 17:23 fastcgi_params
-rw-r--r-- 1 root root 1007 Aug 12 17:23 fastcgi_params.default
-rw-r--r-- 1 root root 2837 Aug 12 17:23 koi-utf
-rw-r--r-- 1 root root 2223 Aug 12 17:23 koi-win
-rw-r--r-- 1 root root 5349 Aug 12 17:23 mime.types
-rw-r--r-- 1 root root 5349 Aug 12 17:23 mime.types.default
-rw-r--r-- 1 root root 2656 Aug 12 17:23 nginx.conf
-rw-r--r-- 1 root root 2656 Aug 12 17:23 nginx.conf.default
-rw-r--r-- 1 root root 636 Aug 12 17:23 scgi_params
-rw-r--r-- 1 root root 636 Aug 12 17:23 scgi_params.default
-rw-r--r-- 1 root root 664 Aug 12 17:23 uwsgi_params
-rw-r--r-- 1 root root 664 Aug 12 17:23 uwsgi_params.default
-rw-r--r-- 1 root root 3610 Aug 12 17:23 win-utf
[rootCaptian conf]# vim nginx.conf我们打开nginx.conf文件修改以下配置
1、修改端口为了防止和其他的端口有冲突我们将80端口改为9090端口自定义。
2、修改root里dist的路径。
#user nobody;
worker_processes 1;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024;
}http {include mime.types;default_type application/octet-stream;#log_format main $remote_addr - $remote_user [$time_local] $request # $status $body_bytes_sent $http_referer # $http_user_agent $http_x_forwarded_for;#access_log logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {listen 9090;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root /home/www/dist; # 路径改成自己的dist路径index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apaches document root# concurs with nginxs one##location ~ /\.ht {# deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#}
}改完这些之后我们重启一下nginx
systemctl restart nginx配置防火墙
由于我们把端口改了所以现在需要我们把加入的端口加入到防火墙中。
添加端口
firewall-cmd --zonepublic --add-port9090/tcp --permanent然后重启防火墙
systemctl restart firewalld.service我姑且举灰黑的手装作喝干一杯酒 我将在不知道时候的时候独自远行。 ——鲁迅