安装笔记:docker安装discuz

docker安装discuz

查询discuz镜像版本,选第一个

docker search discuz

查询discuz镜像
下载镜像

docker pull docker.io/tencentci/discuz

下载镜像
启动discuz镜像,名称:BCB_BBS,外部 8000端口映射到内部 80端口

docker run --name BCB_BBS  -d -p 8000:80  tencentci/discuz

启动discuz
访问主机地址8000端口,出现下面画面:
http://192.168.1.251:8000/
在这里插入图片描述
在宿主机上安装mariadb数据库

yum install mariadb-server

mariadb-server安装完毕

开启数据库服务

systemctl start mariadb

检查数据库的端口是3306,有这一端口,表明数据库已开启

ss -lntup | grep 3306 

查看Mysql进程

ps -ef | grep mysql 

开启mariadb服务
运行数据库的初始化页面,如下图所示

mysql_secure_installation

初始化数据库
详见

Mariadb数据库的安装与初始化
链接地址: https://blog.csdn.net/qq_53086187/article/details/125429557

使用mysql -u指定用户,-p密码 登录mysql数据库

 [root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>



查看数据库

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)

创建名为:论坛的数据库

 MariaDB [(none)]> create database BCB_BBS;
Query OK, 1 row affected (0.00 sec)

在这里插入图片描述
使用论坛数据库,查看里面是否有表

MariaDB [(none)]> use BCB_BBS
Database changed
MariaDB [BCB_BBS]> show tables
    -> ;
Empty set (0.00 sec)
MariaDB [BCB_BBS]> exit
Bye

查看 BCB_BBS 这一容器的IP地址

[root@localhost ~]# docker exec BCB_BBS hostname -I
172.17.0.2 

填写相关信息,创建论坛,如下图所示
打开http://192.168.1.251:8000/
我同意——取消(安装UTF8正式版下载)——
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
上图
在这里插入图片描述
这里数据库连接错误。先把centos的防火墙关闭:

systemctl stop firewalld

在这里插入图片描述
还提示错误:“Host ‘172.17.0.2’ is not allowed to connect to this MariaDB server”。这个问题应该是数据库root远程登录权限被禁止造成,如下操作:

mysql -u root -p         #用root打开mysql

show databases;   #显示已有数据库

use mysql   #打开mysql库

select host, user from user; #列出主机、用户权限

grant all on *.* to root@'192.168.1.251' identified by 'mysql';  #给root用户在192.168.1.251上赋访问权限,密码 mysql

grant all on *.* to root@'%' identified by 'mysql';    #给root用户在任何主机上赋访问权限,密码 mysql

flush privileges; #更新

select host,user,password from user; #列出host,user,password权限列表

update user set user="root" where host='%';   #更新数据库用户权限

在这里插入图片描述

注意几点:

centos7防火墙必须关闭,论坛才能正常运行。
mariaDB安装完要赋予root用户,其他机器访问权限

让docker容器BCB_BBS开机自动启动

1、让docker服务自动开启

命令:systemctl enable 服务名称

[root@localhost ~]# systemctl enable docker 设置自动重启
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]# systemctl status docker #查看docker服务运行状态
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since 四 2022-10-20 15:01:34 CST; 23s ago
     Docs: http://docs.docker.com
 Main PID: 4159 (dockerd-current)
   CGroup: /system.slice/docker.service

2、容器BCB_BBS自动启动

命令: docker update --restart=always 容器ID

[root@localhost ~]# docker ps -a #列出所有创建的容器
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
7919e60488a0        tencentci/discuz    "docker-php-entryp..."   28 hours ago        Exited (0) 6 minutes ago                       BCB_BBS
[root@localhost ~]# docker start BCB_BBS #开启容器BCB_BBS
BCB_BBS
[root@localhost ~]# docker ps #查询开启的容器
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                           NAMES
7919e60488a0        tencentci/discuz    "docker-php-entryp..."   28 hours ago        Up 7 seconds        443/tcp, 0.0.0.0:8000->80/tcp   BCB_BBS
[root@localhost ~]# docker update --restart=always 7919e60488a0  #设置已打开的容器自动重启
7919e60488a0

命令记录:

[root@localhost ~]# mysql -u root -p         
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| BCB_BBS            |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> use BCB_BBS
Database changed
MariaDB [BCB_BBS]> show tables
    -> ;
Empty set (0.00 sec)

MariaDB [BCB_BBS]> select host, user from user;
ERROR 1146 (42S02): Table 'BCB_BBS.user' doesn't exist
MariaDB [BCB_BBS]> mysql_install_db
    -> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'mysql_install_db' at line 1
MariaDB [BCB_BBS]> quit
Bye
[root@localhost ~]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] n
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@localhost ~]# mysql -u root -p         
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.68-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| BCB_BBS            |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> use BCB_BBS
Database changed
MariaDB [BCB_BBS]> show tables
    -> ;
Empty set (0.00 sec)

MariaDB [BCB_BBS]> select host, user from user;
ERROR 1146 (42S02): Table 'BCB_BBS.user' doesn't exist
MariaDB [BCB_BBS]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> select host, user from user;
+-----------+------+
| host      | user |
+-----------+------+
| 127.0.0.1 | root |
| ::1       | root |
| localhost | root |
+-----------+------+
3 rows in set (0.00 sec)

MariaDB [mysql]> grant all on *.* to root@'192.168.1.251' identified by 'mysql';
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> grant all on *.* to root@'%' identified by 'mysql';             
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [mysql]> select host,user,password from user;
+---------------+------+-------------------------------------------+
| host          | user | password                                  |
+---------------+------+-------------------------------------------+
| localhost     | root | *69EFC9886A9E927DB443FE7FC277FB2F643C4E99 |
| 127.0.0.1     | root | *69EFC9886A9E927DB443FE7FC277FB2F643C4E99 |
| ::1           | root | *69EFC9886A9E927DB443FE7FC277FB2F643C4E99 |
| %             | root | *E74858DB86EBA20BC33D0AECAE8A8108C56B17FA |
| 192.168.1.251 | root | *E74858DB86EBA20BC33D0AECAE8A8108C56B17FA |
+---------------+------+-------------------------------------------+
5 rows in set (0.00 sec)

MariaDB [mysql]> update user set user="root" where host='%';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

MariaDB [mysql]> quit
Bye

[root@localhost ~]# systemctl enable docker 设置自动重启
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[root@localhost ~]# systemctl status docker #查看docker服务运行状态
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since 四 2022-10-20 15:01:34 CST; 23s ago
     Docs: http://docs.docker.com
 Main PID: 4159 (dockerd-current)
   CGroup: /system.slice/docker.service

[root@localhost ~]# docker ps -a #列出所有创建的容器
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                     PORTS               NAMES
7919e60488a0        tencentci/discuz    "docker-php-entryp..."   28 hours ago        Exited (0) 6 minutes ago                       BCB_BBS
[root@localhost ~]# docker start BCB_BBS #开启容器BCB_BBS
BCB_BBS
[root@localhost ~]# docker ps #查询开启的容器
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                           NAMES
7919e60488a0        tencentci/discuz    "docker-php-entryp..."   28 hours ago        Up 7 seconds        443/tcp, 0.0.0.0:8000->80/tcp   BCB_BBS
[root@localhost ~]# docker update --restart=always 7919e60488a0  #设置已打开的容器自动重启
7919e60488a0   


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值