环境部署-基础设施

137 阅读3分钟

Node部署

下载Node

# https://registry.npmmirror.com/binary.html?path=node/v21.0.0/

cd /usr/local
sudo tar -xf ~/huo-l/node-v21.0.0-linux-x64.tar.xz --strip-components=1

验证

[root@openeuler2203sp4-x86 ~]# node -v
v21.0.0
[root@openeuler2203sp4-x86 ~]# npm -v
10.2.0

安装Docker

Docker Static Binaries

下载的版本是 docker-26.1.3.tgz

解压

tar -zxvf docker-26.1.3.tgz

安装

cp docker/* /usr/bin/

# 编辑配置文件
vim /etc/systemd/system/docker.service

添加内容

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
  
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock --selinux-enabled=false --default-ulimit nofile=65536:65536
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
  
[Install]
WantedBy=multi-user.target

添加文件可执行权限

chmod +x /etc/systemd/system/docker.service

重新加载 daemon 服务

systemctl daemon-reload

启动

systemctl start docker

验证

[root@openeuler2203sp4-x86 huo-l]# docker -v
Docker version 26.1.3, build b72abbb
[root@openeuler2203sp4-x86 huo-l]# docker info
Client:
 Version:    26.1.3
 Context:    default
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 26.1.3
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 926c9586fe4a6236699318391cd44976a98e31f1
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 5.10.0-216.0.0.115.oe2203sp4.x86_64
 Operating System: openEuler 22.03 (LTS-SP4)
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 7.26GiB
 Name: openeuler2203sp4-x86
 ID: 3bb04545-dc6e-4030-a147-1001a12c28fa
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine

配置私有仓储

[root@openeuler2203sp4-x86 docker]# more /etc/docker/daemon.json 
{
  "insecure-registries":
     ["10.170.33.110"],
   "exec-opts": ["native.cgroupdriver=systemd"],
   "log-driver": "json-file",
   "log-opts": {"max-size":"300m", "max-file":"3"}
}

重启docker

sudo service docker restart

Redis

拉取镜像

docker pull 10.170.33.110/redis/redis@sha256:3ab6458e5a80c5e20631f54ec8381bb16a8d346c557504dcdae1376e931a5b59

# 打标签
docker tag e35748fd6a72 10.170.33.110/redis/redis:latest

启动

docker run --name bp-redis -p 6379:6379 -d 10.170.33.110/redis/redis:latest

Mysql数据库

源文件

[root@openeuler2203sp4-x86 huo-l]# rpm -ivh mysql84-community-release-el8-1.noarch.rpm 
警告:mysql84-community-release-el8-1.noarch.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql84-community-release-el8-1  ################################# [100%]
   Warning: native mysql package from platform vendor seems to be enabled.
    Please consider to disable this before installing packages from repo.mysql.com.
    Run: yum module -y disable mysql
    
# 查看
[root@openeuler2203sp4-x86 yum.repos.d]# ls
mysql-community-debuginfo.repo  mysql-community.repo  mysql-community-source.repo  openEuler.repo

安装

[root@openeuler2203sp4-x86 yum.repos.d]# yum install -y mysql-server
MySQL 8.4 LTS Community Server                                                                 
Installed:
  mysql-community-client-8.4.5-1.el8.x86_64         mysql-community-client-plugins-8.4.5-1.el8.x86_64         mysql-community-common-8.4.5-1.el8.x86_64         mysql-community-icu-data-files-8.4.5-1.el8.x86_64        
  mysql-community-libs-8.4.5-1.el8.x86_64           mysql-community-server-8.4.5-1.el8.x86_64                
Complete!

重置密码

# 默认密码
sudo grep 'temporary password' /var/log/mysqld.log
2025-05-08T01:28:33.652086Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: syatZXhqC7+X

# 登录
[root@openeuler2203sp4-x86 yum.repos.d]# mysql -u root -p
Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.5

Copyright (c) 2000, 2025, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

# 修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '您的密码';

设置数据目录

# 停止服务
sudo systemctl stop mysqld

# 安装 rsync
yum install rsync

# 复制当前数据目录到/data
sudo rsync -av /var/lib/mysql /data/

# 更新配置文件 /etc/my.cnf
[mysqld]
datadir=/data/mysql

# 调整目录权限
sudo chown -R root:root /data/mysql

# 启动服务
systemctl start mysqld

# 验证
SHOW VARIABLES WHERE Variable_name = 'datadir';

访问

# 允许其他ip地址可以访问
UPDATE mysql.user SET host = '%' WHERE user = 'root';

# 刷新权限
FLUSH PRIVILEGES;

客户端访问

f9b4a890-994a-4efa-8cf0-b6b3c369a1e5.jpg

常用命令

sudo systemctl stop mysqld

systemctl start mysqld