rap2搭建,mysql,redis,nginx安装,node环境安装,rap2安装

2024-04-19 17:48

本文主要是介绍rap2搭建,mysql,redis,nginx安装,node环境安装,rap2安装,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

所需环境

1、mysql
2、redis
3、nginx安装
4、npm/nodejs环境
5、rap2-delos端安装
6、客户端dolores环境搭建

1、mysql安装

CentOS7的yum源中默认好像是没有mysql的。为了解决这个问题,我们要先下载mysql的repo源。

1. 下载mysql的repo源

$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2. 安装mysql-community-release-el7-5.noarch.rpm包

   $ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

安装这个包后,会获得两个mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。

3. 安装mysql

$ sudo yum install mysql-server

根据步骤安装就可以了,不过安装完成后,没有密码,需要重置密码。

4. 重置密码

重置密码前,首先要登录

$ mysql -u root

登录时有可能报这样的错:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),原因是/var/lib/mysql的访问权限问题。下面的命令把/var/lib/mysql的拥有者改为当前用户:

$ sudo chown -R root:root /var/lib/mysql

5、修改my.cnf
vim /etc/my.cnf,修改的内容是:

[mysqld]
basedir=/home/mysql
datadir=/home/mysql/data
port=3306
skip-grant-tables
character_set_server=utf8
init_connect='SET NAMES utf8'
max_connections=500
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#socket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemdmax_allowed_packet=256M[client]
default-character-set=utf8#[mysqld_safe]
#log-error=/home/mysql/log/mariadb.log
#pid-file=/home/mysql/run/mariadb/mariadb.pid#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

然后,重启服务:

$ service mysqld restart

6、接下来登录重置密码:

$ mysql -u root      (直接Enter进入)
修改root的密码
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> update user set authentication_string = PASSWORD('123456') where user = 'root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1mysql> \s
--------------
mysql  Ver 14.14 Distrib 5.7.21, for linux-glibc2.12 (x86_64) using  EditLine wrapperConnection id:		2
Current database:	mysql
Current user:		root@
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		5.7.21 MySQL Community Server (GPL)
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8
Db     characterset:	latin1
Client characterset:	utf8
Conn.  characterset:	utf8
UNIX socket:		/tmp/mysql.sock
Uptime:			4 min 43 secThreads: 1  Questions: 42  Slow queries: 0  Opens: 127  Flush tables: 1  Open tables: 122  Queries per second avg: 0.148
--------------mysql>

修改完成密码之后将/etc/my.cnf中的skip-grant-tables注释掉
然后重启mysql,执行命令:service mysqld restart

7. 需要更改权限才能实现远程连接MYSQL数据库

可以通过以下方式来确认:

mysql -u root –p     #接下来输入密码:123456
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)mysql>

如果在上面步骤出现类似如下的错误:

ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'

解决办法是:

service mysqld stop
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &mysql -u root mysql
mysql>use mysql ;
mysql> UPDATE user SET Password=PASSWORD('123456') where USER='root' and host='127.0.0.l' or host='bigdata1' or host='localhost';//把空的用户密码都修改成非空的密码就行了。(我将此处的newpassword 改成了123456)
mysql> FLUSH PRIVILEGES;
mysql> quit然后service mysqld start
再次输入以下,发现已经需要输入密码了
mysql -uroot -p
[root@bigdata1 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.43 MySQL Community Server (GPL)Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
mysql> use mysql
mysql> grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
mysql> flush privileges;

可以查看密码信息

mysql> select host, user, password from user;
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| bigdata1  | root | 123456                                    |
| 127.0.0.1 | root | 123456                                    |
| ::1       | root | 123456                                    |
| localhost |      | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| bigdata1  |      |                                           |
| %         | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+------+-------------------------------------------+
7 rows in set (0.00 sec)mysql>

至此mysql安装完毕

2、安装redis

参考地址:https://www.cnblogs.com/zuidongfeng/p/8032505.html

3、nginx安装

安装方式:https://blog.csdn.net/tototuzuoquan/article/details/78155700
3.1 安装所需环境
Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Windows 版本,本篇则使用 CentOS 7 作为安装环境。
一. gcc 安装
安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:

yum install gcc-c++

二. PCRE pcre-devel 安装
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:

yum install -y pcre pcre-devel

三. zlib 安装
zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。

yum install -y zlib zlib-devel

四. OpenSSL 安装
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。
yum install -y openssl openssl-devel
3.2 官网下载
1.直接下载.tar.gz安装包,地址:https://nginx.org/en/download.html
在这里插入图片描述
2.使用wget命令下载(推荐)。
wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
在这里插入图片描述
我下载的是1.10.1版本,这个是目前的稳定版。
3.3 解压
依然是直接命令:

tar -zxvf nginx-1.10.1.tar.gz -C /home/bigdata/installed/
cd nginx-1.10.1

3.4 配置
其实在 nginx-1.10.1 版本中你就不需要去配置相关东西,默认就可以了。当然,如果你要自己配置目录也是可以的。
1.使用默认配置

./configure

2.自定义配置(不推荐)

./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi

注:将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录
3.5 编译安装

make
make install

查找安装路径:

whereis nginx

在这里插入图片描述
3.6 启动、停止nginx
cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload
./nginx -s quit:此方式停止步骤是待nginx进程处理任务完毕进行停止。
./nginx -s stop:此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
查询nginx进程:
ps aux|grep nginx
3.7 重启 nginx
1.先停止再启动(推荐):
对 nginx 进行重启相当于先停止再启动,即先执行停止命令再执行启动命令。如下:
./nginx -s quit
./nginx
2.重新加载配置文件:
当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 ngin x再启动 nginx 即可将配置信息在 nginx 中生效,如下:
./nginx -s reload
启动成功后,在浏览器可以看到这样的页面:
在这里插入图片描述
3.8 开机自启动
即在rc.local增加启动代码就可以了。
vi /etc/rc.local
增加一行 /usr/local/nginx/sbin/nginx (这里在实际的机器上已经注释掉了)
设置执行权限:
chmod 755 rc.local
在这里插入图片描述
到这里,nginx就安装完毕了,启动、停止、重启操作也都完成了,当然,你也可以添加为系统服务,我这里就不在演示了。

4、安装npm/nodejs环境

参考地址:https://blog.csdn.net/micarlxm/article/details/81091284
下载的版本是:wget https://nodejs.org/dist/latest-v8.x/node-v8.15.1-linux-x64.tar.gz

5、安装rap2-delos

1、下载服务端代码
git clone https://github.com/thx/rap2-delos.git

配置文件

目录:rap2-delos/src/config
文件:config.dev.ts;config.local.ts;config.prod.ts 请把三个文件都修改  请看下面注释
修改:config.dev.ts文件中db对象中username,password参数与本地或者开发环境的数据库信息匹配

上面三个 配置文件 config.*.tx 都要修改 主要是针对 mysql 做修改

import { IConfigOptions } from "../types";let config: IConfigOptions = {version: '2.3',serve: {port: 8080,},keys: ['some secret hurr'],session: {key: 'rap2:sess',},db: {dialect: 'mysql',host: 'localhost',port: 3306,username: 'root',password: '123456',database: 'db_rap2_delos_app',pool: {max: 5,min: 0,idle: 10000,},logging: false,},redis: {host: '127.0.0.1',port: 6379}
}export default config

三个文件都按照上面的文件进行配置

2、创建数据库
自己根据上面定义的数据名字创建 我的是 RAP2_DELOS_APP

CREATE DATABASE IF NOT EXISTS db_rap2_delos_app
DEFAULT CHARSET utf8
COLLATE utf8_general_ci;

3、安装依赖包

进入项目根目录
# cd rap2-delos
安装项目所需依赖
# npm install
全局安装PM2   这是用来启动服务端代码的
# npm install -g pm2
安装 TypeScript 编译包
# npm install typescript -g

4、初始化数据库

执行编译  
# npm run build
如果上面编译报错  rimraf: command not found  则执行 npm install rimraf --save-dev -g  其他错误根据具体去处理初始化数据库  如果不执行上面的编译 直接执行初始化数据库会报错
# npm run create-db
如果上面报错 sh: cross-env: command not found  则先执行 npm install --save-dev cross-env -g

5、代码规范检查

# npm run check
如果上面报错 sh: tslint: command not found  则先执行 npm install -g tslint typescript

6、启动项目 下面两种不同的启动方式

开发模式 启动开发模式的服务器 监视并在发生代码变更时自动重启 (第一次运行比较慢,请耐心等待)
# npm run dev生产模式 启动生产模式服务器
# npm start没报错代表启动了起来   如果启动失败,请确认node 已经是10版本以上,如果不是 请先切换版本  nvm use v10.15.0

7、查看是否正常启动

1、执行命令 如下显示则代表数据库连接正常
pm2 log

DATABASE √
HOST localhost
PORT 3306
DATABASE RAP2_DELOS_APP

2、浏览器查看 ip:8080 请记得开放 8080 端口[下面代表启动正常]

1、执行命令 如下显示则代表数据库连接正常
pm2 log

DATABASE √
HOST localhost
PORT 3306
DATABASE RAP2_DELOS_APP

2、浏览器查看 ip:8080 请记得开放 8080 端口[下面代表启动正常]

RAP2后端服务已启动,请从前端服务(rap2-dolores)访问。 RAP2 back-end server is started, please visit via front-end service (rap2-dolores).

8、常见问题

1、执行npm run create-db命令,提示Unable to connect to the database:{ SequelizeAccessDeniedError: Access denied for user 'root'@'localhost' (using password:NO)}原因:未修改rap2-delos/src/config目录下数据库配置文件,或者是与文件中的数据库信息与之连接的数据库信息不匹配
解决方法:修改config.dev.ts文件数据库配置信息如果修改正确无误后,执行npm run create-db依旧出错,那么查看该项目中是否已经存在dist目录,如果有,请按照如上修改对应的数据库配置信息2、执行npm run dev命令,提示Error: listen EADDRINUSE :::8080原因:8080 端口被占用解决方法:杀掉占用 8080 端口的应用3、执行npm install 命令,提示hiredis 编译无法通过原因:无权限操作rap2-delos/node_modules/hiredis路径解决方法:sudo npm install如果提示sudo: npm: command not found,请参考 stackoverflow-npm,stackoverflow-node4、执行npm run dev可以正常启动,npm start命令无法正常启动服务原因:请使用pm2 logs查看日志具体定位5、示例:由于 Redis 的安全模式,不能正常使用ReplyError: Ready check failed: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
解决方法: 使用--protected-mode no方式启动
--------------------- 
作者:清悟 
来源:CSDN 
原文:https://blog.csdn.net/qq_16142851/article/details/85198925 
版权声明:本文为博主原创文章,转载请附上博文链接!

7、客户端dolores环境搭建

1、获取源代码

git clone https://github.com/thx/rap2-dolores.git
执行不成功 多执行几次,或者直接在浏览器打开 https://github.com/thx/rap2-dolores.git 去下载压缩包回来

2、配置文件

目录:rap2-dolores/src/config
文件:config.dev.ts; 其中 dev,表示开发环境,其他同理
修改:config.dev.ts文件,serve地址是 服务端 rap2-delos 部署成功后的地址,默认:'http://localhost:8080'   可以不做修改

最终修改如下 配置文件如下 请注意 ip 那里 不能使用 127.0.0.1 请使用服务器ip (可以尝试使用localhost试试)
module.exports = {
serve: ‘http://ip:8080’,
keys: [‘some secret hurr’],
session: {
key: ‘koa:sess’
}
}
3、安装项目依赖包

# npm install  【如果报下面错误】错误gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/data/wwwroot/rap2-dolores/node_modules/node-sass/.node-gyp'错误解决1、在项目根目录创建.npmrc文件,复制下面代码到该文件
phantomjs_cdnurl=http://cnpmjs.org/downloads
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
registry=https://registry.npm.taobao.org2、删除之前安装node-sass包
# npm uninstall node-sass
3、重新安装
# npm install -g node-sass如果上面还是不成功还是报错 
ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/data/wwwroot/rap2-dolores/node_modules/node-sass/.node-gyp'安装淘宝 npm
# npm install -g cnpm --registry=https://registry.npm.taobao.org
使用cnpm 安装node-sass
# cnpm install -g node-sass执行成功后 再执行npm install

4、编译启动项目

01、开发模式 自动监视改变后重新编译
# npm run dev
备注:测试用例
# npm run test02、生产模式 编译 React 生产包
# npm run build

5、配置服务器 我使用的是nginx

使用 nginx 服务器路由到编译产出的 build 文件夹作为静态服务器即可配置如下   8181 是我的前端页面端口server {listen 8181;server_name _;root /data/wwwroot/rap2-dolores/build;index index.html index.htm;location / {try_files $uri /index.html;}error_page 500 502 503 504 /500.html;
}重新加载配置文件
# systemctl reload nginx访问服务 ip:8181  成功如果不成功 一直有圈圈在转 请查看 rap2-dolores/src/config/config.dev.ts 文件 ip 必须是服务器的ip 不能是127.0.0.1module.exports = {serve: 'http://ip:8080',keys: ['some secret hurr'],session: {key: 'koa:sess'}
}配置完成后 重新运行 npm run build  即可

这篇关于rap2搭建,mysql,redis,nginx安装,node环境安装,rap2安装的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/918202

相关文章

Mysql的主从同步/复制的原理分析

《Mysql的主从同步/复制的原理分析》:本文主要介绍Mysql的主从同步/复制的原理分析,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录为什么要主从同步?mysql主从同步架构有哪些?Mysql主从复制的原理/整体流程级联复制架构为什么好?Mysql主从复制注意

Nginx Location映射规则总结归纳与最佳实践

《NginxLocation映射规则总结归纳与最佳实践》Nginx的location指令是配置请求路由的核心机制,其匹配规则直接影响请求的处理流程,下面给大家介绍NginxLocation映射规则... 目录一、Location匹配规则与优先级1. 匹配模式2. 优先级顺序3. 匹配示例二、Proxy_pa

python获取cmd环境变量值的实现代码

《python获取cmd环境变量值的实现代码》:本文主要介绍在Python中获取命令行(cmd)环境变量的值,可以使用标准库中的os模块,需要的朋友可以参考下... 前言全局说明在执行py过程中,总要使用到系统环境变量一、说明1.1 环境:Windows 11 家庭版 24H2 26100.4061

如何搭建并配置HTTPD文件服务及访问权限控制

《如何搭建并配置HTTPD文件服务及访问权限控制》:本文主要介绍如何搭建并配置HTTPD文件服务及访问权限控制的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、安装HTTPD服务二、HTTPD服务目录结构三、配置修改四、服务启动五、基于用户访问权限控制六、

如何解决Druid线程池Cause:java.sql.SQLRecoverableException:IO错误:Socket read timed out的问题

《如何解决Druid线程池Cause:java.sql.SQLRecoverableException:IO错误:Socketreadtimedout的问题》:本文主要介绍解决Druid线程... 目录异常信息触发场景找到版本发布更新的说明从版本更新信息可以看到该默认逻辑已经去除总结异常信息触发场景复

MyBatis编写嵌套子查询的动态SQL实践详解

《MyBatis编写嵌套子查询的动态SQL实践详解》在Java生态中,MyBatis作为一款优秀的ORM框架,广泛应用于数据库操作,本文将深入探讨如何在MyBatis中编写嵌套子查询的动态SQL,并结... 目录一、Myhttp://www.chinasem.cnBATis动态SQL的核心优势1. 灵活性与可

pytest+allure环境搭建+自动化实践过程

《pytest+allure环境搭建+自动化实践过程》:本文主要介绍pytest+allure环境搭建+自动化实践过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、pytest下载安装1.1、安装pytest1.2、检测是否安装成功二、allure下载安装2.

MySQL 表的内外连接案例详解

《MySQL表的内外连接案例详解》本文给大家介绍MySQL表的内外连接,结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录表的内外连接(重点)内连接外连接表的内外连接(重点)内连接内连接实际上就是利用where子句对两种表形成的笛卡儿积进行筛选,我

使用vscode搭建pywebview集成vue项目实践

《使用vscode搭建pywebview集成vue项目实践》:本文主要介绍使用vscode搭建pywebview集成vue项目实践,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录环境准备项目源码下载项目说明调试与生成可执行文件核心代码说明总结本节我们使用pythonpywebv

Pytorch介绍与安装过程

《Pytorch介绍与安装过程》PyTorch因其直观的设计、卓越的灵活性以及强大的动态计算图功能,迅速在学术界和工业界获得了广泛认可,成为当前深度学习研究和开发的主流工具之一,本文给大家介绍Pyto... 目录1、Pytorch介绍1.1、核心理念1.2、核心组件与功能1.3、适用场景与优势总结1.4、优