文章目录
一、通过xshell在Linux上安装Java
1. 创建目录
cd /usr/
进入文件夹;再输入mkdir java
创建java文件夹(路径随你选择)
2. 下载JDK8
JDK8下载,通过xftp将其传至服务器的java文件夹下
3. 解压
tar -zxvf jdk-8u301-linux-x64.tar.gz(压缩包文件名)
4. 配置环境变量
继续执行vim /etc/profile
进行环境变量的配置
在vim编辑器里,点击i键开始编辑,在最下面添加:
export JAVA_HOME=/usr/java/jdk1.8.0_301
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
编辑完,按ESC键,可能需要按 :wq 保存
5. 查看是否安装成功
输入source /etc/profile
使环境变量生效,输入java -version
,查看是否安装成功
二、通过xshell在Linux上安装nginx
1. gcc 安装
安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境
yum install gcc-c++
2. PCRE pcre-devel安装
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。
nginx 的 http 模块使用 pcre 来解析正则表达式。
pcre-devel是使用 pcre 开发的一个二次开发库。
yum install -y pcre pcre-devel
3. zlib安装
zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip
yum install -y zlib zlib-devel
4. OpenSSL 安装
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
yum install -y openssl openssl-devel
5. 下载安装nginx
使用wget命令下载,确保系统已经安装了wget,如果没有安装,执行
yum install wget
下载nginx
wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
解压命令:
tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
6. 环境配置
配置ssl支持
./configure --prefix=/usr/local/nginx --with-http_ssl_module
编译安装
make && make install
坑
解决
-
输入命令 进入**/nginx-1.12.0/objs**中,编辑Makefile
cd objs vim Makefile
-
把里面一个单词 -Werror 删除掉 然后:wq保存退出
-
进入目录 **/nginx-1.12.0/src/os/unix/**中,编辑ngx_user.c
cd src/os/unix/ vim ngx_user.c
把这行注释掉,然后保存退出。
继续执行编译安装
cd /root/nginx-1.12.0
make && make install
查找安装路径:
whereis nginx
7. 启动nginx
cd /usr/local/nginx/sbin/ #进入bin目录
./nginx #启动
./nginx -s stop #此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程
./nginx -s quit #此方式停止步骤是待nginx进程处理任务完毕进行停止
./nginx -s reload #重启
8. 端口占用
用下面这个命令进行查看80端口被谁占用
netstat -tunlp | grep 80
关闭之后重开nginx再次访问
三、通过xshell在linux上安装mysql5.7
1. 下载安装
下载
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
安装
yum localinstall mysql57-community-release-el7-11.noarch.rpm
查看是否安装成功:
yum repolist enabled | grep "mysql.*-community.*"
2.设置服务
安装mysql
yum module disable mysql
yum install mysql-community-server
启动mysql:
systemctl start mysqld
关闭mysql:
systemctl stop mysqld
查看是否启动:
systemctl status mysqld
重启mysql:
systemctl restart mysqld
3. 设置开机自启
systemctl enable mysqld
4. 修改密码
查看默认密码:
grep 'temporary password' /var/log/mysqld.log
连接数据库:
mysql -u root -p
然后输入上面查询的默认密码
进入mysql之后,修改密码:
alter user 'root'@'localhost' identified by '新密码';
坑
如果密码太过简单,可能会弹下面的错误:
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
解决
在简单密码前面加字母。(想设置123456这种简单密码,需要修改MySQL密码设置规范,可自行百度)
5. 远程连接
远程连接设置:
首先确定阿里云上安全配置开启数据库端口
grant all privileges on *.* to root@'%'identified by '数据库密码';
四、通过xshell在linux上安装redis
1. 上传解压
通过xftp将redis安装包上传到linux;
解压
tar -zxvf redis-6.2.5.tar.gz
2. 编译
进入redis文件夹,执行make命令进行编译 (指定安装位置安装)
cd /root/redis-6.2.5
make install PREFIX=/usr/redis
3. 测试启动
进入bin目录下执行服务端启动
cd /usr/redis/bin
./redis-server
看下是否出现如下界面。
这样启动不能继续进行操作,所以我们应该配置后台启动。
按Ctrl+c退出。
4. 后台启动
先将配置文件复制到bin目录下
cp /root/redis-6.2.5/redis.conf /usr/redis/bin
然后编辑该配置文件
vim /usr/redis/bin/redis.conf
将daemonize no 改为daemonize yes
将bind 127.0.0.1 改为bind 0.0.0.0
重新进入bin文件夹下,执行
./redis-server redis.conf
即可后台启动redis。
查看redis启动状态:
ps aux|grep redis
强制关闭进程:
kill -9 5317(进程ID)
五、部署项目
1. 服务器安全组配置
确保端口都已打开
端口全部打开
2. 打包
前端:终端输入
npm run build
后端:clean、运行项目然后package(可能部署到服务器上出问题,需要重复多次打包尝试)
3. 上传
通过Xftp将打包好的dist和jar包上传到云服务器上。
4. 后台启动jar包
cd到jar包所在的路径
nohup java -jar jar包名字 &
5.nginx配置文件
- nginx.conf
需要修改的地方:
-
第44行(例):
root /srv/zhejiang_monitor/dist;
root后面填dist的路径
-
第95行:
添加 include vhost/*.conf;
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 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
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 /srv/zhejiang_monitor/dist;
# index index.html index.htm;
# }
#}
include vhost/*.conf;
# 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;
# }
#}
}
-
vhost/*.conf
没有vhost的话,需要先在nginx/conf下创建vhost
需要修改的地方
-
第四行:server_name 114.55.67.204;
server_name 后面填服务器ip
-
第五行:root /srv/zhejiang_monitor/dist;
root 后面填dist路径
-
第27行: proxy_pass http://127.0.0.1:8081/;
后面8081改为后端java的端口号
-
第35、36、39行
自己定义存放路径
server { listen 80; autoindex on; server_name 114.55.67.204; root /srv/zhejiang_monitor/dist; access_log /usr/local/nginx/logs/access.log combined; index index.html index.htm index.jsp index.php; #防止重定向页面刷新 路由失效 try_files $uri $uri/ /index.html; index index.jsp index.html index.htm; #error_page 404 /404.html; index index.html; if ( $query_string ~* ".*[\;'\<\>].*" ){ return 404; } location /api/oasis { proxy_pass https://218.108.146.92:10443/; add_header Access-Control-Allow-Origin '*'; } location /api { proxy_pass http://127.0.0.1:8081/; add_header Access-Control-Allow-Origin '*'; } location ~ .*\.(gif|jpg|jpeg|png)$ { expires 24h; root /srv/zhejiang_monitor/images/;#指定图片存放路径 access_log /srv/zhejiang_monitor/logs/images.log;#日志存放路径 proxy_store on; proxy_store_access user:rw group:rw all:rw; proxy_temp_path /srv/zhejiang_monitor/images/;#图片访问路径 proxy_redirect off; proxy_set_header Host 127.0.0.1; client_max_body_size 10m; client_body_buffer_size 1280k; proxy_connect_timeout 900; proxy_send_timeout 900; proxy_read_timeout 900; proxy_buffer_size 40k; proxy_buffers 40 320k; proxy_busy_buffers_size 640k; proxy_temp_file_write_size 640k; if ( !-e $request_filename) { proxy_pass http://127.0.0.1;#默认80端口 } } }
-
6. 启动nginx
cd /usr/local/nginx/sbin/ (cd到你的sbin目录下)
如果nginx没启动,启动命令:
./nginx
如果nginx已经启动,重启命令:
./nginx -s reload
部署完毕!
参考: Linux开发环境配置大全