Linux部署项目

1. 安装JDK

1.1 工作目录:/user/local/src

1.2 上传安装包

1.3 解压文件

命令1: 解压指令

tar -xvf jdk-8u51-linux-x64.tar.gz

命令2: 删除安装文件

 rm -f jdk-8u51-linux-x64.tar.gz

命令3: 修改文件名称

mv jdk1.8xxxxxx jdk1.8

1.4 JDK环境调试

命令1: vim /etc/profile

#设定jdk环境
export JAVA_HOME=/usr/local/src/jdk1.8
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib

命令2: 让JDK环境变量立即生效 source /etc/profile
或者重启Linux系统即可.

2. 安装MariaDB数据库

2.1 安装命令:

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

2.2 数据库启动

	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 

2.3 数据库初始化操作

命令:

mysql_secure_installation

设置密码,一路y

2.4 测试数据库用户名和密码是否有效

mysql -uroot -p

2.5 Mysql数据库远程访问配置

关于连接数据库的说明

说明:
1.如果需要远程连接数据库必须通过防火墙
2.如果远程连接数据库,数据库必须开启远程访问权限才可以,否则拒绝连接

2.5.1 配置防火墙策略

1 .检查防火墙状态

firewall-cmd --state

2 .手动关闭防火墙

1. systemctl stop firewalld.service
2. systemctl start firewalld.service

3 .防火墙配置

1.systemctl disable firewalld.service	#关闭开机自启
2.systemctl enable firewalld.service	#开启开机自启

4 . 配置防火墙后,重启防火墙

firewall-cmd --reload

2.5.2 配置Linux数据库访问权限

1 . 切换数据库mysql

1. show databases;
2. use mysql;

2 . 将user表中的host=“localhost"改为”%"

update user set host="%" where host="localhost";

3 . 刷新数据库权限

flush privileges;

2.6 导入数据库文件

1 . 可视化客户端导入
2 . 命令行导入

source /xxx/xxxx/xxxx/jt.sql;

3. tomcat集群部署

说明: 在/usr/local/src/ 创建tomcats的目录

3.0 端口占用问题

1 . 查询java进程命令: jps
2 . 关闭进程项
说明: 如果需要关闭Linux系统中的进程,则需要如下命令
语法: kill PID号
命令:

1. kill PID号 常规关闭进程
2. kil -15 PID号 较为严格的关闭. (当前的进程被其他进程引用 无法关闭)
3. kill -9 PID号 强制关闭进程

3.1 准备8091/8092服务器

说明:将后台服务器修改端口号后,install生成8091/8092,传入Linux系统

3.2 前台启动命令

命令:

java -jar 8091.jar & java -jar 8092.jar &

启动成功之后,回车跳入Linux系统.
弊端: 与当前的Session绑定. 如果Session关闭,则服务器全部停止.

3.3 后台启动项目

命令:

nohup java -jar 8091.jar => 8091.log &

说明: 通过上述命令可以实现后台启动,不会与session绑定.

3.3.1 浏览文件

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

3.3.2 脚本启动

说明: Linux系统中提供了shell脚本. 可以提供批处理的机制.
注意事项: 标识符 xxx.sh 注意表头
编辑脚本:

vim start.sh

脚本内容

#!/bin/sh
nohup java -jar 8091.jar => 8091.log &
nohup java -jar 8092.jar => 8092.log &

运行脚本:

 sh start.sh

3.4 编辑hosts文件

路径: C:\Windows\System32\drivers\etc
修改文件内容

127.0.0.1       localhost
::1             localhost
#图片服务器域名
#127.0.0.1       image.jt.com
#前端域名地址
#127.0.0.1       web.jt.com
#后端域名地址
#127.0.0.1       manage.jt.com

#Linux系统配置 只对本机测试有效
192.168.126.129       image.jt.com
192.168.126.129       web.jt.com
192.168.126.129       manage.jt.com

4. Nginx安装

软件安装

5. 前端项目发布

5.1 nginx配置文件说明

http {
	#每个服务都是一个server
    server {
    	#默认监听80端口
        listen       80;
        #监听域名信息
        server_name  localhost;
		#具体反向代理服务 / 默认写法
        location / {
        	#root 代理的是一个目录
            root   html;
            #默认访问页面
            index  index.html index.htm;
        }
	}
}

5.2 前端发布准备工作

5.2.1 修改前端main.js

设定axios的请求目录为远程linux的域名
axios.defaults.baseURL = 'http://manage.jt.com/'

5.2.2 修改AddItem.vue文件 指向远程服务器

访问远程服务器
uploadUrl: "http://manage.jt.com/file/upload"

5.3 前端项目打包上传

1 . 项目打包,生成dist文件目录
2. 将前端打包好的目录dist 上传到指定的位置 /usr/local/nginx 目录下

6. 配置nginx配置文件 nginx.conf

6.1 配置前端反向代理

需求: 通过http://web.jt.com:80 访问前端的静态资源文件.
修改nginx配置文件:

#配置前端服务器
	server {
		listen 80;
		server_name web.jt.com;

		location / {
			root dist;
			index index.html;
		}
	}

6.2 配置后端tomcat集群

说明: 前端项目 web.jt.com 向后端服务器 manage.jt.com 发送请求.
问题: 后端服务器有8091/8092都可以为用户提供服务.
难点: 通过域名负载均衡一个服务器 为用户提供数据支持.

配置tomcat集群

#一次请求,访问一个服务器 集群的配置 负载均衡机制
	# upstream 集群的关键字.
	# tomcats 是集群的名称 可以任意 xxxx
	# server  每个服务的地址
	# 默认采用轮询的策略,依次访问服务器.
	upstream tomcats {
		server   192.168.126.129:8091;
		server   192.168.126.129:8092;
	}

	
	#配置后端服务器 8091/8092
	#后端域名  manage.jt.com
	server {
		listen 80;
		server_name manage.jt.com;

		location / {
			#proxy_pass 反向代理服务器发起是一个http请求
			proxy_pass  http://tomcats;
		}
	}

6.3 配置图片上传的反向代理

说明: 用户请求网址 http://image.jt.com 要求代理到 /usr/local/src/images

    #配置图片反向代理  image.jt.com 
	server {
		listen 80;
		server_name image.jt.com;
		location / {
			root /usr/local/src/images;
		} 
	}

6.4 nginx完整配置文件


#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
    server {
    	#默认监听80端口
        listen       80;
        #监听域名信息
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
		#具体反向代理服务 / 默认写法
        location / {
        	#root 代理的是一个目录
            root   html;
            #默认访问页面
            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 Apache's document root
        # concurs with nginx's 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;
    #    }
    #}

	#配置前端服务器
	server {
		listen 80;
		server_name web.jt.com;

		location / {
			root dist;
			index index.html;
		}
	}

	#一次请求,访问一个服务器 集群的配置 负载均衡机制
	# upstream 集群的关键字.
	# tomcats 是集群的名称 可以任意 xxxx
	# server  每个服务的地址
	# 默认采用轮询的策略,依次访问服务器.
	upstream tomcats {
		server   192.168.126.129:8091;
		server   192.168.126.129:8092;
	}

	
	#配置后端服务器 8091/8092
	#后端域名  manage.jt.com
	server {
		listen 80;
		server_name manage.jt.com;

		location / {
			#proxy_pass 反向代理服务器发起是一个http请求
			proxy_pass  http://tomcats;
		}
	}

	#配置图片反向代理  image.jt.com 
	server {
		listen 80;
		server_name image.jt.com;
		location / {
			root /usr/local/src/images;
		} 
	}
	
}

6.5 修改成功之后,上传nginx.conf文件,之后重启nginx服务器

路径: nginx/sbin

命令:

./nginx -s reload

7. 项目发布完成正常访问

浏览器访问网址: http:// web.jt.com

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值