DevOps之基本软件安装:在Redhat 8.x 上 安装NodeJS,PM2,Docker, Ngnix

Posted 大象无形,大音希声

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DevOps之基本软件安装:在Redhat 8.x 上 安装NodeJS,PM2,Docker, Ngnix相关的知识,希望对你有一定的参考价值。

在Redhat 8.x 上 安装NodeJS,PM2,Docker, Ngnix

前言

DevOps工具栈中基本工具安装是非常常见和重要的,比如NodeJS的安装,PM2的安装,Docker的安装等等。下面

Node安装

Node的安装步骤如下:
Step1. 下载gz安装包

cd ~/download
wget https://nodejs.org/dist/latest-v12.x/node-v12.22.12-linux-x64.tar.xz


Step2. 创建Node的安装目录

VERSION=v12.22.12
DISTRO=linux-x64
sudo mkdir -p /usr/local/lib/nodejs
sudo tar -xJvf node-$VERSION-$DISTRO.tar.xz -C /usr/local/lib/nodejs 

Step3 设置环境变量

. ~/.profile

echo > ~/.profile
vim ~/.profile

把下面的配置加入到上面的配置文件~/.profile里面

# Nodejs
VERSION=v12.22.12
DISTRO=linux-x64
export PATH=/usr/local/lib/nodejs/node-$VERSION-$DISTRO/bin:$PATH


Step4 环境变量生效

. ~/.profile

Step5 验证是否安装成功

[root@iZ0jl7nhcg5nazavryytxkZ ~]# node -v
v12.22.12
[root@iZ0jl7nhcg5nazavryytxkZ ~]# npm -v
6.14.16
[root@iZ0jl7nhcg5nazavryytxkZ ~]# npx -v
6.14.16
[root@iZ0jl7nhcg5nazavryytxkZ ~]# npm version

  npm: '6.14.16',
  ares: '1.18.1',
  brotli: '1.0.9',
  cldr: '37.0',
  http_parser: '2.9.4',
  icu: '67.1',
  llhttp: '2.1.4',
  modules: '72',
  napi: '8',
  nghttp2: '1.41.0',
  node: '12.22.12',
  openssl: '1.1.1n',
  tz: '2021a4',
  unicode: '13.0',
  uv: '1.40.0',
  v8: '7.8.279.23-node.57',
  zlib: '1.2.11'


pm2安装

pm2的安装比较简单,直接执行下面的命令

[root@iZ0jl7nhcg5nazavryytxkZ ~]# npm install pm2 -g
npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
/usr/local/lib/nodejs/node-v12.22.12-linux-x64/bin/pm2 -> /usr/local/lib/nodejs/node-v12.22.12-linux-x64/lib/node_modules/pm2/bin/pm2
/usr/local/lib/nodejs/node-v12.22.12-linux-x64/bin/pm2-dev -> /usr/local/lib/nodejs/node-v12.22.12-linux-x64/lib/node_modules/pm2/bin/pm2-dev
/usr/local/lib/nodejs/node-v12.22.12-linux-x64/bin/pm2-docker -> /usr/local/lib/nodejs/node-v12.22.12-linux-x64/lib/node_modules/pm2/bin/pm2-docker
/usr/local/lib/nodejs/node-v12.22.12-linux-x64/bin/pm2-runtime -> /usr/local/lib/nodejs/node-v12.22.12-linux-x64/lib/node_modules/pm2/bin/pm2-runtime
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules/pm2/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted "os":"darwin","arch":"any" (current: "os":"linux","arch":"x64")

pm2 --version
5.2.2

Docker安装

在Redhat企业版上安装Docker十分的简单,直接输入下面的命令 yum install docker
其输出如下:

[root@iZ0jl7nhcg5nazavryytxkZ ~]# yum install docker
Red Hat Enterprise Linux 8 for x86_64 - AppStream from RHUI (RPMs)                                                                                                                                            30 MB/s |  52 MB     00:01
Red Hat Enterprise Linux 8 for x86_64 - BaseOS from RHUI (RPMs)                                                                                                                                               32 MB/s |  56 MB     00:01
Last metadata expiration check: 0:00:08 ago on Sun 05 Feb 2023 11:36:21 PM CST.
Dependencies resolved.
=============================================================================================================================================================================================================================================
 Package                                        Architecture                         Version                                                                  Repository                                                                Size
=============================================================================================================================================================================================================================================
Installing:
 podman-docker                                  noarch                               3:4.2.0-6.module+el8.7.0+17498+a7f63b89                                  rhui-rhel-8-for-x86_64-appstream-rhui-rpms                                70 k
Upgrading:
 podman                                         x86_64                               3:4.2.0-6.module+el8.7.0+17498+a7f63b89                                  rhui-rhel-8-for-x86_64-appstream-rhui-rpms                                12 M
 podman-catatonit                               x86_64                               3:4.2.0-6.module+el8.7.0+17498+a7f63b89                                  rhui-rhel-8-for-x86_64-appstream-rhui-rpms                               357 k

Transaction Summary
=============================================================================================================================================================================================================================================
Install  1 Package
Upgrade  2 Packages

Total download size: 13 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): podman-catatonit-4.2.0-6.module+el8.7.0+17498+a7f63b89.x86_64.rpm                                                                                                                                     1.0 MB/s | 357 kB     00:00
(2/3): podman-docker-4.2.0-6.module+el8.7.0+17498+a7f63b89.noarch.rpm                                                                                                                                        187 kB/s |  70 kB     00:00
(3/3): podman-4.2.0-6.module+el8.7.0+17498+a7f63b89.x86_64.rpm                                                                                                                                                17 MB/s |  12 MB     00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                         15 MB/s |  13 MB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                                                     1/1
  Running scriptlet: podman-catatonit-3:4.2.0-6.module+el8.7.0+17498+a7f63b89.x86_64                                                                                                                                                     1/1
  Upgrading        : podman-catatonit-3:4.2.0-6.module+el8.7.0+17498+a7f63b89.x86_64                                                                                                                                                     1/5
  Upgrading        : podman-3:4.2.0-6.module+el8.7.0+17498+a7f63b89.x86_64                                                                                                                                                               2/5
  Installing       : podman-docker-3:4.2.0-6.module+el8.7.0+17498+a7f63b89.noarch                                                                                                                                                        3/5
  Cleanup          : podman-2:4.1.1-2.module+el8.6.0+15917+093ca6f8.x86_64                                                                                                                                                               4/5
  Cleanup          : podman-catatonit-2:4.1.1-2.module+el8.6.0+15917+093ca6f8.x86_64                                                                                                                                                     5/5
  Running scriptlet: podman-catatonit-2:4.1.1-2.module+el8.6.0+15917+093ca6f8.x86_64                                                                                                                                                     5/5
  Verifying        : podman-docker-3:4.2.0-6.module+el8.7.0+17498+a7f63b89.noarch                                                                                                                                                        1/5
  Verifying        : podman-3:4.2.0-6.module+el8.7.0+17498+a7f63b89.x86_64                                                                                                                                                               2/5
  Verifying        : podman-2:4.1.1-2.module+el8.6.0+15917+093ca6f8.x86_64                                                                                                                                                               3/5
  Verifying        : podman-catatonit-3:4.2.0-6.module+el8.7.0+17498+a7f63b89.x86_64                                                                                                                                                     4/5
  Verifying        : podman-catatonit-2:4.1.1-2.module+el8.6.0+15917+093ca6f8.x86_64                                                                                                                                                     5/5

Upgraded:
  podman-3:4.2.0-6.module+el8.7.0+17498+a7f63b89.x86_64                                                            podman-catatonit-3:4.2.0-6.module+el8.7.0+17498+a7f63b89.x86_64
Installed:
  podman-docker-3:4.2.0-6.module+el8.7.0+17498+a7f63b89.noarch

Complete!

执行主要的Docker命令。

[root@iZ0jl7nhcg5nazavryytxkZ ~]# docker version
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Client:       Podman Engine
Version:      4.2.0
API Version:  4.2.0
Go Version:   go1.18.4
Built:        Mon Dec 12 19:41:56 2022
OS/Arch:      linux/amd64

如果要删除Docker,则执行下面的命令

 [root@iZ0jl7nhcg5nazavryytxkZ ~]#  yum list installed | grep docker
podman-docker.noarch                          3:4.2.0-6.module+el8.7.0+17498+a7f63b89   @rhui-rhel-8-for-x86_64-appstream-rhui-rpms
[root@iZ0jl7nhcg5nazavryytxkZ ~]# sudo yum -y remove podman-docker.noarch
Dependencies resolved.
=============================================================================================================================================================================================================================================
 Package                                      Architecture                          Version                                                                 Repository                                                                  Size
=============================================================================================================================================================================================================================================
Removing:
 podman-docker                                noarch                                3:4.2.0-6.module+el8.7.0+17498+a7f63b89                                 @rhui-rhel-8-for-x86_64-appstream-rhui-rpms                                230

Transaction Summary
=============================================================================================================================================================================================================================================
Remove  1 Package

Freed space: 230
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                                                     1/1
  Erasing          : podman-docker-3:4.2.0-6.module+el8.7.0+17498+a7f63b89.noarch                                                                                                                                                        1/1
  Verifying        : podman-docker-3:4.2.0-6.module+el8.7.0+17498+a7f63b89.noarch                                                                                                                                                        1/1

Removed:
  podman-docker-3:4.2.0-6.module+el8.7.0+17498+a7f63b89.noarch

Complete!

如果要安装别的版本,比如,安装docker最新版本docker version 20.10.1;则参考《安装docker最新版本docker version 20.10.1》

nginx安装

 yum install nginx


启动nginx

 yum install nginx

查看nginx状态

 systemctl status nginx

参考文献

以上是关于DevOps之基本软件安装:在Redhat 8.x 上 安装NodeJS,PM2,Docker, Ngnix的主要内容,如果未能解决你的问题,请参考以下文章

centos 8.x系统配置chrony时间同步服务

centos 8.x系统配置chrony时间同步服务

DevOps利器之Docker入门篇

DevOps之主机

DevOps之Operate阶段工具Docker

Linux 之 软件安装-yumrpm源码安装