大家好,我是满心

为何要写这篇文章,网上什么都能找到?
网上东西确实很多,但就是因为多,而且不全,容易花了眼,同时有一些教程不全,搭建过程中,容易出现问题,所以我归纳形成了这篇文章,配置的各类属性和参数根据自己实际情况有所删减

以下内容都是我躺坑过,并总结出来的内容,希望记录给自己使用的同时,也能帮助到大家

当然也可以使用第三方工具来配合使用,我目前比较喜欢的是portainer,可以去看我另一篇博文docker安装portainer,portainer基于的是docker-compose去拉取和构建镜像的,这里就不细说了

今天我们就按照docker命令的方式来操作

Docker环境

安装Docker

1、删docker历史版本

1
yum remove docker  docker-common docker-selinux docker-engine

2、安装docker需要的软件包

1
yum install -y yum-utils   device-mapper-persistent-data   lvm2

3、设置docker的yum源

1
yum-config-manager   --add-repo    https://download.docker.com/linux/centos/docker-ce.repo

4、安装DOCKER CE

1
yum install docker-ce

4、启动Docker

1
2
systemctl start docker
systemctl status docker

5、卸载

1
yum remove docker-ce

Docker安装Mysql

1、查找镜像

1
docker search mysql

2、下载镜像(默认拉取最新版本)(指定版本:docker pull java:5.7)

1
docker run -p 3306:3306  --name manxin-mysql -d --restart=always  -v /etc/my.cnf:/etc/my.cnf -v /root/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7

my.cnf需要自己创建,以下是我目前用的,仅供参考

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
  • 参数说明:

    1
    2
    3
    4
    -p 3306:3306:将容器的 3306 端口映射到主机的 3306 端口。
    -v /etc/my.cnf:/etc/my.cnf:将主机当前目录下的 /etc/my.cnf 挂载到容器的 /etc/my.cnf。
    -v /root/data:/var/lib/mysql :将主机当前目录下的data目录挂载到容器的 /var/lib/mysql 。
    -e MYSQL_ROOT_PASSWORD=root:初始化 root 用户的密码。
  • 如果navicat连接mysql出现

Client does not support authentication protocol requested by server

  • 那么继续往下走,如果能正常连接,一下步骤忽略

  • 进入容器

1
docker exec -it 62349aa31687 /bin/bash
  • 进入mysql
1
mysql -uroot -p
  • 授权
1
GRANT ALL ON *.* TO 'root'@'%';
  • 刷新权限
1
flush privileges;
  • 更新加密规则
1
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
  • 更新root用户密码
1
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
  • 刷新权限
1
flush privileges;

安装redis

1、查找镜像

1
docker search redis

2、下载镜像(默认拉取最新版本)(指定版本:docker pull redis)

1
docker run -p 6379:6379 --name manxin-redis -d --restart=always -v /etc/redis.conf:/etc/redis/redis.conf -v $PWD/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes --requirepass etoak

  • 参数说明
1
2
3
4
这里说一下与mysql不同地方
requirepass:设置密码
appendonly:持久化
也可在`redis.conf`初始化参数

安装Minio(文件服务)

1、拉取镜像

1
docker pull minio/minio

2、运行容器

1
2
3
4
5
6
7
8
docker run -p 9000:9000 --name minio \
-d --restart=always \
-e "MINIO_ACCESS_KEY=admin" \
-e "MINIO_SECRET_KEY=ohsminio" \
-v /home/data:/data \
-v /home/config:/root/.minio \
minio/minio server /data \
--console-address ":9000" --address ":9090"(新版本属性)

访问地址:ip:9000

安装nginx

1、查找镜像

1
docker search nginx

2、安装nginx

1
docker pull nginx

3、运行容器

1
docker run --name manxin-nginx -p 80:80 -v /etc/nginx/nginx.conf:/etc/nginx/nginx.conf -v /etc/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf -d nginx

JDK + MAVEN

1、下载安装包,上传至服务器
JDK下载地址
MAVEN下载地址
下载tar包即可

2、配置环境变量

1
vi /etc/profile

具体文件如下,结合实际自行修改

1
2
3
4
5
6
7
8
#--JDK--
export JAVA_HOME=/opt/jdk
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin

#--Maven--
export M2_HOME=/opt/maven
export PATH=$PATH:$M2_HOME/bin

3、配置生效

1
source /etc/profile

4、验证

1
2
mvn -v
java -version

其它软件安装,操作也差不多,后续有持续安装的,我也会持续分享

Docker-Compose

我这里就具体以portainer为例,我这里只分享docker-compose文件

Mysql

1
2
3
4
5
6
7
8
9
10
11
12
13
version: '2'
services:
mysql:
environment:
MYSQL_ROOT_PASSWORD: root
restart: always
container_name: mysql
image: mysql:5.7
ports:
- 3306:3306
volumes:
- /etc/my.cnf:/etc/my.cnf
command: --lower_case_table_names=1

Nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
version: '2'
services:
ohs-nginx:
image: nginx
container_name: qibin-nginx
ports:
- 80:80
volumes:
- /etc/nginx/nginx.conf:/etc/nginx/nginx.conf
- /etc/nginx/conf.d/:/usr/local/nginx/conf.d/:ro
environment:
- TZ=Asia/Shanghai
- LANG=zh_CN.UTF-8

Gitea(git私服)

自己的服务器配置不够,选用轻量级的git仓库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
version: "2"
networks:
gitea:
external: false
services:
server:
image: gitea/gitea:1.17.2
container_name: gitea
environment:
- USER_UID=1000
- USER_GID=1000
restart: always
networks:
- gitea
volumes:
- /data/gitea:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "222:22"

Gitlab

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
version: "2"
services:
gitlab:
image: gitlab/gitlab-ce:15.4.0-ce.0
container_name: gitlab
#restart: always
hostname: gitlab
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url "http://lovelu.top:9099"
gitlab_rails['gitlab_shell_ssh_port'] = 2222
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'manxin@lovelu.top'
gitlab_rails['gitlab_email_display_name'] = 'manxin'
gitlab_rails['gitlab_email_reply_to'] = 'manxin@lovelu.top'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "395893032@qq.com"
gitlab_rails['smtp_password'] = "manxin@email"
gitlab_rails['smtp_domain'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_openssl_verify_mode'] = 'peer'
gitlab_rails['smtp_tls'] = true
gitlab_rails['time_zone'] = 'Asia/Shanghai'
ports:
- '9099:9099'
- '2222:22'
volumes:
- '/www/gitlab/config:/etc/gitlab'
- '/www/gitlab/logs:/var/log/gitlab'
- '/www/gitlab/data:/var/opt/gitlab'
logging:
driver: "json-file"
options:
max-size: "20m"
max-file: "10"

php-admin

一款好用的内网映射数据库连接工具,不需要把数据库端口放到外网

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
version: '2'

services:
phpmyadmin:
#restart: always
image: phpmyadmin/phpmyadmin:5.2.0
container_name: phpmyadmin
hostname: phpmyadmin
ports:
- 8000:80
environment:
- PMA_HOSTS=192.168.2.200
- PMA_VERBOSES=typecho_dev
phpredisadmin:
#restart: always
image: erikdubbelboer/phpredisadmin:latest
container_name: phpredisadmin
ports:
- 8001:80
environment:
- REDIS_1_HOST=192.168.2.200
- REDIS_1_NAME=redis
- REDIS_1_PORT=6379
- REDIS_1_AUTH=root
- REDIS_2_HOST=192.168.2.185
- REDIS_2_NAME=SMARTMSP-REDIS
- REDIS_2_PORT=16379
- ADMIN_USER=admin
- ADMIN_PASS=root

Minio

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
version: '2'
services:
manxin-minio:
container_name: manxin-minio
image: minio/minio
command: server /data
ports:
- 9000:9000
volumes:
- /www/minio/data:/data
- /wwwminio/config:/root/.minio
environment:
- MINIO_DOMAIN=lovelu.top
- MINIO_ACCESS_KEY=admin
- MINIO_SECRET_KEY=123456

Cloudreve

一款免费的云盘工具

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
version: "2.2"
services:
cloudreve:
container_name: cloudreve
image: cloudreve/cloudreve:latest
restart: unless-stopped
ports:
- "5212:5212"
volumes:
- temp_data:/data
- /www/cloudreve/uploads:/cloudreve/uploads
- /www/cloudreve/conf.ini:/cloudreve/conf.ini
- /www/cloudreve/cloudreve.db:/cloudreve/cloudreve.db
- /www/cloudreve/avatar:/cloudreve/avatar
depends_on:
- aria2
aria2:
container_name: aria2
image: p3terx/aria2-pro
restart: unless-stopped
environment:
- RPC_SECRET=195829tt
- RPC_PORT=6800
volumes:
- /www/aria2/config:/config
- temp_data:/data
volumes:
temp_data:
driver: local
driver_opts:
type: none
device: $PWD/data
o: bind

CodeFever

一款免费的git私服

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
version: "2.2"
services:
codefever:
image: pgyer/codefever-community-lite:latest
ports:
- "8000:80"
- "23:22"
volumes:
- /www/codeFever/git-storage:/data/www/codefever-community/git-storage
- /www/codeFever/logs:/data/www/codefever-community/application/logs
environment:
DB_HOST: "103.215.80.206"
DB_PORT: "3306"
DB_USER: "root"
DB_PASS: "etoak" # Need to be the same as MYSQL_ROOT_PASSWORD
DB_NAME: "codefever_community"