Wsl 安装中间件

本人电脑配置 R9000X 48G运存!

本文章记录使用,有兴趣的可以看看,不做整理了。

涉及中间件:MySQL / Redis / Minio / Nacos / Seata / Sentinel / ZipKin

WSL 安装 CentOS8

https://github.com/CentOS/sig-cloud-instance-images/blob/CentOS-8-x86_64/docker/centos-8-x86_64.tar.xz

安装开源的 WSL 专用的镜像包

安装 chocolatey 和 LxRunOffline

管理员身份运行 PowerShell

> Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

> choco upgrade lxrunoffline
安装成功提示:
 The install of lxrunoffline was successful.
  Software installed to 'C:\tools\lxrunoffline'
正常情况下,环境变量会自动配置,不过可手动查看下
配置环境变量:Path = C:\tools\lxrunoffline

> LxRunOffline install -n CentOS8 -d D:/WSL/CentOS8 -f D:\WSL\CentOS8\centos-8-x86_64.tar.xz
解释:
-n CentOS8 >> 命名
-d D:/WSL/CentOS8 >> WSL 使用,需要反斜杠
-f D:\WSL\CentOS8\centos-8-x86_64.tar.xz >> LxRunOffline 使用,Windows 路径

choco 指令:
choco -v 查看 choco 版本
choco list -li 查看本地安装的软件
choco search nodejs 查找安装包
choco install sublimetext3 下载
choco uninstall sublimetext3 卸载
choco upgrade sublimetext3 更新升级(update)
choco upgrade chocolatey 更新升级 chocolatey 自己

查看 WSL 列表
> wsl -l -v
设置 CentOS8 为 WSL2
> wsl --set-version CentOS8 2
设置默认子系统
> wslconfig /setdefault CentOS8

进入 WSL 基础设置

我的镜像无法使用 yum 及 dnf 下载,出现了无法获得镜像URL,解决:
# sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
# sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
# yum makecache
# yum update -y
安装 安装 wget vim 等工具
# cd ~ 
# dnf -y install vim nano wget curl git make unzip
# dnf -y install net-tools #启用 ifconfig, netstat 等网络命令
# dnf -y install initscripts #启用 service 命令
解决 systemctl 命令不可用
官网的方法!!!
# cd /
# nano /etc/wsl.conf

输入内容:
[boot]
systemd=true

退出 Nano 文本编辑器(Ctrl + X,选择 Y 来保存更改)
然后退出子系统 # exit
关闭 WSL > wsl --shutdown

建议参考下列指令,备份此子系统!

查看当前安装的发行版
> wsl -l -v
关闭 WSL
> wsl --shutdown
导出
> wsl --export CentOS8 D:\WSL\CentOS8\CentOS8_20240222.tar
注销
> wsl --unregister CentOS8
导入
> wsl --import CentOS8 D:\WSL\CentOS8 D:\WSL\CentOS8\CentOS8_20240222.tar
进入系统
> wsl

由于开启了 systemd,导致一旦关闭命令行,WSL 就会在几分钟后自动关闭,无法后台运行

Win + R 输入 shell:startup
在目录中创建 wsl-startup.vbs
输入内容:

set ws=wscript.CreateObject("wscript.shell")
ws.run "wsl -d CentOS8", vbhide
保存!
新建文件C:\Users\<UserName>\.wslconfig
输入内容:
[wsl2]
memory=16GB 
processors=8
保存!

一、安装 MySQL

CentOS 7.x 安装 MySQL8.0

二、安装 Redis

Yum 安装 Redis,发现找不到包!!!

# wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# rpm -ivh epel-release-latest-7.noarch.rpm
# yum repolist
CentOS 7.x 安装 Redis

安装 NVM

# wget https://github.com/nvm-sh/nvm/archive/refs/tags/v0.39.1.tar.gz
# mkdir -p /root/.nvm
# tar -zxvf v0.39.1.tar.gz -C /root/.nvm
# cd /root/.nvm/nvm-0.39.1
# sh install.sh
如果一直卡在下载,可以试试执行如下指令更新
# yum update -y nss curl
安装完成后刷新环境变量
# source ~/.bashrc
安装
# nvm install v18.16.0
# npm install -g yarn
安装 Yarn 卡住了,解决
# npm cache clean --force
# npm config set registry https://registry.npmmirror.com
# npm config get registry

安装 Python 3.7

依赖安装!!!

# dnf -y install gcc
# dnf -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel

报错:Error: Unable to find a match: db4-devel libpcap-devel

# dnf -y install dnf-plugins-core
# dnf upgrade
# dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
# dnf config-manager --set-enabled powertools
# dnf -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel

报错:Error: Unable to find a match: db4-devel

可去以下网站下载libdb4-4.8.30-30.el8.x86_64.rpm和libdb4-devel-4.8.30-30.el8.x86_64.rpm:
https://centos.pkgs.org/8/raven-x86_64/libdb4-4.8.30-30.el8.x86_64.rpm.html
https://centos.pkgs.org/8/raven-x86_64/libdb4-devel-4.8.30-30.el8.x86_64.rpm.html

# rpm -ivh libdb4-4.8.30-30.el8.x86_64.rpm libdb4-devel-4.8.30-30.el8.x86_64.rpm
# dnf -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel

Python 安装!!!
官网 :https://www.python.org/downloads/source/
Python 3.7.8 - June 27, 2020
Download Gzipped source tarball
复制该链接也许,下载后放到 WSL 文件系统也许!

# wget https://www.python.org/ftp/python/3.7.8/Python-3.7.8.tgz
# tar -zxvf Python-3.7.8.tgz
# mkdir /data/python3
# cd Python-3.7.8
# ./configure --prefix=/data/python3
# make && make install

Installing collected packages: setuptools, pip
  WARNING: The script easy_install-3.7 is installed in '/data/python3/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts pip3 and pip3.7 are installed in '/data/python3/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

# ln -s /data/python3/bin/python3.7 /usr/bin/python3
# ln -s /data/python3/bin/pip3.7 /usr/bin/pip3

安装 RedisInsight

https://github.com/RedisInsight/RedisInsight/releases

https://github.com/RedisInsight/RedisInsight/wiki/How-to-build-and-contribute

# wget https://github.com/RedisInsight/RedisInsight/archive/refs/tags/2.40.0.zip
# unzip 2.40.0.zip
# cd RedisInsight-2.40.0
# yarn install && yarn --cwd redisinsight/api/

开启 Api
# yarn --cwd redisinsight/api/ start:dev
访问 http://localhost:5000/api/docs 成功

开启 Gui
# yarn start:web
访问 http://localhost:8080/ 成功,注意实现,这里可能访问时要等个 1 分钟左右

修改 Gui 默认的 8080 端口
# vim ./configs/webpack.config.web.dev.ts

entry: [
    'regenerator-runtime/runtime',
            `webpack-dev-server/client?http://${HOST}:8085`,
            'webpack/hot/only-dev-server',
            require.resolve('../redisinsight/ui/index.tsx'),
          ],

devServer: {
    host: HOST,
    allowedHosts: 'all',
    port: 8085,
    historyApiFallback: true,
},

两处地方更改后保存!

# yarn start:web
启动后访问,更改成功!

三、安装 Minio

# mkdir minio
# cd minio
# wget http://dl.minio.org.cn/server/minio/release/linux-amd64/minio
# chmod +x minio
# wget https:// dl.minio.org.cn/client/mc/release/linux-amd64/mc
# chmod +x mc

# cd /etc/systemd/system/
# touch minio.service
# vim minio.service
[Unit]
Description=Minio Service
After=network.target

[Service]
Environment="MINIO_ROOT_USER=admin"
Environment="MINIO_ROOT_PASSWORD=12345678"
ExecStart=/data/minio/minio server /data/minio/data --address ":9000" --console-address ":9095"
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
StandardOutput=/data/minio/logs/minio.log
PrivateTmp=true

[Install]
WantedBy=multi-user.target
# systemctl start minio.service
# chkconfig minio on

四、安装 Nacos 与 Seate

安装 JDK

# yum -y remove tzdata-java.noarch
# yum -y remove javapackages-tools.noarch

无法使用 OpenJDK,下载 Oracle Java8 [jdk-8u401-linux-x64.rpm]
# rpm -ivh jdk-8u401-linux-x64.rpm

# vim /etc/profile

export JAVA_HOME=/usr/lib/jvm/jdk-1.8-oracle-x64/
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin

export PATH=$PATH:${JAVA_PATH}

# source /etc/profile && source ~/.bashrc

安装 Maven

不明缘由,发现就算在 Linux 配置了 Maven,使用执行 mvn 还是访问的 Windows 物理机的,很是奇怪。

最后 /etc/profile 配置时,放到最前面!!!

官网安装 .zip 包,解压配置 settings.xml 与 环境变量

# wget https://dlcdn.apache.org/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.zip
# unzip apache-maven-3.9.6-bin.zip -c /data/maven
# vim /data/maven/conf/settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">

  <localRepository>D:\MavenData</localRepository>
  <pluginGroups></pluginGroups>
  <proxies></proxies>
  <servers></servers>
  <mirrors>
    <!-- 阿里云仓库 -->
    <mirror>
      <id>alimaven</id>
      <mirrorOf>central</mirrorOf>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
    </mirror>
    <!-- 中央仓库1 -->
    <mirror>
      <id>repo1</id>
      <mirrorOf>central</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://repo1.maven.org/maven2/</url>
    </mirror>
    <!-- 中央仓库2 -->
    <mirror>
      <id>repo2</id>
      <mirrorOf>central</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://repo2.maven.org/maven2/</url>
    </mirror>
  </mirrors>
  <profiles>
	<profile>     
		<id>JDK-1.8</id>       
		<activation>       
			<activeByDefault>true</activeByDefault>       
			<jdk>1.8</jdk>       
		</activation>       
		<properties>       
			<maven.compiler.source>1.8</maven.compiler.source>       
			<maven.compiler.target>1.8</maven.compiler.target>       
			<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>       
		</properties>       
	</profile>
  </profiles>
</settings>
# vim /etc/profile
export PATH=/data/maven/bin:$PATH:${JAVA_PATH}

# source /etc/profile && source ~/.bashrc

安装 Nacos

# git clone https://github.com/alibaba/nacos.git
# cd nacos/
# mvn -Prelease-nacos -Dmaven.test.skip=true clean install -U  
# ls -al distribution/target/
# mv distribution/target/nacos-server-2.3.1-SNAPSHOT/nacos /data/

# vim conf/application.properties

spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://localhost:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
db.user.0=root
db.password.0=123456

另外注意:执行文件 startup.sh 与 shutdown.sh 需要设置编码,vim 后 :set ff=unix 与 :wq!

# cd /etc/systemd/system/
# touch nacos.service
# vim nacos.service
[Unit]
Description=Nacos Service
After=network.target mysqld.service
 
[Service]
Type=forking
ExecStart=/data/nacos/bin/startup.sh -m standalone
ExecReload=/data/nacos/bin/shutdown.sh
ExecStop=/data/nacos/bin/shutdown.sh
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
# systemctl start nacos.service
# chkconfig nacos on

重大问题:Idea 配置 Nacos -> localhost:8848 无法访问!但是浏览器却可以访问到。

这里经过查找资料后,找到一种比较完美的处理方法!安装 Nginx 通过转发来处理。

安装教程在下面,我这里为了方便浏览,先把解决方案写这里:

配置 nginx.conf,这里我只放片段,就是 http {} 内的配置。

http {
	 upstream cluster{       
	 server localhost:8848 weight=1;
	 }   
	 server {        
		listen       8888;        
		server_name  localhost;        
		 
	 location / {            
	 proxy_pass http://cluster;        
	 }        
		 
	 location = /50x.html {            
		root   html;        
	 }        
}

配置 Idea 项目的 application.yml 地址端口为 localhost:8888
同时,你会申请的发现,浏览器用 127.0.0.1:8888 也能访问了!!!

安装 Nginx

# wget http://nginx.org/download/nginx-1.16.0.tar.gz
# yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
# tar -xzvf nginx-1.16.0.tar.gz
# mv nginx-1.16.0 /usr/local
# cd /usr/local/nginx-1.16.0
# ./configure
# make
# make install
# rm -rf /usr/local/nginx-1.16.0

# cd /etc/systemd/system/
# touch nginx.service
# vim nginx.service
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target
# systemctl start nginx.service
# chkconfig nginx on

安装 Seate

# wget https://github.com/apache/incubator-seata/releases/download/v2.0.0/seata-server-2.0.0.zip
# unzip seata-server-2.0.0.zip
# cd seata
# vim conf/application.yml
将 127.0.0.1 改成 localhost

seata:
  config:
    # support: nacos, consul, apollo, zk, etcd3
    type: nacos
    nacos:
      server-addr: localhost:8848
      group : SEATA_GROUP # 具体看 Nacos Web
      namespace: 068d89da-ab40-423f-b26d-f9fd14126033 # 具体看 Nacos Web
      # username: nacos
      # password: nacos
      data-id: seata-server.properties # 具体看 Nacos Web
  registry:
    # support: nacos, eureka, redis, zk, consul, etcd3, sofa
    type: nacos
    nacos:
      application: seata-server
      serverAddr: localhost:8848
      group: SEATA_GROUP # 具体看 Nacos Web
      namespace: 068d89da-ab40-423f-b26d-f9fd14126033 # 具体看 Nacos Web
      cluster: default
      # username: nacos
      # password: nacos
  #store:
  #  # support: file 、 db 、 redis 、 raft
  #  mode: file
  #  server:
  #    service-port: 8091 #If not configured, the default is '${server.port} + 1000'
# cd /etc/systemd/system/
# touch seata.service
# vim seata.service
[Unit]
Description=Seata Service
After=network.target mysqld.service nacos.service

[Service]
Type=forking
ExecStart=/data/seata/bin/seata-server.sh start
ExecReload=/data/seata/bin/seata-server.sh restart
ExecStop=/data/seata/bin/seata-server.sh stop
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
# systemctl start seata.service
# chkconfig seata on

安装 Sentinel

下载 sentinel-dashboard-1.8.6.jar

# vim sentinel.sh
#!/bin/bash
# chkconfig: 2345 10 90
# description:auto_run

RUN_NAME="sentinel-dashboard-1.8.6.jar"
JAVA_OPTS=/data/sentinel/sentinel-dashboard-1.8.6.jar

LOG_DIR=/data/sentinel/logs/csp
LOG_FILE=$LOG_DIR/sentinel-dashboard.log
LOG_OPTS=/data/sentinel/sentinel_temp.log

start() {
        nohup java -Xms256M -Xmx512M -XX:PermSize=128M -XX:MaxPermSize=256M -Dcsp.sentinel.log.dir=$LOG_DIR -Dlogging.file=$LOG_FILE -Dserver.port=8858 -Dcsp.sentinel.dashboard.server=127.0.0.1:8858 -Dproject.name=Sentinel-Controller -Dsentinel.dashboard.auth.username=sentinel -Dsentinel.dashboard.auth.password=123456 -jar $JAVA_OPTS >$LOG_OPTS 2>&1 &
        echo "$RUN_NAME started success."
}

stop() {
        echo "stopping $RUN_NAME ..."
        kill -9 `ps -ef|grep $JAVA_OPTS|grep -v grep|grep -v stop|awk '{print $2}'`
}

case "$1" in
        start)
            start
            ;;
        stop)
            stop
            ;;
        restart)
            stop
            start
            ;;
        *)
        echo "Userage: $0 {start|stop|restart}"
        exit 1
esac
# chmod +x sentinel.sh
# cd /etc/systemd/system/
# touch sentinel.service
# vim sentinel.service
[Unit]
Description=Sentinel Service
After=network.target
 
[Service]
Type=forking
ExecStart=/data/sentinel/sentinel.sh start
ExecReload=/data/sentinel/sentinel.sh restart
ExecStop=/data/sentinel/sentinel.sh stop
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
# systemctl start sentinel.service
# chkconfig sentinel on

安装 ZipKin

下载 zipkin-server-2.24.3-exec.jar

# vim zipkin.sh
#!/bin/bash
# chkconfig: 2345 10 90
# description:auto_run

RUN_NAME="zipkin-server-2.24.3-exec.jar"
JAVA_OPTS=/data/zipkin/zipkin-server-2.24.3-exec.jar

LOG_OPTS=/data/zipkin/zipkin_temp.log

start() {
        nohup java -Xms256M -Xmx512M -XX:PermSize=128M -XX:MaxPermSize=256M -jar $JAVA_OPTS --STORAGE_TYPE=mysql --MYSQL_HOST=localhost --MYSQL_TCP_PORT=3306 --MYSQL_DB=zipkin --MYSQL_USER=root --MYSQL_PASS=123456 >$LOG_OPTS 2>&1 &
        echo "$RUN_NAME started success."
}

stop() {
        echo "stopping $RUN_NAME ..."
        kill -9 `ps -ef|grep $JAVA_OPTS|grep -v grep|grep -v stop|awk '{print $2}'`
}

case "$1" in
        start)
            start
            ;;
        stop)
            stop
            ;;
        restart)
            stop
            start
            ;;
        *)
        echo "Userage: $0 {start|stop|restart}"
        exit 1
esac
# chmod +x zipkin.sh
# cd /etc/systemd/system/
# touch zipkin.service
# vim zipkin.service
[Unit]
Description=Zipkin Service
After=network.target mysqld.service
 
[Service]
Type=forking
ExecStart=/data/zipkin/zipkin.sh start
ExecReload=/data/zipkin/zipkin.sh restart
ExecStop=/data/zipkin/zipkin.sh stop
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
# systemctl start zipkin.service
# chkconfig zipkin on
  • 打赏
请选择打赏方式
  • 微信
  • 支付宝

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注

滚动至顶部