❤️Linux环境下的部署(基于Docker容器)

小明的学习圈子2024-03-25环境

一、Docker环境安装

参照地址open in new window

二、MySQL安装

1、下载MySQL5.7的docker镜像

docker pull mysql:5.7

2、使用如下命令启动MySQL服务

docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=stucoding  \
-d mysql:5.7
  • 参数说明

-p 3306:3306:将容器的3306端口映射到主机的3306端口

-v /mydata/mysql/conf:/etc/mysql:将配置文件夹挂在到主机

-v /mydata/mysql/log:/var/log/mysql:将日志文件夹挂载到主机

-v /mydata/mysql/data:/var/lib/mysql/:将数据文件夹挂载到主机

-e MYSQL_ROOT_PASSWORD=stucoding:初始化root用户的密码

3、查看mysql日志

这里docker安装mysql报错了


[root@linux-local ~]# docker logs -f mysql
2024-04-01 13:22:38+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
2024-04-01 13:22:38+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
        command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.InMJZRaXCR
        mysqld: Can't read dir of '/etc/mysql/conf.d/' (Errcode: 2 - No such file or directory)
mysqld: [ERROR] Fatal error in defaults handling. Program aborted!

4、重新安装

  • 首先删除mydata下的mysql文件夹(如果不存在不用管)

[root@linux-local ~]# cd /mydata
[root@linux-local mydata]# ll
total 0
drwx--x---. 12 root root 185 Apr  1 20:02 docker
drwxr-xr-x.  5 root root  41 Apr  1 21:22 mysql
[root@linux-local mydata]# rm mysql/ -rf
[root@linux-local mydata]# ll
total 0
drwx--x---. 12 root root 185 Apr  1 20:02 docker
[root@linux-local mydata]#

  • 其次删除刚才安装的mysql容器
docker rm mysql
  • 运行容器
docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=stucoding  \
-d mysql:5.7
  • 再次查看log

[root@linux-local mydata]# docker logs -f mysql
2024-04-01 13:37:42+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
2024-04-01 13:37:43+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2024-04-01 13:37:43+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
2024-04-01 13:37:43+00:00 [Note] [Entrypoint]: Initializing database files
2024-04-01T13:37:43.202624Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-04-01T13:37:43.572647Z 0 [Warning] InnoDB: New log files created, LSN=45790
2024-04-01T13:37:43.749861Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2024-04-01T13:37:43.845728Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 04b87953-f02d-11ee-97cb-0242ac110002.
2024-04-01T13:37:43.849064Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2024-04-01T13:37:44.152513Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2024-04-01T13:37:44.152524Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2024-04-01T13:37:44.153474Z 0 [Warning] CA certificate ca.pem is self signed.
2024-04-01T13:37:44.308699Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2024-04-01 13:37:49+00:00 [Note] [Entrypoint]: Database files initialized
2024-04-01 13:37:49+00:00 [Note] [Entrypoint]: Starting temporary server
2024-04-01 13:37:49+00:00 [Note] [Entrypoint]: Waiting for server startup
2024-04-01T13:37:49.656877Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-04-01T13:37:49.658981Z 0 [Note] mysqld (mysqld 5.7.44) starting as process 123 ...
2024-04-01T13:37:49.662739Z 0 [Note] InnoDB: PUNCH HOLE support available
2024-04-01T13:37:49.662761Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2024-04-01T13:37:49.662764Z 0 [Note] InnoDB: Uses event mutexes
2024-04-01T13:37:49.662769Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2024-04-01T13:37:49.662771Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.13
2024-04-01T13:37:49.662773Z 0 [Note] InnoDB: Using Linux native AIO
2024-04-01T13:37:49.662956Z 0 [Note] InnoDB: Number of pools: 1
2024-04-01T13:37:49.663250Z 0 [Note] InnoDB: Using CPU crc32 instructions
2024-04-01T13:37:49.664871Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2024-04-01T13:37:49.671487Z 0 [Note] InnoDB: Completed initialization of buffer pool
2024-04-01T13:37:49.673362Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2024-04-01T13:37:49.684811Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2024-04-01T13:37:49.694450Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2024-04-01T13:37:49.694689Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2024-04-01T13:37:49.730994Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2024-04-01T13:37:49.731529Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2024-04-01T13:37:49.731535Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2024-04-01T13:37:49.732154Z 0 [Note] InnoDB: Waiting for purge to start
2024-04-01T13:37:49.782467Z 0 [Note] InnoDB: 5.7.44 started; log sequence number 2768291
2024-04-01T13:37:49.782788Z 0 [Note] Plugin 'FEDERATED' is disabled.
2024-04-01T13:37:49.787670Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2024-04-01T13:37:49.787679Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2024-04-01T13:37:49.787682Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2024-04-01T13:37:49.787683Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2024-04-01T13:37:49.788137Z 0 [Warning] CA certificate ca.pem is self signed.
2024-04-01T13:37:49.788169Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2024-04-01T13:37:49.788664Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2024-04-01T13:37:49.789848Z 0 [Note] InnoDB: Buffer pool(s) load completed at 240401 13:37:49
2024-04-01T13:37:49.793576Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2024-04-01T13:37:49.802585Z 0 [Note] Event Scheduler: Loaded 0 events
2024-04-01T13:37:49.802720Z 0 [Note] mysqld: ready for connections.
Version: '5.7.44'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server (GPL)
2024-04-01 13:37:50+00:00 [Note] [Entrypoint]: Temporary server started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2024-04-01T13:37:50.559364Z 3 [Note] InnoDB: Stopping purge
2024-04-01T13:37:50.574173Z 3 [Note] InnoDB: Resuming purge
2024-04-01T13:37:50.578728Z 3 [Note] InnoDB: Stopping purge
2024-04-01T13:37:50.585860Z 3 [Note] InnoDB: Resuming purge
2024-04-01T13:37:50.589234Z 3 [Note] InnoDB: Stopping purge
2024-04-01T13:37:50.595855Z 3 [Note] InnoDB: Resuming purge
2024-04-01T13:37:50.599381Z 3 [Note] InnoDB: Stopping purge
2024-04-01T13:37:50.607209Z 3 [Note] InnoDB: Resuming purge
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.

2024-04-01 13:37:52+00:00 [Note] [Entrypoint]: Stopping temporary server
2024-04-01T13:37:52.879665Z 0 [Note] Giving 0 client threads a chance to die gracefully
2024-04-01T13:37:52.879679Z 0 [Note] Shutting down slave threads
2024-04-01T13:37:52.879684Z 0 [Note] Forcefully disconnecting 0 remaining clients
2024-04-01T13:37:52.879688Z 0 [Note] Event Scheduler: Purging the queue. 0 events
2024-04-01T13:37:52.880194Z 0 [Note] Binlog end
2024-04-01T13:37:52.880889Z 0 [Note] Shutting down plugin 'ngram'
2024-04-01T13:37:52.880896Z 0 [Note] Shutting down plugin 'partition'
2024-04-01T13:37:52.880899Z 0 [Note] Shutting down plugin 'BLACKHOLE'
2024-04-01T13:37:52.880901Z 0 [Note] Shutting down plugin 'ARCHIVE'
2024-04-01T13:37:52.880903Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2024-04-01T13:37:52.880924Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
2024-04-01T13:37:52.880926Z 0 [Note] Shutting down plugin 'MyISAM'
2024-04-01T13:37:52.880931Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
2024-04-01T13:37:52.880933Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
2024-04-01T13:37:52.880935Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
2024-04-01T13:37:52.880937Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
2024-04-01T13:37:52.880939Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
2024-04-01T13:37:52.880941Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
2024-04-01T13:37:52.880942Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
2024-04-01T13:37:52.880944Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
2024-04-01T13:37:52.880946Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
2024-04-01T13:37:52.880947Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
2024-04-01T13:37:52.880949Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
2024-04-01T13:37:52.880951Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
2024-04-01T13:37:52.880952Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
2024-04-01T13:37:52.880954Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
2024-04-01T13:37:52.880955Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
2024-04-01T13:37:52.880957Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
2024-04-01T13:37:52.880959Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
2024-04-01T13:37:52.880961Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
2024-04-01T13:37:52.880962Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
2024-04-01T13:37:52.880964Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
2024-04-01T13:37:52.881084Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
2024-04-01T13:37:52.881086Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
2024-04-01T13:37:52.881088Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
2024-04-01T13:37:52.881090Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
2024-04-01T13:37:52.881091Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
2024-04-01T13:37:52.881093Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
2024-04-01T13:37:52.881095Z 0 [Note] Shutting down plugin 'INNODB_CMP'
2024-04-01T13:37:52.881097Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
2024-04-01T13:37:52.881098Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
2024-04-01T13:37:52.881100Z 0 [Note] Shutting down plugin 'INNODB_TRX'
2024-04-01T13:37:52.881102Z 0 [Note] Shutting down plugin 'InnoDB'
2024-04-01T13:37:52.881136Z 0 [Note] InnoDB: FTS optimize thread exiting.
2024-04-01T13:37:52.882371Z 0 [Note] InnoDB: Starting shutdown...
2024-04-01T13:37:52.983343Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2024-04-01T13:37:52.983542Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 240401 13:37:52
2024-04-01T13:37:56.509449Z 0 [Note] InnoDB: Shutdown completed; log sequence number 12219419
2024-04-01T13:37:56.510687Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2024-04-01T13:37:56.510700Z 0 [Note] Shutting down plugin 'MEMORY'
2024-04-01T13:37:56.510707Z 0 [Note] Shutting down plugin 'CSV'
2024-04-01T13:37:56.510710Z 0 [Note] Shutting down plugin 'sha256_password'
2024-04-01T13:37:56.510711Z 0 [Note] Shutting down plugin 'mysql_native_password'
2024-04-01T13:37:56.510793Z 0 [Note] Shutting down plugin 'binlog'
2024-04-01T13:37:56.511229Z 0 [Note] mysqld: Shutdown complete

2024-04-01 13:37:56+00:00 [Note] [Entrypoint]: Temporary server stopped

2024-04-01 13:37:56+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.

2024-04-01T13:37:57.051273Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-04-01T13:37:57.052056Z 0 [Note] mysqld (mysqld 5.7.44) starting as process 1 ...
2024-04-01T13:37:57.055345Z 0 [Note] InnoDB: PUNCH HOLE support available
2024-04-01T13:37:57.055366Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2024-04-01T13:37:57.055370Z 0 [Note] InnoDB: Uses event mutexes
2024-04-01T13:37:57.055372Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2024-04-01T13:37:57.055375Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.13
2024-04-01T13:37:57.055378Z 0 [Note] InnoDB: Using Linux native AIO
2024-04-01T13:37:57.055638Z 0 [Note] InnoDB: Number of pools: 1
2024-04-01T13:37:57.055993Z 0 [Note] InnoDB: Using CPU crc32 instructions
2024-04-01T13:37:57.057382Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2024-04-01T13:37:57.063153Z 0 [Note] InnoDB: Completed initialization of buffer pool
2024-04-01T13:37:57.066012Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2024-04-01T13:37:57.077977Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2024-04-01T13:37:57.130171Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2024-04-01T13:37:57.130237Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2024-04-01T13:37:57.153995Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2024-04-01T13:37:57.154777Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2024-04-01T13:37:57.154784Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2024-04-01T13:37:57.155085Z 0 [Note] InnoDB: Waiting for purge to start
2024-04-01T13:37:57.205337Z 0 [Note] InnoDB: 5.7.44 started; log sequence number 12219419
2024-04-01T13:37:57.205601Z 0 [Note] Plugin 'FEDERATED' is disabled.
2024-04-01T13:37:57.210763Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2024-04-01T13:37:57.210774Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2024-04-01T13:37:57.210777Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2024-04-01T13:37:57.210779Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2024-04-01T13:37:57.211365Z 0 [Warning] CA certificate ca.pem is self signed.
2024-04-01T13:37:57.211398Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2024-04-01T13:37:57.211620Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2024-04-01T13:37:57.212089Z 0 [Note] IPv6 is available.
2024-04-01T13:37:57.212100Z 0 [Note]   - '::' resolves to '::';
2024-04-01T13:37:57.212122Z 0 [Note] Server socket created on IP: '::'.
2024-04-01T13:37:57.212877Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2024-04-01T13:37:57.214556Z 0 [Note] InnoDB: Buffer pool(s) load completed at 240401 13:37:57
2024-04-01T13:37:57.219816Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2024-04-01T13:37:57.228820Z 0 [Note] Event Scheduler: Loaded 0 events
2024-04-01T13:37:57.228937Z 0 [Note] mysqld: ready for connections.
Version: '5.7.44'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)


  • 将容器内的配置文件拷贝到指定目录
docker container cp mysql:/etc/mysql /mydata/mysql/conf
  • 具体步骤

[root@linux-local mydata]# docker container cp mysql:/etc/mysql /mydata/mysql/conf
Successfully copied 2.56kB to /mydata/mysql/conf
[root@linux-local mydata]# ^C
[root@linux-local mydata]# cd /mydata/mysql/conf/
[root@linux-local conf]# ll
total 0
drwxr-xr-x. 2 root root 6 Dec 15 07:51 conf.d
drwxr-xr-x. 2 root root 6 Dec 15 07:51 mysql.conf.d

  • 然后再停止和删除mysql

[root@linux-local mydata]# cd /mydata/mysql/conf/
[root@linux-local conf]# ll
total 0
drwxr-xr-x. 2 root root 6 Dec 15 07:51 conf.d
drwxr-xr-x. 2 root root 6 Dec 15 07:51 mysql.conf.d
[root@linux-local conf]# ^C
[root@linux-local conf]# docker stop mysql
mysql
[root@linux-local conf]# dorker rm mysql
bash: dorker: command not found...
[root@linux-local conf]# docker rm mysql
mysql
[root@linux-local conf]#

  • 最后再执行,然后
docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=stucoding  \
-d mysql:5.7
  • 然后再运行log

[root@linux-local conf]# docker run -p 3306:3306 --name mysql \
> -v /mydata/mysql/log:/var/log/mysql \
> -v /mydata/mysql/data:/var/lib/mysql \
> -v /mydata/mysql/conf:/etc/mysql \
> -e MYSQL_ROOT_PASSWORD=stucoding  \
> -d mysql:5.7
7b180e4e04c0e4a7db89e122dff2daa653eb8f2398f923c9529ca59435e7a8fc
[root@linux-local conf]# docker logs -f mysql
2024-04-01 13:47:26+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
2024-04-01 13:47:26+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2024-04-01 13:47:26+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
'/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
2024-04-01T13:47:27.233641Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2024-04-01T13:47:27.234532Z 0 [Note] mysqld (mysqld 5.7.44) starting as process 1 ...
2024-04-01T13:47:27.237099Z 0 [Note] InnoDB: PUNCH HOLE support available
2024-04-01T13:47:27.237116Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2024-04-01T13:47:27.237119Z 0 [Note] InnoDB: Uses event mutexes
2024-04-01T13:47:27.237121Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2024-04-01T13:47:27.237124Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.13
2024-04-01T13:47:27.237126Z 0 [Note] InnoDB: Using Linux native AIO
2024-04-01T13:47:27.237300Z 0 [Note] InnoDB: Number of pools: 1
2024-04-01T13:47:27.237408Z 0 [Note] InnoDB: Using CPU crc32 instructions
2024-04-01T13:47:27.238587Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2024-04-01T13:47:27.244139Z 0 [Note] InnoDB: Completed initialization of buffer pool
2024-04-01T13:47:27.245670Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2024-04-01T13:47:27.256834Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2024-04-01T13:47:27.302951Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2024-04-01T13:47:27.303015Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2024-04-01T13:47:27.323074Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2024-04-01T13:47:27.323627Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2024-04-01T13:47:27.323633Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2024-04-01T13:47:27.324106Z 0 [Note] InnoDB: Waiting for purge to start
2024-04-01T13:47:27.374706Z 0 [Note] InnoDB: 5.7.44 started; log sequence number 12219447
2024-04-01T13:47:27.374927Z 0 [Note] Plugin 'FEDERATED' is disabled.
2024-04-01T13:47:27.378879Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2024-04-01T13:47:27.378887Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2024-04-01T13:47:27.378890Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2024-04-01T13:47:27.378891Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2024-04-01T13:47:27.379327Z 0 [Warning] CA certificate ca.pem is self signed.
2024-04-01T13:47:27.379358Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2024-04-01T13:47:27.379690Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2024-04-01T13:47:27.380040Z 0 [Note] IPv6 is available.
2024-04-01T13:47:27.380049Z 0 [Note]   - '::' resolves to '::';
2024-04-01T13:47:27.380070Z 0 [Note] Server socket created on IP: '::'.
2024-04-01T13:47:27.380978Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2024-04-01T13:47:27.381965Z 0 [Note] InnoDB: Buffer pool(s) load completed at 240401 13:47:27
2024-04-01T13:47:27.385326Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2024-04-01T13:47:27.393232Z 0 [Note] Event Scheduler: Loaded 0 events
2024-04-01T13:47:27.393534Z 0 [Note] mysqld: ready for connections.
Version: '5.7.44'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)

5、进入运行MySQL的docker容器:

docker exec -it mysql /bin/bash

6、使用MySQL命令打开客户端

mysql -uroot -pstucoding --default-character-set=utf8

7、创建数据库

create database stucoding character set utf8

[root@linux-local conf]# docker exec -it mysql /bin/bash
bash-4.2# mysql -uroot -pstucoding --default-character-set=utf8
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, 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.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database stucoding character set utf8
    -> create database stucoding character set utf8;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'create database stucoding character set utf8' at line 2
mysql> create database stucoding character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql>

8、安装上传下载插件

  • 并将stucoding.sql上传到Linux的服务器mydata目录下
  • 退出mysql后再下载插件
yum -y install lrzsz

mysql> create database stucoding character set utf8
    -> create database stucoding character set utf8;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'create database stucoding character set utf8' at line 2
mysql> create database stucoding character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> ^C
mysql> exit
Bye
bash-4.2# exit
exit
[root@linux-local conf]# yum -y install lrzsz
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
Package lrzsz-0.12.20-36.el7.x86_64 already installed and latest version
Nothing to do
[root@linux-local conf]#

[root@linux-local conf]# cd /mydata
[root@linux-local mydata]# ll
total 0
drwx--x---. 12 root root 185 Apr  1 20:02 docker
drwxr-xr-x.  5 root root  41 Apr  1 21:43 mysql
[root@linux-local mydata]# ll
total 8
drwx--x---. 12 root root  185 Apr  1 20:02 docker
drwxr-xr-x.  5 root root   41 Apr  1 21:43 mysql
-rw-r--r--.  1 root root 4231 Apr  1 21:59 stucoding.sql

9、将stucoding.sql文件拷贝到mysql容器的/目录下

docker cp /mydata/stucoding.sql mysql:/

10、在mysql里将sql文件导入到数据库(注意是mysql容器里)

use stucoding;
source /stucoding.sql;
ot@linux-local mydata]# docker cp /mydata/stucoding.sql mysql:/
Successfully copied 6.14kB to mysql:/
[root@linux-local mydata]# docker exec -it mysql /bin/bash
bash-4.2# mysql -uroot -pstucoding --default-character-set=utf8
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, 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.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use stucoding;
Database changed
mysql> source /stucoding.sql;
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

Database changed
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.03 sec)

Query OK, 6 rows affected (0.01 sec)
Records: 6  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.04 sec)

Query OK, 6 rows affected (0.00 sec)
Records: 6  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.04 sec)

Query OK, 13 rows affected (0.00 sec)
Records: 13  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.04 sec)

Query OK, 8 rows affected (0.01 sec)
Records: 8  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.03 sec)

Query OK, 4 rows affected (0.00 sec)
Records: 4  Duplicates: 0  Warnings: 0

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql>

创建一个reader:stucoding帐号并修改权限,使得任何ip都能访问:

grant all privileges on *.* to 'reader' @'%' identified by 'stucoding';

mysql> grant all privileges on *.* to 'reader' @'%' identified by 'stucoding';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql>

最后再刷新下权限

flush privileges;

mysql> grant all privileges on *.* to 'reader' @'%' identified by 'stucoding';
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> ^C
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

三、Redis安装

  • 下载Redis7的docker镜像:
docker pull redis:7
  • 使用如下命令启动Redis服务:
docker run -p 6379:6379 --name redis \
-v /mydata/redis/data:/data \
-d redis:7 redis-server --appendonly yes
  • 进入Redis容器使用redis-cli命令进行连接:
docker exec -it redis redis-cli

[root@linux-local mydata]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
redis        7         170a1e90f843   2 months ago   138MB
mysql        5.7       5107333e08a8   3 months ago   501MB
[root@linux-local mydata]# docker run -p 6379:6379 --name redis \
> -v /mydata/redis/data:/data \
> -d redis:7 redis-server --appendonly yes
3a6c18413fa4a1656e449367b4dfe1cc77567e6b6b46a3ed63fcf554d09046f0
[root@linux-local mydata]# docker logs -f nginx
Error response from daemon: No such container: nginx
[root@linux-local mydata]# docker exec -it redis redis-cli
127.0.0.1:6379> set a 100
OK
127.0.0.1:6379> get a
"100"
127.0.0.1:6379> exit
[root@linux-local mydata]# docker ps
CONTAINER ID   IMAGE       COMMAND                  CREATED             STATUS             PORTS                                                  NAMES
3a6c18413fa4   redis:7     "docker-entrypoint.s…"   53 seconds ago      Up 52 seconds      0.0.0.0:6379->6379/tcp, :::6379->6379/tcp              redis
7b180e4e04c0   mysql:5.7   "docker-entrypoint.s…"   About an hour ago   Up About an hour   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
[root@linux-local mydata]#

四、Nginx安装

  • 下载Nginx1.22的docker镜像:
docker pull nginx:1.22
  • 先运行一次容器(为了拷贝配置文件):
docker run -p 80:80 --name nginx \
-v /mydata/nginx/html:/usr/share/nginx/html \
-v /mydata/nginx/logs:/var/log/nginx  \
-d nginx:1.22
  • 将容器内的配置文件拷贝到指定目录:
docker container cp nginx:/etc/nginx /mydata/nginx/
  • 修改文件名称:
mv nginx conf

image-20240404115225888


[root@linux-local ~]# cd /mydata/nginx/
[root@linux-local nginx]# ll
total 0
drwxr-xr-x. 2 root root   6 Apr  4 11:49 html
drwxr-xr-x. 2 root root  41 Apr  4 11:49 logs
drwxr-xr-x. 3 root root 132 Mar 29  2023 nginx
[root@linux-local nginx]# mv nginx conf
[root@linux-local nginx]# cd /mydata/nginx/
[root@linux-local nginx]# ll
total 0
drwxr-xr-x. 3 root root 132 Mar 29  2023 conf
drwxr-xr-x. 2 root root   6 Apr  4 11:49 html
drwxr-xr-x. 2 root root  41 Apr  4 11:49 logs
[root@linux-local nginx]#

  • 终止并删除容器:
docker stop nginx
docker rm nginx
  • 使用如下命令启动Nginx服务:
docker run -p 80:80 --name nginx \
-v /mydata/nginx/html:/usr/share/nginx/html \
-v /mydata/nginx/logs:/var/log/nginx  \
-v /mydata/nginx/conf:/etc/nginx \
-d nginx:1.22

五、RabbitMQ安装

  • 下载rabbitmq3.9.11-management的docker镜像:
docker pull rabbitmq:3.9.11-management
  • 使用如下命令启动RabbitMQ服务:
docker run -p 5672:5672 -p 15672:15672 --name rabbitmq \
-v /mydata/rabbitmq/data:/var/lib/rabbitmq \
-d rabbitmq:3.9.11-management
  • 开启防火墙:
firewall-cmd --zone=public --add-port=15672/tcp --permanent
firewall-cmd --reload
  • 访问地址查看是否安装成功:http://192.168.1.71:15672/

  • 输入账号密码并登录:guest guest image-20240403203528599

  • 创建帐号并设置其角色为管理员:mall stucoding

image-20240403204509260

  • 创建一个新的虚拟host为:/mall

image-20240403204646919

  • 点击mall用户进入用户配置页面

image-20240403204801250

  • 给mall用户配置该虚拟host的权限

image-20240403204902505

六、Elasticsearch安装

  • 下载Elasticsearch7.17.3的docker镜像:
docker pull elasticsearch:7.17.3
  • 修改虚拟内存区域大小,否则会因为过小而无法启动:
sysctl -w vm.max_map_count=262144

[root@linux-local ~]# yum-config-manager \
>     --add-repo \
>     http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@linux-local ~]# yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.tuna.tsinghua.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
docker-ce-stable                                                                                                 | 3.5 kB  00:00:00
Package 3:docker-ce-26.0.0-1.el7.x86_64 already installed and latest version
Package 1:docker-ce-cli-26.0.0-1.el7.x86_64 already installed and latest version
Package containerd.io-1.6.28-3.2.el7.x86_64 already installed and latest version
Nothing to do
[root@linux-local ~]# docker version
Client: Docker Engine - Community
 Version:           26.0.0
 API version:       1.45
 Go version:        go1.21.8
 Git commit:        2ae903e
 Built:             Wed Mar 20 15:21:09 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          26.0.0
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.8
  Git commit:       8b79278
  Built:            Wed Mar 20 15:20:06 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[root@linux-local ~]#
[root@linux-local ~]# vim /etc/docker/daemon.json
[root@linux-local ~]# cat  /etc/docker/daemon.json
{
  "registry-mirrors": ["https://mr63yffu.mirror.aliyuncs.com"]
}
[root@linux-local ~]# systemctl daemon-reload
[root@linux-local ~]# systemctl restart docker
[root@linux-local ~]# docker pull elasticsearch:7.17.3
7.17.3: Pulling from library/elasticsearch
e0b25ef51634: Pull complete
0ed156f90b4d: Pull complete
0b3c161c8ebd: Pull complete
157de9ee3c7a: Pull complete
eea187b8272b: Pull complete
a04594f99bf2: Pull complete
c88cab9df767: Pull complete
b95579404185: Pull complete
3da4afe05b7a: Pull complete
Digest: sha256:5e6ac15bf6a57c42fa702a647c13749b1249c89e59be8f654f61a3feade9dc47
Status: Downloaded newer image for elasticsearch:7.17.3
docker.io/library/elasticsearch:7.17.3
[root@linux-local ~]# docker images
REPOSITORY      TAG                 IMAGE ID       CREATED         SIZE
redis           7                   170a1e90f843   2 months ago    138MB
mysql           5.7                 5107333e08a8   3 months ago    501MB
nginx           1.22                0f8498f13f3a   12 months ago   142MB
elasticsearch   7.17.3              3c91aa69ae06   23 months ago   613MB
rabbitmq        3.9.11-management   6c3c2a225947   2 years ago     253MB
[root@linux-local ~]# sysctl -w vm.max_map_count=262144
vm.max_map_count = 262144
[root@linux-local ~]#
  • 使用如下命令启动Elasticsearch服务,内存小的服务器可以通过ES_JAVA_OPTS来设置占用内存大小:
docker run -p 9200:9200 -p 9300:9300 --name elasticsearch \
-e "discovery.type=single-node" \
-e "cluster.name=elasticsearch" \
-e "ES_JAVA_OPTS=-Xms512m -Xmx1024m" \
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
-d elasticsearch:7.17.3
  • 启动时会发现/usr/share/elasticsearch/data目录没有访问权限,只需要修改/mydata/elasticsearch/data目录的权限,再重新启动即可;
chmod 777 /mydata/elasticsearch/data/
docker start elasticsearch
  • docker logs -f elasticsearch命令查看安装信息

[root@linux-local ~]# docker run -p 9200:9200 -p 9300:9300 --name elasticsearch \
> -e "discovery.type=single-node" \
> -e "cluster.name=elasticsearch" \
> -e "ES_JAVA_OPTS=-Xms512m -Xmx1024m" \
> -v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
> -v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
> -d elasticsearch:7.17.3
2f30042929c7d4b8185e76faba7b2ba8e6519dc9d282751f9a975373e858f1a6
[root@linux-local ~]# docker logs -f elasticsearch
{"type": "server", "timestamp": "2024-04-05T01:21:54,515Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "version[7.17.3], pid[7], build[default/docker/5ad023604c8d7416c9eb6c0eadb62b14e766caff/2022-04-19T08:11:19.070913226Z], OS[Linux/3.10.0-1160.el7.x86_64/amd64], JVM[Eclipse Adoptium/OpenJDK 64-Bit Server VM/18/18+36]" }
{"type": "server", "timestamp": "2024-04-05T01:21:54,524Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "JVM home [/usr/share/elasticsearch/jdk], using bundled JDK [true]" }
{"type": "server", "timestamp": "2024-04-05T01:21:54,525Z", "level": "INFO", "component": "o.e.n.Node", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "JVM arguments [-Xshare:auto, -Des.networkaddress.cache.ttl=60, -Des.networkaddress.cache.negative.ttl=10, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -XX:+ShowCodeDetailsInExceptionMessages, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dio.netty.allocator.numDirectArenas=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j2.formatMsgNoLookups=true, -Djava.locale.providers=SPI,COMPAT, --add-opens=java.base/java.io=ALL-UNNAMED, -Djava.security.manager=allow, -XX:+UseG1GC, -Djava.io.tmpdir=/tmp/elasticsearch-10124468993157386465, -XX:+HeapDumpOnOutOfMemoryError, -XX:+ExitOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m, -Des.cgroups.hierarchy.override=/, -Xms512m, -Xmx1024m, -XX:MaxDirectMemorySize=536870912, -XX:G1HeapRegionSize=4m, -XX:InitiatingHeapOccupancyPercent=30, -XX:G1ReservePercent=15, -Des.path.home=/usr/share/elasticsearch, -Des.path.conf=/usr/share/elasticsearch/config, -Des.distribution.flavor=default, -Des.distribution.type=docker, -Des.bundled_jdk=true]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,928Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [aggs-matrix-stats]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,928Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [analysis-common]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,928Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [constant-keyword]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,928Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [frozen-indices]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,929Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [ingest-common]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,929Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [ingest-geoip]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,929Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [ingest-user-agent]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,929Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [kibana]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,929Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [lang-expression]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,929Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [lang-mustache]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,957Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [lang-painless]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,957Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [legacy-geo]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,957Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [mapper-extras]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,957Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [mapper-version]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,957Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [parent-join]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,957Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [percolator]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,958Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [rank-eval]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,958Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [reindex]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,958Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [repositories-metering-api]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,958Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [repository-encrypted]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,958Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [repository-url]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,958Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [runtime-fields-common]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,958Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [search-business-rules]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,958Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [searchable-snapshots]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,958Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [snapshot-repo-test-kit]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,959Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [spatial]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,959Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [transform]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,959Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [transport-netty4]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,959Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [unsigned-long]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,959Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [vector-tile]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,959Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [vectors]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,959Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [wildcard]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,959Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-aggregate-metric]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,959Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-analytics]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,960Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-async]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,960Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-async-search]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,960Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-autoscaling]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,960Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-ccr]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,960Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-core]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,960Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-data-streams]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,960Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-deprecation]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,960Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-enrich]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,960Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-eql]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,961Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-fleet]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,961Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-graph]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,961Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-identity-provider]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,961Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-ilm]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,961Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-logstash]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,961Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-ml]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,961Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-monitoring]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,961Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-ql]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,961Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-rollup]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,962Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-security]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,962Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-shutdown]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,962Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-sql]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,962Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-stack]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,962Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-text-structure]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,962Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-voting-only-node]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,962Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "loaded module [x-pack-watcher]" }
{"type": "server", "timestamp": "2024-04-05T01:21:57,974Z", "level": "INFO", "component": "o.e.p.PluginsService", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "no plugins loaded" }
{"type": "server", "timestamp": "2024-04-05T01:21:58,109Z", "level": "ERROR", "component": "o.e.b.ElasticsearchUncaughtExceptionHandler", "cluster.name": "elasticsearch", "node.name": "2f30042929c7", "message": "uncaught exception in thread [main]",
"stacktrace": ["org.elasticsearch.bootstrap.StartupException: ElasticsearchException[failed to bind service]; nested: AccessDeniedException[/usr/share/elasticsearch/data/nodes];",
"at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:157) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:77) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:112) ~[elasticsearch-cli-7.17.3.jar:7.17.3]",
"at org.elasticsearch.cli.Command.main(Command.java:77) ~[elasticsearch-cli-7.17.3.jar:7.17.3]",
"at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:122) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:80) ~[elasticsearch-7.17.3.jar:7.17.3]",
"Caused by: org.elasticsearch.ElasticsearchException: failed to bind service",
"at org.elasticsearch.node.Node.<init>(Node.java:1093) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.node.Node.<init>(Node.java:309) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:234) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:234) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:434) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:166) ~[elasticsearch-7.17.3.jar:7.17.3]",
"... 6 more",
"Caused by: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes",
"at sun.nio.fs.UnixException.translateToIOException(UnixException.java:90) ~[?:?]",
"at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106) ~[?:?]",
"at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111) ~[?:?]",
"at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:397) ~[?:?]",
"at java.nio.file.Files.createDirectory(Files.java:700) ~[?:?]",
"at java.nio.file.Files.createAndCheckIsDirectory(Files.java:807) ~[?:?]",
"at java.nio.file.Files.createDirectories(Files.java:793) ~[?:?]",
"at org.elasticsearch.env.NodeEnvironment.lambda$new$0(NodeEnvironment.java:300) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.env.NodeEnvironment$NodeLock.<init>(NodeEnvironment.java:224) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:298) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.node.Node.<init>(Node.java:429) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.node.Node.<init>(Node.java:309) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:234) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:234) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:434) ~[elasticsearch-7.17.3.jar:7.17.3]",
"at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:166) ~[elasticsearch-7.17.3.jar:7.17.3]",
"... 6 more"] }
uncaught exception in thread [main]
ElasticsearchException[failed to bind service]; nested: AccessDeniedException[/usr/share/elasticsearch/data/nodes];
Likely root cause: java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes
        at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
        at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
        at java.base/sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:397)
        at java.base/java.nio.file.Files.createDirectory(Files.java:700)
        at java.base/java.nio.file.Files.createAndCheckIsDirectory(Files.java:807)
        at java.base/java.nio.file.Files.createDirectories(Files.java:793)
        at org.elasticsearch.env.NodeEnvironment.lambda$new$0(NodeEnvironment.java:300)
        at org.elasticsearch.env.NodeEnvironment$NodeLock.<init>(NodeEnvironment.java:224)
        at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:298)
        at org.elasticsearch.node.Node.<init>(Node.java:429)
        at org.elasticsearch.node.Node.<init>(Node.java:309)
        at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:234)
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:234)
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:434)
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:166)
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:157)
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:77)
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:112)
        at org.elasticsearch.cli.Command.main(Command.java:77)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:122)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:80)
For complete error details, refer to the log at /usr/share/elasticsearch/logs/elasticsearch.log
[root@linux-local ~]#

  • 安装中文分词器IKAnalyzer,注意下载与Elasticsearch对应的版本,下载地址:https://github.com/medcl/elasticsearch-analysis-ik/releases

image-20240405095725419

  • 下载完成后,将文件重命名为analysis-ik,并压缩成analysis-ik.tar.gz格式,解压到Elasticsearch的/mydata/elasticsearch/plugins目录下,然后删除压缩文件;

[root@linux-local plugins]# tar zxvf analysis-ik.tar.gz
analysis-ik/
analysis-ik/commons-codec-1.9.jar
analysis-ik/commons-logging-1.2.jar
analysis-ik/config/
analysis-ik/config/extra_main.dic
analysis-ik/config/extra_single_word.dic
analysis-ik/config/extra_single_word_full.dic
analysis-ik/config/extra_single_word_low_freq.dic
analysis-ik/config/extra_stopword.dic
analysis-ik/config/IKAnalyzer.cfg.xml
analysis-ik/config/main.dic
analysis-ik/config/preposition.dic
analysis-ik/config/quantifier.dic
analysis-ik/config/stopword.dic
analysis-ik/config/suffix.dic
analysis-ik/config/surname.dic
analysis-ik/elasticsearch-analysis-ik-7.17.3.jar
analysis-ik/httpclient-4.5.2.jar
analysis-ik/httpcore-4.4.4.jar
analysis-ik/plugin-descriptor.properties
analysis-ik/plugin-security.policy
[root@linux-local plugins]# ll
total 4192
drwxrwxrwx. 3 root root     244 Apr  5 09:36 analysis-ik
-rw-r--r--. 1 root root 4290140 Apr  5 10:07 analysis-ik.tar.gz
[root@linux-local plugins]# rm analysis-ik.tar.gz
rm: remove regular file ‘analysis-ik.tar.gz’?
[root@linux-local plugins]# ll
total 4192
drwxrwxrwx. 3 root root     244 Apr  5 09:36 analysis-ik
-rw-r--r--. 1 root root 4290140 Apr  5 10:07 analysis-ik.tar.gz

[root@linux-local plugins]# rm analysis-ik.tar.gz
rm: remove regular file ‘analysis-ik.tar.gz’? y
[root@linux-local plugins]# ll
total 0
drwxrwxrwx. 3 root root 244 Apr  5 09:36 analysis-ik
[root@linux-local plugins]# cd analysis-ik
[root@linux-local analysis-ik]# ll
total 1432
-rwxrwxrwx. 1 root root 263965 Jan 18  2022 commons-codec-1.9.jar
-rwxrwxrwx. 1 root root  61829 Jan 18  2022 commons-logging-1.2.jar
drwxrwxrwx. 2 root root   4096 Jan 18  2022 config
-rwxrwxrwx. 1 root root  54931 Apr 27  2022 elasticsearch-analysis-ik-7.17.3.jar
-rwxrwxrwx. 1 root root 736658 Jan 18  2022 httpclient-4.5.2.jar
-rwxrwxrwx. 1 root root 326724 Jan 18  2022 httpcore-4.4.4.jar
-rwxrwxrwx. 1 root root   1807 Apr 27  2022 plugin-descriptor.properties
-rwxrwxrwx. 1 root root    125 Apr 27  2022 plugin-security.policy
[root@linux-local analysis-ik]#

  • 重新启动服务:
docker restart elasticsearch
  • 开启防火墙:
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload
  • 访问会返回版本信息:http://192.168.1.71:9200
{
  "name": "708f1d885c16",
  "cluster_name": "elasticsearch",
  "cluster_uuid": "mza51wT-QvaZ5R0NmE183g",
  "version": {
    "number": "7.17.3",
    "build_flavor": "default",
    "build_type": "docker",
    "build_hash": "5ad023604c8d7416c9eb6c0eadb62b14e766caff",
    "build_date": "2022-04-19T08:11:19.070913226Z",
    "build_snapshot": false,
    "lucene_version": "8.11.1",
    "minimum_wire_compatibility_version": "6.8.0",
    "minimum_index_compatibility_version": "6.0.0-beta1"
  },
  "tagline": "You Know, for Search"
}

七、Logstash安装

  • 下载Logstash7.17.3的docker镜像:
docker pull logstash:7.17.3
  • 修改Logstash的配置文件logstash.confoutput节点下的Elasticsearch连接地址为es:9200,配置文件地址:https://github.com/macrozheng/mall/blob/teach/document/elk/logstash.conf
output {
  elasticsearch {
    hosts => "es:9200"
    index => "mall-%{type}-%{+YYYY.MM.dd}"
  }
}
  • 创建/mydata/logstash目录,并将Logstash的配置文件logstash.conf拷贝到该目录;
mkdir /mydata/logstash
  • 使用如下命令启动Logstash服务;
docker run --name logstash -p 4560:4560 -p 4561:4561 -p 4562:4562 -p 4563:4563 \
--link elasticsearch:es \
-v /mydata/logstash/logstash.conf:/usr/share/logstash/pipeline/logstash.conf \
-d logstash:7.17.3
  • 旧版需要进入容器内部,安装json_lines插件,新版本已自带,无需安装。
logstash-plugin install logstash-codec-json_lines

八、Kibana安装

  • 下载Kibana7.17.3的docker镜像:
docker pull kibana:7.17.3
  • 使用如下命令启动Kibana服务:
docker run --name kibana -p 5601:5601 \
--link elasticsearch:es \
-e "elasticsearch.hosts=http://es:9200" \
-d kibana:7.17.3
  • 开启防火墙:
firewall-cmd --zone=public --add-port=5601/tcp --permanent
firewall-cmd --reload
  • 访问地址进行测试:http://192.168.3.101:5601

九、MongoDB安装

  • 下载MongoDB4的docker镜像:
docker pull mongo:4
  • 使用docker命令启动:
docker run -p 27017:27017 --name mongo \
-v /mydata/mongo/db:/data/db \
-d mongo:4

十、MinIO安装

  • 下载MinIO的Docker镜像;
docker pull minio/minio
  • 下载完成后使用如下命令运行MinIO服务,注意使用--console-address指定MinIO Console的运行端口(否则会随机端口运行):
docker run -p 9090:9000 -p 9001:9001 --name minio \
-v /mydata/minio/data:/data \
-e MINIO_ROOT_USER=minioadmin \
-e MINIO_ROOT_PASSWORD=minioadmin \
-d minio/minio server /data --console-address ":9001"
  • 运行成功后就可访问MinIO Console的管理界面了,输入账号密码minioadmin:minioadmin即可登录,访问地址:http://192.168.3.101:9001

十一、nacos安装(最新版)

前言

  • 安装之前你需要准备一个mysql,当前安装方式是将数据持久化到数据库中的,这里的部署是单机模式

1、Docker 拉取镜像

docker pull nacos/nacos-server
  • PS:这是拉取最新的nacos版本,如果需要拉取别的版本可以加:版本号(如:docker pull nacos/nacos-server:v2.2.0)

2、挂载目录

mkdir -p /mydata/nacos/logs/                      #新建logs目录
mkdir -p /mydata/nacos/conf/						#新建conf目录
  • PS:这一步是添加映射文件夹,将宿主机的文件映射到nacos容器中

3、启动nacos并复制文件到宿主机,关闭容器

4、启动容器

docker run -p 8848:8848 --name nacos -d nacos/nacos-server

5、复制文件

docker cp nacos:/home/nacos/logs/ /mydata/nacos/
docker cp nacos:/home/nacos/conf/ /mydata/nacos/

6、关闭容器

docker rm -f nacos
  • PS:这一步启动nacos是为了将nacos里面的文件拷贝出到挂载目录中,这样我们就可以直接修改挂载目录中文件来映射到容器里面去了

7、mysql中创建nacos所需的表

  • mysql中新建一个库,名字可自定义,这里就用nacos-config
  • githubopen in new window中找到创建表的文件,在nacos-config库中执行,创建所需的表

8、再次启动nacos

docker run -d
--name nacos															 
-p 8848:8848  -p 9848:9848 -p 9849:9849
--privileged=true
-e JVM_XMS=256m
-e JVM_XMX=256m
-e MODE=standalone
-v /mydata/nacos/logs/:/home/nacos/logs
-v /mydata/nacos/conf/:/home/nacos/conf/
--restart=always
nacos/nacos-server

  • PS : 复制上面的语句执行失败,可以将上面的执行语句变成一行,如下,可直接复制执行
docker run -d --name nacos -p 8848:8848  -p 9848:9848 -p 9849:9849 --privileged=true -e JVM_XMS=256m -e JVM_XMX=256m -e MODE=standalone -v /mydata/nacos/logs/:/home/nacos/logs -v /mydata/nacos/conf/:/home/nacos/conf/ --restart=always nacos/nacos-server

语句讲解 docker run -d : 启动容器 -d是后台启动并返回容器id的意思 –name nacos :为容器指定一个名称 -p 8848:8848 -p 9848:9848 -p 9849:9849 : 指定端口映射,注意这里的p不能大写,大写是随机端口映射 –privileged=true : 扩大容器内的权限,将容器内的权限变为root权限,不加的话就是普通用户权限,可能会出现cannot open directory -e JVM_XMS=256m : 为jvm启动时分配的内存 -e JVM_XMX=256m : 为jvm运行过程中分配的最大内存 -e MODE=standalone : 使用 standalone模式(单机模式),MODE值有cluster(集群)模式/standalone模式两种,MODE必须大写 -v /mydata/nacos/logs/:/home/nacos/logs : 将容器的/home/nacos/logs目录挂载到 /mydata/nacos/logs -v /mydata/nacos/conf/:/home/nacos/conf/: 将容器的/home/nacos/conf目录挂载到 /mydata/nacos/conf –restart=always :重启docker时,自动启动相关容器

9、注意事项

1、需要在防火墙开放相关端口,如果你是云服务器,开放安全组,下面提供相关语句

## 开放端口8848 9848 9849
firewall-cmd --zone=public --add-port=8848/tcp --permanent
firewall-cmd --zone=public --add-port=9848/tcp --permanent
firewall-cmd --zone=public --add-port=9849/tcp --permanent

## 重启防火墙
firewall-cmd --reload

## 查看所有开启的端口
firewall-cmd --zone=public --list-ports
  • PS:这里有点小问题,重启完防火墙之后,需要重启docker
## 重启docker
systemctl restart docker

2、这里最容易犯错的就是挂载目录对应不上,可以看下自己语句中的-v 后面的目录是否映射正确,第一次安装的时候logs里面还有一个logs文件夹,conf里面还有个conf文件夹,导致出错


[root@linux-local ~]# docker images
REPOSITORY           TAG                 IMAGE ID       CREATED         SIZE
nacos/nacos-server   latest              d3063c1db2bb   6 days ago      820MB
minio/minio          latest              a66f62e448f2   9 days ago      159MB
mongo                4                   3593bb45b7ce   5 weeks ago     427MB
redis                7                   170a1e90f843   3 months ago    138MB
mysql                5.7                 5107333e08a8   3 months ago    501MB
nginx                1.22                0f8498f13f3a   12 months ago   142MB
elasticsearch        7.17.3              3c91aa69ae06   24 months ago   613MB
kibana               7.17.3              4897f4b8b6ee   24 months ago   797MB
logstash             7.17.3              dd4291c803f4   24 months ago   774MB
rabbitmq             3.9.11-management   6c3c2a225947   2 years ago     253MB
[root@linux-local ~]# mkdir -p /mydata/nacos/logs/
[root@linux-local ~]# mkdir -p /mydata/nacos/conf/
[root@linux-local ~]# docker run -p 8848:8848 --name nacos -d nacos/nacos-server
a44b9cc71c0fc387abff019daaf0547a7e834a4661c713f266b4091b0eb89321
[root@linux-local ~]# docker cp nacos:/home/nacos/logs/ /mydata/nacos/
Successfully copied 126kB to /mydata/nacos/
[root@linux-local ~]# docker cp nacos:/home/nacos/conf/ /mydata/nacos/
Successfully copied 65.5kB to /mydata/nacos/
[root@linux-local ~]# docker rm -f nacos
nacos
[root@linux-local ~]# docker run -d
--name nacos
-p 8848:8848  -p 9848:9848 -p 9849:9849
--privileged=true
-e JVM_XMS=256m
-e JVM_XMX=256m
-e MODE=standalone
-v /mydata/nacos/logs/:/home/nacos/logs
-v /mydata/nacos/conf/:/home/nacos/conf/
--restart=always
nacos/nacos-server"docker run" requires at least 1 argument.
See 'docker run --help'.

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Create and run a new container from an image
[root@linux-local ~]# --name nacos-bash: complete: --: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
-bash: complete: --: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
-bash: complete: --: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
-bash: complete: --: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
-bash: complete: --: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
-bash: complete: --: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
-bash: complete: --: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
-bash: complete: --: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
-bash: complete: --: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
-bash: complete: --: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
-bash: complete: --: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
-bash: complete: --: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
-bash: complete: --: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
-bash: complete: --: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]
-bash: complete: --: invalid option
complete: usage: complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G globpat] [-W wordlist]  [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...]

bash: --name: command not found...
[root@linux-local ~]# -p 8848:8848  -p 9848:9848 -p 9849:9849
bash: -p: command not found...
[root@linux-local ~]# --privileged=true
bash: --privileged=true: command not found...
[root@linux-local ~]# -e JVM_XMS=256m
bash: -e: command not found...
[root@linux-local ~]# -e JVM_XMX=256m
bash: -e: command not found...
[root@linux-local ~]# -e MODE=standalone
bash: -e: command not found...
[root@linux-local ~]# -v /mydata/nacos/logs/:/home/nacos/logs
bash: -v: command not found...
[root@linux-local ~]# -v /mydata/nacos/conf/:/home/nacos/conf/
bash: -v: command not found...
[root@linux-local ~]# --restart=always
bash: --restart=always: command not found...
[root@linux-local ~]# docker run -d --name nacos -p 8848:8848  -p 9848:9848 -p 9849:9849 --privileged=true -e JVM_XMS=256m -e JVM_XMX=256m -e MODE=standalone -v /mydata/nacos/logs/:/home/nacos/logs -v /mydata/nacos/conf/:/home/nacos/conf/ --restart=always nacos/nacos-server
4117268ba16b953241c84c39b3d6cfed40d24dfb2f0981aed96a0768273e8e70
[root@linux-local ~]# firewall-cmd --zone=public --add-port=8848/tcp --permanent
success
[root@linux-local ~]# firewall-cmd --zone=public --add-port=9848/tcp --permanent
success
[root@linux-local ~]# firewall-cmd --zone=public --add-port=9849/tcp --permanent
success
[root@linux-local ~]# firewall-cmd --reload
success
[root@linux-local ~]# firewall-cmd --zone=public --list-ports
8080/tcp 15672/tcp 9200/tcp 8848/tcp 9848/tcp 9849/tcp
[root@linux-local ~]# systemctl restart docker
[root@linux-local ~]# docker ps
CONTAINER ID   IMAGE                COMMAND                  CREATED         STATUS         PORTS                                                                                                      NAMES
4117268ba16b   nacos/nacos-server   "bin/docker-startup.…"   2 minutes ago   Up 3 seconds   0.0.0.0:8848->8848/tcp, :::8848->8848/tcp, 0.0.0.0:9848-9849->9848-9849/tcp, :::9848-9849->9848-9849/tcp   nacos

10、修改配置文件

  • 主要修改的是application.properties文件
## 在宿主机中修改application.properties文件
vim /mydata/nacos/conf/application.properties
  • 文件修改的地方(修改为你对应的mysql)
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://localhost:3306/nacos-config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=30000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user=root
db.password=stucoding
  • PS :因为我们在第三步已经复制了logs和conf到了我们的宿主机里面,那么我们可以直接修改application.properties文件映射到容器里,可以通过下面的语句来查看
## 进入到nacos容器里
docker exec -it nacos /bin/bash

## 查看application.properties文件
cat /home/nacos/conf/application.properties

## 退出容器
exit
  • PS:如果文件没有修改成功的话,说明挂载目录映射的不对,仔细查看一下,可以通过下面的方法来查看是否正确

11、访问页面

http://ip:8848/nacos/index.html

十二、nacos安装(指定版本2.0.2)

1、Docker 拉取镜像

docker pull nacos/nacos-server:2.0.2

2、挂载目录

mkdir -p /mydata/nacos/logs/                      #新建logs目录
mkdir -p /mydata/nacos/conf/						#新建conf目录

3、启动容器nacos

docker run -p 8848:8848 --name nacos -di nacos/nacos-server:2.0.2

4、复制文件

docker cp nacos:/home/nacos/logs/ /mydata/nacos/
docker cp nacos:/home/nacos/conf/ /mydata/nacos/

5、停止临时容器并删除

# 停止nacos
docker stop nacos
# 删除nacos容器
docker rm nacos

6、mysql中创建nacos所需的表

/*
 * Copyright 1999-2018 Alibaba Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = config_info   */
/******************************************/
CREATE TABLE `config_info` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `data_id` varchar(255) NOT NULL COMMENT 'data_id',
  `group_id` varchar(255) DEFAULT NULL,
  `content` longtext NOT NULL COMMENT 'content',
  `md5` varchar(32) DEFAULT NULL COMMENT 'md5',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  `src_user` text COMMENT 'source user',
  `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',
  `app_name` varchar(128) DEFAULT NULL,
  `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
  `c_desc` varchar(256) DEFAULT NULL,
  `c_use` varchar(64) DEFAULT NULL,
  `effect` varchar(64) DEFAULT NULL,
  `type` varchar(64) DEFAULT NULL,
  `c_schema` text,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_configinfo_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info';

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = config_info_aggr   */
/******************************************/
CREATE TABLE `config_info_aggr` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `data_id` varchar(255) NOT NULL COMMENT 'data_id',
  `group_id` varchar(255) NOT NULL COMMENT 'group_id',
  `datum_id` varchar(255) NOT NULL COMMENT 'datum_id',
  `content` longtext NOT NULL COMMENT '内容',
  `gmt_modified` datetime NOT NULL COMMENT '修改时间',
  `app_name` varchar(128) DEFAULT NULL,
  `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_configinfoaggr_datagrouptenantdatum` (`data_id`,`group_id`,`tenant_id`,`datum_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='增加租户字段';


/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = config_info_beta   */
/******************************************/
CREATE TABLE `config_info_beta` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `data_id` varchar(255) NOT NULL COMMENT 'data_id',
  `group_id` varchar(128) NOT NULL COMMENT 'group_id',
  `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
  `content` longtext NOT NULL COMMENT 'content',
  `beta_ips` varchar(1024) DEFAULT NULL COMMENT 'betaIps',
  `md5` varchar(32) DEFAULT NULL COMMENT 'md5',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  `src_user` text COMMENT 'source user',
  `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',
  `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_configinfobeta_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_beta';

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = config_info_tag   */
/******************************************/
CREATE TABLE `config_info_tag` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `data_id` varchar(255) NOT NULL COMMENT 'data_id',
  `group_id` varchar(128) NOT NULL COMMENT 'group_id',
  `tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id',
  `tag_id` varchar(128) NOT NULL COMMENT 'tag_id',
  `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
  `content` longtext NOT NULL COMMENT 'content',
  `md5` varchar(32) DEFAULT NULL COMMENT 'md5',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  `src_user` text COMMENT 'source user',
  `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_configinfotag_datagrouptenanttag` (`data_id`,`group_id`,`tenant_id`,`tag_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_tag';

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = config_tags_relation   */
/******************************************/
CREATE TABLE `config_tags_relation` (
  `id` bigint(20) NOT NULL COMMENT 'id',
  `tag_name` varchar(128) NOT NULL COMMENT 'tag_name',
  `tag_type` varchar(64) DEFAULT NULL COMMENT 'tag_type',
  `data_id` varchar(255) NOT NULL COMMENT 'data_id',
  `group_id` varchar(128) NOT NULL COMMENT 'group_id',
  `tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id',
  `nid` bigint(20) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`nid`),
  UNIQUE KEY `uk_configtagrelation_configidtag` (`id`,`tag_name`,`tag_type`),
  KEY `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_tag_relation';

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = group_capacity   */
/******************************************/
CREATE TABLE `group_capacity` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `group_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'Group ID,空字符表示整个集群',
  `quota` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '配额,0表示使用默认值',
  `usage` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '使用量',
  `max_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值',
  `max_aggr_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '聚合子配置最大个数,,0表示使用默认值',
  `max_aggr_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',
  `max_history_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最大变更历史数量',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_group_id` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='集群、各Group容量信息表';

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = his_config_info   */
/******************************************/
CREATE TABLE `his_config_info` (
  `id` bigint(64) unsigned NOT NULL,
  `nid` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `data_id` varchar(255) NOT NULL,
  `group_id` varchar(128) NOT NULL,
  `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
  `content` longtext NOT NULL,
  `md5` varchar(32) DEFAULT NULL,
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `src_user` text,
  `src_ip` varchar(50) DEFAULT NULL,
  `op_type` char(10) DEFAULT NULL,
  `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
  PRIMARY KEY (`nid`),
  KEY `idx_gmt_create` (`gmt_create`),
  KEY `idx_gmt_modified` (`gmt_modified`),
  KEY `idx_did` (`data_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='多租户改造';


/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = tenant_capacity   */
/******************************************/
CREATE TABLE `tenant_capacity` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `tenant_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'Tenant ID',
  `quota` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '配额,0表示使用默认值',
  `usage` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '使用量',
  `max_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值',
  `max_aggr_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '聚合子配置最大个数',
  `max_aggr_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',
  `max_history_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最大变更历史数量',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='租户容量信息表';


CREATE TABLE `tenant_info` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `kp` varchar(128) NOT NULL COMMENT 'kp',
  `tenant_id` varchar(128) default '' COMMENT 'tenant_id',
  `tenant_name` varchar(128) default '' COMMENT 'tenant_name',
  `tenant_desc` varchar(256) DEFAULT NULL COMMENT 'tenant_desc',
  `create_source` varchar(32) DEFAULT NULL COMMENT 'create_source',
  `gmt_create` bigint(20) NOT NULL COMMENT '创建时间',
  `gmt_modified` bigint(20) NOT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_tenant_info_kptenantid` (`kp`,`tenant_id`),
  KEY `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='tenant_info';

CREATE TABLE `users` (
	`username` varchar(50) NOT NULL PRIMARY KEY,
	`password` varchar(500) NOT NULL,
	`enabled` boolean NOT NULL
);

CREATE TABLE `roles` (
	`username` varchar(50) NOT NULL,
	`role` varchar(50) NOT NULL,
	UNIQUE INDEX `idx_user_role` (`username` ASC, `role` ASC) USING BTREE
);

CREATE TABLE `permissions` (
    `role` varchar(50) NOT NULL,
    `resource` varchar(255) NOT NULL,
    `action` varchar(8) NOT NULL,
    UNIQUE INDEX `uk_role_permission` (`role`,`resource`,`action`) USING BTREE
);

INSERT INTO users (username, password, enabled) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE);

INSERT INTO roles (username, role) VALUES ('nacos', 'ROLE_ADMIN');

7、再次启动nacos

docker run -d
--name nacos															 
-p 8848:8848  -p 9848:9848 -p 9849:9849
--privileged=true
-e JVM_XMS=256m
-e JVM_XMX=256m
-e MODE=standalone
-v /mydata/nacos/logs/:/home/nacos/logs
-v /mydata/nacos/conf/:/home/nacos/conf/
--restart=always
nacos/nacos-server:2.0.2
  • PS : 复制上面的语句执行失败,可以将上面的执行语句变成一行,如下,可直接复制执行
docker run -d --name nacos -p 8848:8848  -p 9848:9848 -p 9849:9849 --privileged=true -e JVM_XMS=256m -e JVM_XMX=256m -e MODE=standalone -v /mydata/nacos/logs/:/home/nacos/logs -v /mydata/nacos/conf/:/home/nacos/conf/ --restart=always nacos/nacos-server:2.0.2

8、注意事项

  • 需要在防火墙开放相关端口,如果你是云服务器,开放安全组,下面提供相关语句
## 开放端口8848 9848 9849
firewall-cmd --zone=public --add-port=8848/tcp --permanent
firewall-cmd --zone=public --add-port=9848/tcp --permanent
firewall-cmd --zone=public --add-port=9849/tcp --permanent

## 重启防火墙
firewall-cmd --reload

## 查看所有开启的端口
firewall-cmd --zone=public --list-ports

  • PS:这里有点小问题,重启完防火墙之后,需要重启docker
## 重启docker
systemctl restart docker
  • 这里最容易犯错的就是挂载目录对应不上,可以看下自己语句中的-v 后面的目录是否映射正确,博主第一次安装的时候logs里面还有一个logs文件夹,conf里面还有个conf文件夹,导致出错

9、修改配置文件

  • 复制备份配置文件

[root@linux-local /]# cd /mydata/nacos/conf/
[root@linux-local conf]# ll
total 56
-rw-r--r--. 1 root root  1224 Apr 19  2021 1.4.0-ipv6_support-update.sql
-rw-r--r--. 1 root root  2532 Jun 29  2021 application.properties
-rw-r--r--. 1 root root     1 Apr 10 18:54 cluster.conf
-rw-r--r--. 1 root root 31156 Jun  7  2021 nacos-logback.xml
-rw-r--r--. 1 root root  8795 Apr 19  2021 schema.sql
[root@linux-local conf]# ^C
[root@linux-local conf]# cp application.properties applicationback2024.properties
[root@linux-local conf]#
  • 主要修改的是application.properties文件
## 在宿主机中修改application.properties文件
vim /mydata/nacos/conf/application.properties
  • 文件修改的地方(修改为你对应的mysql)
# spring
server.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos}
server.contextPath=/nacos
server.port=${NACOS_APPLICATION_PORT:8848}
#spring.datasource.platform=${SPRING_DATASOURCE_PLATFORM:""}
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false

### If use MySQL as datasource:
spring.datasource.platform=mysql
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://192.168.1.71:3306/nacos-config?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false
db.user=root
db.password=stucoding

### The auth system to use, currently only 'nacos' is supported:
nacos.core.auth.system.type=${NACOS_AUTH_SYSTEM_TYPE:nacos}


### The token expiration in seconds:
nacos.core.auth.default.token.expire.seconds=${NACOS_AUTH_TOKEN_EXPIRE_SECONDS:18000}

### The default token:
nacos.core.auth.default.token.secret.key=${NACOS_AUTH_TOKEN:SecretKey012345678901234567890123456789012345678901234567890123456789}

### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=${NACOS_AUTH_CACHE_ENABLE:false}
nacos.core.auth.enable.userAgentAuthWhite=${NACOS_AUTH_USER_AGENT_AUTH_WHITE_ENABLE:false}
nacos.core.auth.server.identity.key=${NACOS_AUTH_IDENTITY_KEY:serverIdentity}
nacos.core.auth.server.identity.value=${NACOS_AUTH_IDENTITY_VALUE:security}
server.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false}
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir
server.tomcat.basedir=
## spring security config
### turn off security
nacos.security.ignore.urls=${NACOS_SECURITY_IGNORE_URLS:/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**}
# metrics for elastic search
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false

nacos.naming.distro.taskDispatchThreadCount=10
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true
  • PS :因为我们在第三步已经复制了logs和conf到了我们的宿主机里面,那么我们可以直接修改application.properties文件映射到容器里,可以通过下面的语句来查看
## 进入到nacos容器里
docker exec -it nacos /bin/bash

## 查看application.properties文件
cat /home/nacos/conf/application.properties

## 退出容器
exit
  • PS:如果文件没有修改成功的话,说明挂载目录映射的不对,仔细查看一下,可以通过下面的方法来查看是否正确
docker inspect --format="{{json .Mounts}}" nacos

10、访问页面

http://ip:8848/nacos/index.html
http://192.168.1.71/:8848/nacos/index.html

image-20240410195329841

十三、Docker全部环境安装完成

[root@linux-local /]# docker images
REPOSITORY           TAG                 IMAGE ID       CREATED         SIZE
minio/minio          latest              a66f62e448f2   10 days ago     159MB
mongo                4                   3593bb45b7ce   5 weeks ago     427MB
redis                7                   170a1e90f843   3 months ago    138MB
mysql                5.7                 5107333e08a8   3 months ago    501MB
nginx                1.22                0f8498f13f3a   12 months ago   142MB
elasticsearch        7.17.3              3c91aa69ae06   24 months ago   613MB
kibana               7.17.3              4897f4b8b6ee   24 months ago   797MB
logstash             7.17.3              dd4291c803f4   24 months ago   774MB
rabbitmq             3.9.11-management   6c3c2a225947   2 years ago     253MB
nacos/nacos-server   2.0.2               c8cd99bb135c   2 years ago     1.05GB

Last Updated 2024/4/10 19:57:43