nodejs + mysql(v8.0.28) + nginx

linux : Centos7

nodejs:v16.14.2

Mysql:v8.0.28

Nginx:v1.21.1

安装nodejs

安装git

yum install git -y

安装 nvm

下载 nvm

wget https://github.com/nvm-sh/nvm/archive/refs/tags/v0.38.0.tar.gz

解压 nvm

mkdir -p /root/.nvm
tar -zxvfv0.38.0.tar.gz -C /root/.nvm

配置环境

  • 打开 ~/.bashrc
vim ~/.bashrc
  • 在~/.bashrc的末尾,添加如下语句:

    export NVM_DIR="$HOME/.nvm/nvm-0.38.0"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
    

读取并使用配置

source ~/.bashrc

查看可安装的nodejs版本

nvm ls-remote

查看已安装的nodejs版本

nvm ls

下载指定版本nodejs

nvm install v16.14.2

使用指定nodejs版本

nvm use v16.14.2

卸载指定版本

nvm uninstall 8.16.0

安装mysql8.0.28

下载 rpm

wget https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm

安装rpm

rpm -ivh mysql80-community-release-el7-5.noarch.rpm

真正安装MySql

  • 这里时间会久点
  • 出现选择就选 y
yum install mysql-community-server

启动MySql

service mysqld restart

获取初次登录密码

grep "password" /var/log/mysqld.log

输出结果:2022-04-11T09:51:28.478708Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: albgjh6s0/To <== 密码,拷贝,用户下一步登录

登录mysql

mysql -uroot -p

第一次安装修改密码

alter user user() identified by 'Root_12root';   //Root_12root 是新密码

不修改密码报错

You must reset your password using ALTER USER statement before executing this statement.

译:在执行此语句之前,您必须使用Alter User语句重置密码

修改远程登录权限

  1. 登录
mysql -uroot -p
  1. 选择mysql数据库
use mysql;
  1. 修改user表使其root用户可以通过远程连接
update user set host = '%' where user = 'root'
  1. 查看是否开启
select * from mysql.user where user='root' \G;

返回的结果中包括 Host: % 就说明成功了

*************************** 1. row ***************************
 							Host: %
                   	 		User: root
  1. 刷新权限
flush privileges;

现在就在本地连接远程数据库了

安装 Nginx 服务器

安装在 /usr/local 目录

下载依赖

yum -y install pcre*

yum -y install openssl*

下载 wget(类似于迅雷,用来下载文件的)

yum install wget 

下载 nginx

wget http://nginx.org/download/nginx-1.21.1.tar.gz

解压

tar zxvf nginx-1.21.1.tar.gz

进入到解压后的目录,编译

两种编译模式选一个就行,若后面需要配置https协议,则使用第二个。

1. 普通编译

./configure

2. (https协议)携带–with-http_ssl_module配置编译,使编译内容有http_ssl_module,编译

 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

安装(在解压后的目录中执行)

make install

安装完毕后,会在同级目录(与解压后的目录)生成一个 nginx 的目录,这个才是我们的服务器目录

安装时遇到报错

make: *** No rule to make target `install’. Stop.

解决方法:

linux安装./configure --prefix=/usr/local/nginx报错:
报错1:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.

查看网上解决方法:
安装pcre-devel解决问题
yum -y install pcre-devel

报错2:
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib= option.

等等可能是因为缺少库导致的,所以我们需要安装前置库:
yum install -y gcc pcre pcre-devel openssl openssl-devel gd gd-devel

然后再次重新编译安装nginx.

启动 nginx 服务器

1.进入安装目录(nginx),在进入`sbin`目录,sbin目录只有一个nginx目录,
2.输入 ./nginx 即可启动

nginx 常用命令:

- ./nginx:启动

- ./nginx -v:查看版本

- ./nginx -s stop:停止

- ./nginx -s reload:重启   //在sbin目录下

如果确定开启了 nginx 服务器,但浏览器访问没有反应的解决

- 可能时防火墙的问题
查看版本:firewall-cmd --version
————————————————————————————————
输入命令(解决):

sudo firewall-cmd --permanent --zone=public --add-service=http 
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
——————————————————————
命令含义:
--zone #作用域
--add-port=80/tcp #添加开放端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效

防火墙操作

防火墙非必要操作

而什么时候操作呢?在开启了nginx服务后,本地还是不能通过http协议访问,就可能是防火墙的问题.

当 linux 是本地的虚拟机时,需要防火墙操作.

当 linux 是在各云服务提供商时是不用操作的.

查看状态

firewall-cmd --state

开启防火墙

systemctl start firewalld.service

关闭

systemctl stop firewalld.servicel

禁止开机启动防火墙

systemctl disable firewalld.service

重启防火墙

在更改了开放端口后需要重启

systemctl restart firewalld.service
firewall-cmd --reload

开放Mysql使用3306端口

firewall-cmd --permanent --zone=public --add-port=3306/tcp --permanent
firewall-cmd --permanent --zone=public --add-port=443/tcp --permanent
firewall-cmd --permanent --zone=public --add-port=80/tcp --permanent

查看开放端口

firewall-cmd --list-ports

防火墙端口转发

firewall-cmd --permanent --add-forward-port=port=80:proto=tcp:toport=8080
firewall-cmd --permanent --add-forward-port=port=443:proto=tcp:toport=8443

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值