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 的索引?常见的索引类型有哪些?总结性回答详细解释1. MySQL 索引的概念2

使用Redis快速实现共享Session登录的详细步骤

《使用Redis快速实现共享Session登录的详细步骤》在Web开发中,Session通常用于存储用户的会话信息,允许用户在多个页面之间保持登录状态,Redis是一个开源的高性能键值数据库,广泛用于... 目录前言实现原理:步骤:使用Redis实现共享Session登录1. 引入Redis依赖2. 配置R

Nginx进行平滑升级的实战指南(不中断服务版本更新)

《Nginx进行平滑升级的实战指南(不中断服务版本更新)》Nginx的平滑升级(也称为热升级)是一种在不停止服务的情况下更新Nginx版本或添加模块的方法,这种升级方式确保了服务的高可用性,避免了因升... 目录一.下载并编译新版Nginx1.下载解压2.编译二.替换可执行文件,并平滑升级1.替换可执行文件

shell脚本批量导出redis key-value方式

《shell脚本批量导出rediskey-value方式》为避免keys全量扫描导致Redis卡顿,可先通过dump.rdb备份文件在本地恢复,再使用scan命令渐进导出key-value,通过CN... 目录1 背景2 详细步骤2.1 本地docker启动Redis2.2 shell批量导出脚本3 附录总

批量导入txt数据到的redis过程

《批量导入txt数据到的redis过程》用户通过将Redis命令逐行写入txt文件,利用管道模式运行客户端,成功执行批量删除以Product*匹配的Key操作,提高了数据清理效率... 目录批量导入txt数据到Redisjs把redis命令按一条 一行写到txt中管道命令运行redis客户端成功了批量删除k

Win10安装Maven与环境变量配置过程

《Win10安装Maven与环境变量配置过程》本文介绍Maven的安装与配置方法,涵盖下载、环境变量设置、本地仓库及镜像配置,指导如何在IDEA中正确配置Maven,适用于Java及其他语言项目的构建... 目录Maven 是什么?一、下载二、安装三、配置环境四、验证测试五、配置本地仓库六、配置国内镜像地址

Python安装Pandas库的两种方法

《Python安装Pandas库的两种方法》本文介绍了三种安装PythonPandas库的方法,通过cmd命令行安装并解决版本冲突,手动下载whl文件安装,更换国内镜像源加速下载,最后建议用pipli... 目录方法一:cmd命令行执行pip install pandas方法二:找到pandas下载库,然后

MySQL中EXISTS与IN用法使用与对比分析

《MySQL中EXISTS与IN用法使用与对比分析》在MySQL中,EXISTS和IN都用于子查询中根据另一个查询的结果来过滤主查询的记录,本文将基于工作原理、效率和应用场景进行全面对比... 目录一、基本用法详解1. IN 运算符2. EXISTS 运算符二、EXISTS 与 IN 的选择策略三、性能对比

MySQL常用字符串函数示例和场景介绍

《MySQL常用字符串函数示例和场景介绍》MySQL提供了丰富的字符串函数帮助我们高效地对字符串进行处理、转换和分析,本文我将全面且深入地介绍MySQL常用的字符串函数,并结合具体示例和场景,帮你熟练... 目录一、字符串函数概述1.1 字符串函数的作用1.2 字符串函数分类二、字符串长度与统计函数2.1

Redis客户端连接机制的实现方案

《Redis客户端连接机制的实现方案》本文主要介绍了Redis客户端连接机制的实现方案,包括事件驱动模型、非阻塞I/O处理、连接池应用及配置优化,具有一定的参考价值,感兴趣的可以了解一下... 目录1. Redis连接模型概述2. 连接建立过程详解2.1 连php接初始化流程2.2 关键配置参数3. 最大连