# Docker方式

## 安装Redis

配置文件创建

```bash
mkdir ~/docker/docker_data/redis_master/ -p
vim  ~/docker/docker_data/redis_master/redis.conf
```

Redis配置文件

```properties
daemonize no
requirepass 123456
appendonly yes
tcp-keepalive 300
```

安装Redis镜像

```bash
docker run -p 6379:6379 --name redis_master \
-v ~/docker/docker_data/redis_master/redis.conf:/etc/redis/redis.conf \
-v ~/docker/docker_data/redis_master/data:/data \
--restart=always -d redis:7.0.10  --appendonly yes
```

## 安装Minio

```bash
docker run -d \
  -p 9000:9000 \
  -p 9090:9090 \
  --name minio_master --restart=always \
  -v ~/docker/docker_data/minio/data:/data \
  -e "MINIO_ROOT_USER=bunny" \
  -e "MINIO_ROOT_PASSWORD=02120212" \
  minio/minio server /data --console-address ":9090"
```

## 安装MySQL

```bash
# 创建3306配置文件
sudo mkdir -p ~/docker/docker_data/mysql/mysql_master/etc
sudo vim ~/docker/docker_data/mysql/mysql_master/etc/my.cnf
```

**my.cnf 配置**

```sql
[mysqld]
skip-host-cache
skip-name-resolve
secure-file-priv=/var/lib/mysql-files
user=mysql

# 设置字符集
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci

# 设置服务器ID（如果是复制集群，确保每个节点的ID唯一）
server-id=1

# 启用二进制日志
log-bin=mysql-bin

# 设置表名不区分大小写
lower_case_table_names = 1
```

**启动MySQL**

```bash
docker stop mysql_master
docker rm mysql_master

docker run --name mysql_master -p 3306:3306 \
-v  ~/docker/docker_data/mysql/mysql_master/etc/my.cnf:/etc/my.cnf \
-v  ~/docker/docker_data/mysql/mysql_master/data:/var/lib/mysql \
-v  ~/docker/docker_data/mysql/mysql_master/backup:/backup \
--restart=always --privileged=true \
   -e MYSQL_ROOT_PASSWORD=123456 \
   -e TZ=Asia/Shanghai \
   mysql:8.0.33 --lower-case-table-names=1
```

**修改密码**

```sql
# 进入容器
docker exec -it mysql /bin/bash

# 执行SQL命令
mysql -uroot -p123456
use mysql
ALTER USER 'root'@'%' IDENTIFIED BY "123456";
FLUSH PRIVILEGES;
```

## 安装PostgreSQL

```bash
docker run --name pg -e POSTGRES_PASSWORD=123456 -e POSTGRES_USER=postgres -p 5432:5432 -d postgres:latest
```

## 安装MSSQL

```shell
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=123456bunny." \
-p 1433:1433 --name mssql --hostname mssql \
-d --restart=always mcr.microsoft.com/mssql/server:2022-latest
```

设置大小写敏感：Chinese_PRC_CS_AI

设置忽略大小写： Chinese_PRC_CI_AI

## 安装MongoDB

### 创建数据库

```shell
docker stop mongodb
docker rm mongodb

docker run -it \
    --name mongodb \
    --restart=always \
    --privileged \
    -p 27017:27017 \
    -v ~/docker/docker_data/mongo/data:/data/db \
    -v ~/docker/docker_data/mongo/conf:/data/configdb \
    -v ~/docker/docker_data/mongo/logs:/data/log/  \
    -d mongo:latest \
    -f /data/configdb/mongod.conf
```

需要设置权限

```plain
mkdir -p ~/docker/docker_data/mongo/conf
mkdir -p ~/docker/docker_data/mongo/logs
chmod 777 ~/docker/docker_data/mongo/logs
chmod 777 ~/docker/docker_data/mongo/conf

cd ~/docker/docker_data/mongo/logs
touch mongod.log
chmod 777 mongod.log

cd ~/docker/docker_data/mongo/conf
vim mongod.conf
```

### 配置文件

```properties
# 数据库文件存储位置
dbpath = /data/db
# log文件存储位置
logpath = /data/log/mongod.log
# 使用追加的方式写日志
logappend = true
# 是否以守护进程方式运行
# fork = true
# 全部ip可以访问
bind_ip = 0.0.0.0
# 端口号
port = 27017
# 是否启用认证
auth = true
# 设置oplog的大小(MB)
oplogSize=2048
```

### 设置账户密码

```shell
#进入容器
docker exec -it mongodb /bin/bash

#进入mongodb shell
mongosh --port 27017

#切换到admin库
use admin

#创建账号/密码
db.createUser({ user: 'admin', pwd: '02120212', roles: [ { role: "root", db: "admin" } ] });
# db.createUser({ user: 'admin', pwd: '123456', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });
```

## 安装Nacos

安装完成后打开`IP地址:8848/nacos`

```bash
docker run -d -p 8848:8848 -p 9848:9848 -e MODE=standalone --name nacos nacos/nacos-server:v2.4.3
```

## 安装Sentinel

安装之后打开端口`IP地址:8858`

```bash
docker pull bladex/sentinel-dashboard:1.8.8
docker run --name sentinel \
-p 8858:8858 \
--privileged=true \
--restart=always \
-d bladex/sentinel-dashboard:1.8.8
```

## 安装Seata

设置的端口号为：8091

网页打开地址 ：IP地址:7091

```bash
docker pull apache/seata-server:2.3.0.jdk21
docker run -d \
-p 8091:8091 \
--name seata-server apache/seata-server:2.3.0.jdk21
```

## 安装rabbitmq

```shell
docker run -d --name rabbitmq_master --restart=always \
-p 5672:5672 -p 15672:15672   \
-v ~/docker/docker_data/rabbitmq_master/data:/var/lib/rabbitmq_master \
-v ~/docker/docker_data/rabbitmq_master/conf:/etc/rabbitmq_master \
-v ~/docker/docker_data/rabbitmq_master/log:/var/log/rabbitmq_master \
-v ~/docker/docker_data/rabbitmq_master/plugin:/plugins \
-e RABBITMQ_DEFAULT_VHOST=rabbitmq_master \
-e RABBITMQ_DEFAULT_USER=admin \
-e RABBITMQ_DEFAULT_PASS=admin rabbitmq:3.13.7-management
```

### 进入容器

```shell
docker stop rabbitmq_master
docker rm rabbitmq_master

docker logs rabbitmq_master

docker exec -it rabbitmq_master bash
rabbitmq-plugins enable rabbitmq_management
```

### 无法登录

```shell
#进入容器
docker exec -it 你的容器名或者id /bash

# 添加用户
rabbitmqctl add_user 用户名 密码

# 如果存在可以先删除
rabbitmqctl delete_user 用户名

#设置用户操作权限
rabbitmqctl set_user_tags 用户名 administrator
```

#### 添加

```shell
#进入容器
docker exec -it 你的容器名或者id /bin/bash

# 添加用户
rabbitmqctl add_user admin 123456
#设置用户操作权限
rabbitmqctl set_user_tags admin administrator
```

## 安装elasticsearch

### 创建网络

```shell
docker network create es-net
```

**如果有导入**

```bash
docker load -i es.tar
```

**运行容器**

```shell
docker run -d \
    --name elasticsearch \
    -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
    -e "discovery.type=single-node" \
    -v /bunny/docker/es/data:/usr/share/elasticsearch/data \
    -v /bunny/docker/es/plugins:/usr/share/elasticsearch/plugins \
    --privileged \
    --network es-net \
    -p 9200:9200 \
    -p 9300:9300 \
    --restart=always elasticsearch:7.12.1
```

## Harbor安装

### 下载Harbor

github下载地址：https://github.com/goharbor/harbor/releases

```bash
# 解压tgz包
tar -zxvf harbor-offline-installer-v2.10.1.tgz 
# 进入目录后进行复制配置文件
cd harbor/
# 创建一个配置文件
cp harbor.yml.tmpl harbor.yml    
# 修改配置文件
vim harbor.yml
```

![img](./images/1739538509456-6bc7fc32-81f3-440e-81ac-f43859ffe7dd.png)

![img](./images/1739538509454-1492954c-a231-4a35-8677-4e1951e2d829.png)

在我的当前版本中默认密码修改后无法访问，需要查看数据库密码

```bash
# 进入容器
docker exec -it harbor-core bash    
# 查看密码
printenv | grep PASSWORD
```

![img](./images/1739538509446-bc7c75b5-4f6c-4bdc-aa5d-df98623486e6.png)

### 安装Harbor

sh install.sh

启动相关命令这个启动方式需要在你的目录/harbor/下执行，我的当前目录是/root/harbor/所以需要在这个目录下启动，否则会报找不到指定文件等错误。

```bash
# 关闭 Harbor
docker compose -f docker-compose.yml stop

# 启动 Harbor
docker compose -f docker-compose.yml up -d
```

## 安装YApi

```bash
docker run -d --name mongo-yapi mongo:4.2

docker run -it --rm \
 --link mongo-yapi:mongo \
 --entrypoint npm \
 --workdir /api/vendors \
 registry.cn-hangzhou.aliyuncs.com/anoy/yapi \
 run install-server

# 方式二
docker run -d \
 --name yapi \
 --link mongo-yapi:mongo \
 --workdir /api/vendors \
 -p 3001:3000 \
 registry.cn-hangzhou.aliyuncs.com/anoy/yapi \
 server/app.js
log: mongodb load success...
初始化管理员账号成功,账号名："admin@admin.com"，密码："ymfe.org"
```

##  安装ChatGPT

```shell
docker pull yidadaa/chatgpt-next-web

docker run -d -p 4000:3000 --name chatgpt-next-web \
-e OPENAI_API_KEY="sk-Oe0WUg94fsex5aPVwnfkvl5Rh0Rl6jbrpSj8nNRTkN4tVwIA" \
-e BASE_URL=https://api.chatanywhere.com.cn yidadaa/chatgpt-next-web

# 开启启动
docker update --restart=always chatgpt-next-web
```

## 安装Gitea

**docker配置文件**

```yaml
version: "3"

networks:
  gitea:
    external: false

services:
  server:
    image: gitea/gitea:1.21.3
    container_name: gitea
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - GITEA__database__DB_TYPE=mysql
      - GITEA__database__HOST=192.168.3.98:3305
      - GITEA__database__NAME=gitea
      - GITEA__database__USER=gitea
      - GITEA__database__PASSWD=gitea
    restart: always
    networks:
      - gitea
    volumes:
      - ./bunny/docker_data/gitea:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "3000:3000"
      - "222:22"
    depends_on:
      - db

  db:
    container_name: mysql_gitea
    image: mysql:8
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=gitea
      - MYSQL_USER=gitea
      - MYSQL_PASSWORD=gitea
      - MYSQL_DATABASE=gitea
    volumes:
      - /bunny/docker_data/mysql_gitea:/var/lib/mysql
    ports:
      - "3305:3306"
```

**执行命令**

```shell
docker stop gitea
docker rm gitea

docker stop a6861d426b53
docker rm a6861d426b53

docker-compose up -d
docker logs gitea
```

**进入容器**

```shell
docker exec -it local_db_1 bash
mysql -ugitea -pgitea
USE gitea;
ALTER USER 'gitea'@'%' IDENTIFIED BY "gitea";
GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'%';
FLUSH PRIVILEGES;

mysql -uroot -pgitea
```

**开启防火墙**

```shell
firewall-cmd --zone=public --add-port=4000/tcp --permanent
```

## 安装git

**要确保git的版本大于**`2.0.0`**否则后面无法完成安装！！！**

这里使用的`wget`的方式下载，之后解压后安装

https://mirrors.edge.kernel.org/pub/software/scm/git/

**安装编译环境**

```shell
yum install curl-devel expat-devel gettext-devel \
  openssl-devel zlib-devel
```

**执行命令**

```shell
make prefix=/usr/local/git all
sudo make prefix=/usr/local/git install
```

**开机启动**

```shell
docker update --restart=always 76bad48de9c7
docker update --restart=always adea530fd5cd
```

## 安装Jenkins

```shell
docker run -u root -d --name myjenkins \
-p 8040:8080 -p 50000:50000 \
-v /data/jenkins_home:/var/jenkins_home \
--restart=always jenkinsci/blueocean
```

访问http://192.168.3.98:8040/

### 查看密码

```shell
cat /var/jenkins_home/secrets/initialAdminPassword
00a1fcf9b2d444ac821b5e57ea157293
```

### default.json所在目录

```shell
/var/jenkins_home/updates/default.json
```

### 进入目录

```shell
cd /var/jenkins_home/updates/
```

### 替换节点信息

```shell
sed -i 's/www.google.com/www.baidu.com/g' default.json
sed -i 's/updates.jenkins-ci.org\/download/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json
```

### 重启 Jenkins

```shell
docker restart myjenkins
```

## 部署kibana

```shell
docker run -d \
--name kibana \
-e ELASTICSEARCH_HOSTS=http://es:9200 \
--network=es-net \
-p 5601:5601  \
kibana:7.12.1
```

验证：http://192.168.3.98:5601/app/home#/

### 重启es

```shell
docker restart es
```

### 设置屏蔽词和扩展词

```shell
docker restart es
```

配置文件

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
    <comment>IK Analyzer 扩展配置</comment>
    <!--用户可以在这里配置自己的扩展字典 -->
    <entry key="ext_dict">extra.dic</entry>
     <!--用户可以在这里配置自己的扩展停止词字典-->
    <entry key="ext_stopwords">stopword.dic</entry>
    <!--用户可以在这里配置远程扩展字典 -->
    <!-- <entry key="remote_ext_dict">words_location</entry> -->
    <!--用户可以在这里配置远程扩展停止词字典-->
    <!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>
```

