一、阿里云
- 重设系统后:设置连接密码
- 建议选择centOS7.几,8.没有维护了
- [可视化finalShell](
www.hostbuf.com/t/988.html\)
- 防火墙:记得开对应端口
- 更改主机名:ssh 账号@ip地址
- 更改主机名:hostnamectl --static set-hostname lpz
- 清空:clear
- cd .. 、cd ./ 、ls、mkdir、pwd(当前目录)
二、安装dnf包管理工具
- yum install dnf
- dnf --version
三、安装mysql
- wget dev.mysql.com/get/mysql57…
- dnf install mysql-community-server
- 开启mysql-server后台服务
- yum install -y mariadb-server
- 报错(blog.csdn.net/weixin_3970…)
- systemctl start mysqld.service
- 查看服务状态
- systemctl status mysqld.service
- 随系统一起启动
- systemctl enable mysqld(必须,下面可以不用设置)
- 查看默认密码:grep "password" /var/log/mysqld.log
- 进入数据库:mysql -uroot -p 、exit(退出)
- 修改密码:
- set global validate_password_policy=0;
- set global validate_password_length=1;
- alter user 'root'@'localhost' identified by 'root';
- 配置mysql
- mysql_secure_installation:
- (a)为root用户设置密码 2. (b)删除匿名账号 3. (c)取消root用户远程登录 4. (d)删除test库和对test库的访问权限 5. (e)刷新授权表使修改生效
- 通过这几项的设置能够提高mysql库的安全。建议生产环境中mysql安装这完成后一定要运行一次mysql_secure_installation,详细步骤请参看下面的命令:
[root@server1 ~]# mysql_secure_installation\
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL\
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!\
In order to log into MySQL to secure it, we'll need the current\
password for the root user. If you've just installed MySQL, and\
you haven't set the root password yet, the password will be blank,\
so you should just press enter here.\
Enter current password for root (enter for none):<–初次运行直接回车\
OK, successfully used password, moving on…\
Setting the root password ensures that nobody can log into the MySQL\
root user without the proper authorisation.\
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车\
New password: <– 设置root用户的密码\
Re-enter new password: <– 再输入一次你设置的密码\
Password updated successfully!\
Reloading privilege tables..\
… Success!\
By default, a MySQL installation has an anonymous user, allowing anyone\
to log into MySQL without having to have a user account created for\
them. This is intended only for testing, and to make the installation\
go a bit smoother. You should remove them before moving into a\
production environment.\
Remove anonymous users? [Y/n] <– 是否删除匿名用户,生产环境建议删除,所以直接回车\
… Success!\
Normally, root should only be allowed to connect from 'localhost'. This\
ensures that someone cannot guess at the root password from the network.\
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止\
… Success!\
By default, MySQL comes with a database named 'test' that anyone can\
access. This is also intended only for testing, and should be removed\
before moving into a production environment.\
Remove test database and access to it? [Y/n] <– 是否删除test数据库,直接回车\
- Dropping test database…\
… Success!\
- Removing privileges on test database…\
… Success!\
Reloading the privilege tables will ensure that all changes made so far\
will take effect immediately.\
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,直接回车\
… Success!\
Cleaning up…\
All done! If you've completed all of the above steps, your MySQL\
installation should now be secure.\
Thanks for using MySQL!\
[root@server1 ~]#
- navicat:连接云端数据库 服务器放行3306端口,数据库修改root用户远程连接权限,默认root用户只能在本地登录
- 开放全部端口
- use mysql;
- select host, user from user;
- update user set host = '%' where user = 'root';
- flush privileges;
- 注意:云服务器记得开3306端口
四、安装node与npm
- yum install nodejs
- node - v
- yum install npm
- npm -v
五、安装pm2
- npm install pm2 -g
- npm install pm2 -g
- 启动项目:pm2 start 脚本(./app.js) --name 自定义名称
- 查看运行的项目 pm2 restart 自定义名称/id
- 重启项目:Pm2 restart 自定义名称/id
- 停止项目:Pm2 stop 自定义名称/id
- 删除项目:Pm2 delete 自定义名称/id
六 新建文件夹,存放后端代码
- mkdir node
- cd node
- 安装项目npm依赖:npm i -启动项目:pm2 start src/main.js --name node
七、安装nginx
- yum安装:yum install nginx
- 启动nginx:systemctl start nginx /nginx
- 查看nginx状态:systemctl status nginx
- systemctl start nginx.service
- systemctl enable nginx.service(需要配置跟系统同时启动)
- 重启nginx:systemctl restart nginx
- 查看nginx语法错误:nginx -t
- 查看运行的进程:ps -A | grep nginx
- 杀掉进程: kill -9 30914(编号)
- 安装默认路径:/usr/share/nginx/html 与 /etc/nginx
八、前端项目部署
- 创建文件夹:mkdir consume
- 将build的今天静态资源放进去
- 配置nginx.conf文件:http对象里面 `
server {
listen 8080;
server_name 114.55.4.25;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET,POST';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
location / {
root /usr/share/nginx/html/consume;
index index.html index.htm;
}
location /dev/ {
proxy_pass http://114.55.4.25:8000/;
}
}
` 4. 重启nginx:systemctl restart nginx
cd vue
通过express创建服务器
npm init -y
npm install compression -D
npm i
安装依赖
npm i express
npm i compression
上传打包后的文件夹
pm2 start app.js --name vue
打印日志:pm2 logs
前端项目上线:
1、通过node创建web服务器
创建node项目,并安装express,快速创建web服务器,将vue打包生成dist文件夹,托管为静态资源。
2、开启gzip
const express = require('express') // 开启gzip:减少静态资源压缩体积,传输体积更快,首页面渲染更快 const compression = require('compression') const app = express() // 先注册中间件gzip压缩 app.use(compression()) // 托管为静态资源 app.use(express.static('./dist'))
app.listen(8080, '0.0.0.0', () => { console.log('服务器启动成功!8080端口') })