Java - stage03 - Linux -项目部署

1. 网络配置

service network restart 命令冲突解决方法:

service NetworkManager stop
chkconfig NetworkManager off
service network restart

2. 基本命令

  1. 创建多级目录
    mkdir -p a/b/c

  2. 安装mariadb

[root@localhost src]# yum install mariadb-server 安装mariadb数据库
[root@localhost src]# yum clean all 清空已安装文件 如果下载失败之后执行的.

  1. 数据库命令
  1. 启动命令 [root@localhost src]# systemctl start mariadb
  2. 重启命令 [root@localhost src]# systemctl restart mariadb
  3. 关闭命令 [root@localhost src]# systemctl stop mariadb
  4. 设定开机自起 [root@localhost src]# systemctl enable mariadb
  5. 关闭开机自起 [root@localhost src]# systemctl disable mariadb
  1. 数据库初始化
    mysql_secure_installation

  2. 开放数据库权限
    use mysql;
    update user set host=“%” where host=“localhost”;
    flush privileges;

3. 防火墙

  1. 关闭防火墙
    查看防火墙状态
    firewall-cmd --state
    在这里插入图片描述
  2. 禁用启用防火墙

systemctl disable firewalld.service
systemctl enable firewalld.service

  1. 关闭开启防火墙

systemctl stop firewalld.service
systemctl start firewalld.service

  1. 手动开放防火墙端口
    1). 检查防火墙开放的端口

firewall-cmd --list-ports

2).检查端口是否开放

firewall-cmd --query-port 80/tcp
3). 开启防火墙

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

4).移除端口

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

5).关于防火墙操作的解释
–zone #作用域

–add-port=80/tcp #添加端口,格式为:端口/通讯协议

–remove-port=80/tcp #移除端口,格式为:端口/通讯协议

–permanent #永久生效,没有此参数重启后失效

6).重启防火墙

firewall-cmd --reload

4. 部署后端

  1. 后端项目打包
    在这里插入图片描述

  2. 运行项目
    基础命令: java -jar 8091.jar

  3. 后台运行

nohup java -jar 8091.jar => 8091.log &
java -jar jt-8091.jar 2>&1 >/dev/null

  1. 查看java 进程
    jps
  2. 关闭进程
    kill -15 PID号
    kill -9 PID号

日志查看

cat 输出文件所有的内容
more 输出文档所有的内容,分页输出,空格浏览下一屏,q退出
less 用法和more相同,只是通过PgUp、PgDo键来控制
tail 用于显示文件后几号,使用频繁
tail -10 nginx.conf 查看nginx.conf的最后10行
tail –f nginx.conf 动态查看日志,方便查看日志新增的信息
ctrl+c 结束查看

5. Linux 安装 Nginx

官网地址
http://nginx.org/en/download.html
软件下载地址
http://nginx.org/download/nginx-1.21.3.tar.gz

命令
1. 启动nginx start nginx
2. 重启nginx nginx -s reload
3. 关闭nginx nginx -s stop

5.1 service 支持 nginx

编辑 /etc/init.d/nginx
chmod 755 /etc/init.d/nginx

#!/bin/bash
#Startup script for the nginx Web Server
#chkconfig: 2345 85 15
nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done."
;;
stop)
echo -n "Stopping Nginx"
pkill nginx
echo " done."
;;
test)
$nginx -t -c $conf
echo "Success."
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done."
;;
restart)
$nginx -s reload
echo "reload done."
;;
*)
echo "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac

5.2 systemctl 支持 nginx

编辑 /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf 
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

5.3 编辑nginx配置文件

vim /usr/local/nginx/conf/nginx.conf

#配置图片代理 image.jt.com
server {
	listen 80;
	server_name image.jt.com;
	location / {
		root /opt/web/images;
	}
}

#配置前端代理 www.jt.com
server {
	listen 80;
	server_name www.jt.com;
	location / {
		root  /opt/web/jt;
		index index.html;
	}
}

#配置后台服务器集群
upstream tomcats{
	server 192.168.70.129:8091;
	server 192.168.70.129:8092;
	server 192.168.70.129:8093;
}

#配置后端代理 manage.jt.com
server {
	listen 80;
	server_name manage.jt.com;

	location / {
		proxy_pass http://tomcats;
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值