• CentOS7虚拟机部署Part1


    安装centos7

    配置网络

    centos7 初始 不联网

    1.更改虚拟机网络链接为 桥接模式,并启用网络链接


    2 修改配置文件

    cd /etc/sysconfig/network-scripts/
    vi ifcfg-en33   # en33 会有差异
    • 1


    修改文件中的ONBOOT=yes

    3 配置静态ip


    重启

    service network restart


      更新yum

      1 安装wget

      yum install wget

        2 更换yum 源

        备份一下原本的yum源:

        mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

          下载阿里云的yum源

          wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

            生成缓存

            yum makecache

              3 更新

              yum update

                配置ssh

                检查有没有安装ssh服务:

                rpm -qa | grep ssh

                  如果没有安装ssh服务就安装 :

                  yum install openssh-server


                    安装好后在ssh配置文件里进行配置 :

                    vi /etc/ssh/sshd_config



                      开启ssh服务

                      /bin/systemctl start sshd.service


                        检查ssh服务是否开启

                        ps -e | grep sshd


                          检查22端口是否开启

                          netstat -an | grep 22

                            如果出错,netstat 命令没有发现,安装相关包

                            yum install net-tools


                              将ssh服务添加到自启动列表中:

                              systemctl enable sshd.service


                                查看虚拟机centos ip地址

                                ip addr

                                  在windows 客户端登录


                                  安装nodejs

                                  NodeJS 10.x

                                   # As root

                                  curl -sL https://rpm.nodesource.com/setup_10.x | bash -

                                     
                                     # No root privileges

                                    curl -sL https://rpm.nodesource.com/setup_10.x | sudo bash -


                                      安装 yarn

                                       ## 安装yarn

                                      curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
                                      yum install -y yarn
                                      • 1


                                      更换npm源


                                      npm install -g cnpm --registry=https://registry.npm.taobao.org


                                        安装 @nestjs/cli


                                        cnpm install -g i @nestjs/cli@6.0.0

                                          查看版本


                                          nest --version


                                            安装mysql

                                            清华源


                                            vi /etc/yum.repos.d/mysql-community.repo


                                              修改5.7 版本对应的baseurl为


                                              baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/


                                                同时 enable改为1

                                                 enable=1

                                                打开清华镜像站点


                                                https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/


                                                  选择版本(5.7),el7代表centos7

                                                  复制链接地址


                                                  https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/


                                                    下载


                                                    wget https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/


                                                      安装


                                                      yum -y install mysql-community-server


                                                        启动


                                                        systemctl start mysqld


                                                          1 安装yum repo

                                                          由于centos的yum源中没有mysql,需要到mysql的官网下载yum repo配置文件


                                                          wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm


                                                            然后进行repo的安装


                                                            rpm -ivh mysql57-community-release-el7-9.noarch.rpm


                                                              2 安装mysql

                                                              安装


                                                              yum install mysql-server


                                                                启动mysql


                                                                systemctl start mysqld


                                                                  获取安装时的临时密码


                                                                  grep 'temporary password' /var/log/mysqld.log
                                                                  
                                                                  • 1

                                                                  # eB%lUTsHU2%n


                                                                  登录mysql

                                                                  mysql -u root -p


                                                                      输入获取的临时密码

                                                                      grep ‘temporary password’ /var/log/mysqld.log


                                                                        登录成功后,修改登录密码

                                                                        1 修改密码(密码必须满足密码策略,设复杂点)


                                                                        ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘root_@_Password_0’;

                                                                             


                                                                            2 查看mysql初始密码策略


                                                                            SHOW VARIABLES LIKE ‘validate_password%’;


                                                                                关于 mysql 密码策略相关参数;

                                                                                1)、validate_password_length  固定密码的总长度;

                                                                                2)、validate_password_dictionary_file 指定密码验证的文件路径;

                                                                                3)、validate_password_mixed_case_count  整个密码中至少要包含大/小写字母的总个数;

                                                                                4)、validate_password_number_count  整个密码中至少要包含阿拉伯数字的个数;

                                                                                5)、validate_password_policy 指定密码的强度验证等级,默认为 MEDIUM;

                                                                                关于 validate_password_policy 的取值:

                                                                                LOW:只验证长度;

                                                                                1/MEDIUM:验证长度、数字、大小写、特殊字符;

                                                                                2/STRONG:验证长度、数字、大小写、特殊字符、字典文件;

                                                                                6)、validate_password_special_char_count 整个密码中至少要包含特殊字符的个数;

                                                                                创建数据库

                                                                                create database taskmanagement charset utf8 collate utf8_general_ci;


                                                                                    设置环境变量

                                                                                    此处凡是通过process.env获取的 数据都 添加到环境变量中

                                                                                    不敏感的配置如端口 定义在代码的config文件夹中(基于代码的)

                                                                                    敏感信息,如生产模式数据库名和密码定义在环境变量中。

                                                                                    在node环境中,process.env 一直是可用的,不用安装其他软件就可以使用,可以在 node环境中测试

                                                                                    process.env.PROCESSOR_ARCHITECTURE

                                                                                         


                                                                                         // 结果 ‘AMD64’

                                                                                        打开/etc/bashrc,添加项目中 process.env 指向的环境变量

                                                                                        export NODE_ENV=production


                                                                                           # 运行端口


                                                                                          export RDS_PORT=3306 #数据库端口


                                                                                             #数据库用户名


                                                                                            export RDS_USERNAME=root


                                                                                               #数据库密码


                                                                                              export RDS_PASSWORD=root  # 你自己的数据库密码


                                                                                                 # 数据库名


                                                                                                export RDS_DB_NAME=taskmanagement  # 你自己的数据库名


                                                                                                   # 生产环境数据库模式

                                                                                                  export TYPEORM_SYNC=false
                                                                                                  export JWT_SECRET=topSecret51
                                                                                                  • 1


                                                                                                  运行命令


                                                                                                  source /etc/bashrc


                                                                                                    ngnix安装与配置(此处更改为open)

                                                                                                    安装

                                                                                                    1 添加nginx源


                                                                                                    rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm


                                                                                                      2 安装nginx


                                                                                                      yum -y install nginx


                                                                                                        3 启动nginx


                                                                                                        /usr/sbin/nginx


                                                                                                          4 查看防火墙状态,开启80端口


                                                                                                          systemctl status firewalld
                                                                                                          firewall-cmd --state
                                                                                                          firewall-cmd --list-all
                                                                                                          firewall-cmd --permanent --add-port=80/tcp
                                                                                                          • 1
                                                                                                          • 2
                                                                                                          • 3


                                                                                                          重启防火墙


                                                                                                          firewall-cmd --reload


                                                                                                            5 测试nginx(浏览器输入)


                                                                                                            http://ip:80


                                                                                                              6 设置nginx 开机启动


                                                                                                              systemctl enable nginx


                                                                                                                查看selinux的状态


                                                                                                                /usr/sbin/sestatus


                                                                                                                  将SELINUX=enforcing 修改为 SELINUX=disabled 状态


                                                                                                                  vim /etc/selinux/config
                                                                                                                  #SELINUX=enforcing
                                                                                                                  SELINUX=disabled
                                                                                                                  • 1
                                                                                                                  • 2

                                                                                                                  重启

                                                                                                                  reboot

                                                                                                                    配置

                                                                                                                    1 创建文件存放路径

                                                                                                                    mkdir website


                                                                                                                      根目录下创建website文件夹, website 下存放多个项目 文件.

                                                                                                                       

                                                                                                                      website
                                                                                                                      -todo
                                                                                                                      -frontend #前端
                                                                                                                      -backend #后端
                                                                                                                      • 1
                                                                                                                      • 2
                                                                                                                      • 3

                                                                                                                      2 修改文件夹权限


                                                                                                                      chmod 777 website #以及其他文件夹权限

                                                                                                                         


                                                                                                                        3 下载FileZilla,安装

                                                                                                                        链接服务端  略

                                                                                                                        4 编译前端代码,上传代码到前端文件夹

                                                                                                                        代码有两处需要修改:

                                                                                                                        4.1 编译前修改 前端代码中的 BASE_URL  为服务器

                                                                                                                        4.2 修改 tasks所有后端接口,添加 api/


                                                                                                                        yarn run build


                                                                                                                          上传生成的build文件夹下的所有文件

                                                                                                                          5 修改nginx 配置

                                                                                                                          vi /etc/nginx/conf.d/default.conf






                                                                                                                            重启nginx

                                                                                                                            nginx -s reload


                                                                                                                              测试

                                                                                                                              http://ip:80


                                                                                                                                6 后端代码上传

                                                                                                                                修改后端代码中的端口 为 4000

                                                                                                                                tasks 组件中添加 api/

                                                                                                                                上传出 node_modules与 .git外的所有代码到后端存放路径

                                                                                                                                进入

                                                                                                                                cd /website/todo/backend/

                                                                                                                                  7 安装 所需的库

                                                                                                                                  yarn install

                                                                                                                                    8 启动后端

                                                                                                                                     

                                                                                                                                    yarn run start:prod

                                                                                                                                      9 配置nginx 反向代理

                                                                                                                                      vi /etc/nginx/conf.d/default.conf

                                                                                                                                        server {
                                                                                                                                        listen 80;
                                                                                                                                        server_name localhost;
                                                                                                                                        location / {
                                                                                                                                        #root /usr/share/nginx/html;
                                                                                                                                        root /website/todo/frontend;
                                                                                                                                        index index.html index.htm;
                                                                                                                                        try_files u r i < / s p a n > < s p a n c l a s s = " t o k e n v a r i a b l e " > uri uri</span><spanclass="tokenvariable">uri/ /index.html;
                                                                                                                                        }
                                                                                                                                        location ^~ /auth {
                                                                                                                                        proxy_pass http://127.0.0.1:4000;
                                                                                                                                        }
                                                                                                                                        location ^~ /api {
                                                                                                                                        proxy_pass http://127.0.0.1:4000;
                                                                                                                                        }
                                                                                                                                        error_page 500 502 503 504 /50x.html;
                                                                                                                                        location = /50x.html {
                                                                                                                                        root /usr/share/nginx/html;
                                                                                                                                        }
                                                                                                                                        }
                                                                                                                                        • 1
                                                                                                                                        • 2
                                                                                                                                        • 3
                                                                                                                                        • 4
                                                                                                                                        • 5
                                                                                                                                        • 6
                                                                                                                                        • 7
                                                                                                                                        • 8
                                                                                                                                        • 9
                                                                                                                                        • 10
                                                                                                                                        • 11
                                                                                                                                        • 12
                                                                                                                                        • 13
                                                                                                                                        • 14
                                                                                                                                        • 15
                                                                                                                                        • 16
                                                                                                                                        • 17
                                                                                                                                        • 18
                                                                                                                                        • 19
                                                                                                                                        • 20
                                                                                                                                        • 21
                                                                                                                                        • 22
                                                                                                                                        • 23
                                                                                                                                        • 24
                                                                                                                                        • 25
                                                                                                                                        • 26
                                                                                                                                        • 27
                                                                                                                                        • 28
                                                                                                                                        • 29
                                                                                                                                        • 30
                                                                                                                                        • 31
                                                                                                                                        • 32
                                                                                                                                        • 33
                                                                                                                                        • 34
                                                                                                                                        • 35
                                                                                                                                        • 36
                                                                                                                                        • 37
                                                                                                                                        • 38
                                                                                                                                        • 39
                                                                                                                                        • 40
                                                                                                                                        • 41
                                                                                                                                        • 42
                                                                                                                                        • 43
                                                                                                                                        • 44
                                                                                                                                        • 45
                                                                                                                                        • 46
                                                                                                                                        • 47
                                                                                                                                        • 48
                                                                                                                                        • 49
                                                                                                                                        • 50
                                                                                                                                        • 51
                                                                                                                                        • 52
                                                                                                                                        • 53
                                                                                                                                        • 54
                                                                                                                                        • 55
                                                                                                                                        • 56
                                                                                                                                        • 57
                                                                                                                                        • 58
                                                                                                                                        • 59
                                                                                                                                        • 60
                                                                                                                                        • 61
                                                                                                                                        • 62
                                                                                                                                        • 63
                                                                                                                                        • 64
                                                                                                                                        • 65
                                                                                                                                        • 66
                                                                                                                                        • 67
                                                                                                                                        • 68
                                                                                                                                        • 69
                                                                                                                                        • 70
                                                                                                                                        • 71
                                                                                                                                        • 72
                                                                                                                                        • 73
                                                                                                                                        • 74
                                                                                                                                        • 75
                                                                                                                                        • 76
                                                                                                                                        • 77
                                                                                                                                        • 78
                                                                                                                                        • 79
                                                                                                                                        • 80
                                                                                                                                        • 81
                                                                                                                                        • 82
                                                                                                                                        • 83
                                                                                                                                        • 84
                                                                                                                                        • 85
                                                                                                                                        • 86
                                                                                                                                        • 87
                                                                                                                                        • 88
                                                                                                                                        • 89
                                                                                                                                        • 90
                                                                                                                                        • 91
                                                                                                                                        • 92
                                                                                                                                        • 93
                                                                                                                                        • 94
                                                                                                                                        • 95
                                                                                                                                        • 96
                                                                                                                                        • 97
                                                                                                                                        • 98
                                                                                                                                        • 99
                                                                                                                                        • 100
                                                                                                                                        • 101
                                                                                                                                        • 102
                                                                                                                                        • 103
                                                                                                                                        • 104
                                                                                                                                        • 105
                                                                                                                                        • 106
                                                                                                                                        • 107
                                                                                                                                        • 108
                                                                                                                                        • 109
                                                                                                                                        • 110
                                                                                                                                        • 111
                                                                                                                                        • 112
                                                                                                                                        • 113
                                                                                                                                        • 114
                                                                                                                                        • 115
                                                                                                                                        • 116
                                                                                                                                        • 117
                                                                                                                                        • 118
                                                                                                                                        • 119
                                                                                                                                        • 120
                                                                                                                                        • 121
                                                                                                                                        • 122
                                                                                                                                        • 123
                                                                                                                                        • 124
                                                                                                                                        • 125
                                                                                                                                        • 126
                                                                                                                                        • 127
                                                                                                                                        • 128
                                                                                                                                        • 129
                                                                                                                                        • 130
                                                                                                                                        • 131
                                                                                                                                        • 132
                                                                                                                                        • 133
                                                                                                                                        • 134
                                                                                                                                        • 135
                                                                                                                                        • 136
                                                                                                                                        • 137
                                                                                                                                        • 138
                                                                                                                                        • 139

                                                                                                                                         
                                                                                                                                         

                                                                                                                                        重启ngnix

                                                                                                                                        nginx -s reload

                                                                                                                                          启动后端

                                                                                                                                          yarn run start:prod


                                                                                                                                            PM2 配置

                                                                                                                                            pm2安装,测试

                                                                                                                                            npm i -g pm2

                                                                                                                                              使用PM2启动  项目(只需执行一次)

                                                                                                                                              pm2 start yarn --interpreter bash --name todo – start:prod

                                                                                                                                                 

                                                                                                                                                停止项目

                                                                                                                                                pm2 stop todo

                                                                                                                                                  重启项目

                                                                                                                                                   

                                                                                                                                                  pm2 restart todo

                                                                                                                                                    杀死项目进程

                                                                                                                                                     

                                                                                                                                                    pm2 delete 0,1,2 .  # 数字代表 pm2进程,all --删除所有进程



                                                                                                                                                    • 相关阅读:
                                                                                                                                                      Java分布式定时任务场景的思考与设计
                                                                                                                                                      腾讯mini项目-【指标监控服务重构-会议记录】2023-08-04
                                                                                                                                                      每日一问07——什么是Softmax回归?和线性回归的区别是什么?
                                                                                                                                                      conda创建python虚拟环境
                                                                                                                                                      关于xlrd.biffh.XLRDError: Excel xlsx file; not supported的解决方法
                                                                                                                                                      【数据结构】前言
                                                                                                                                                      React中如何提高组件的渲染效率
                                                                                                                                                      idgen导入Android11源码
                                                                                                                                                      stable diffusion实践操作-大模型介绍-SDXL1大模型
                                                                                                                                                      刷题日记【第八篇】-笔试必刷题【查找输入整数二进制中1的个数+手套+完全数计算+扑克牌大小】
                                                                                                                                                    • 原文地址:https://blog.csdn.net/github_37759996/article/details/126126758