作业要求:
使用Discuz和数据库容器搭建论坛服务。
实现步骤:
1、拉取Discuz镜像
[root@localhost ~]# docker search discuz #寻找镜像文件
[root@localhost ~]# docker pull tencentci/discuz #拉取镜像文件
Using default tag: latest
latest: Pulling from tencentci/discuz
d599a449871e: Pull complete
1a363f133ddd: Pull complete
dd6ffd5f60d7: Pull complete
515e48bcd87c: Pull complete
c6f3d43db193: Pull complete
f1c6f8e807f6: Pull complete
65d8fe3b5a08: Pull complete
80429671c76c: Pull complete
053b8d72a5a3: Pull complete
deb7baf580dc: Pull complete
8201b8a6c5c5: Pull complete
689e9b2c72d1: Pull complete
50557b0d5d8a: Pull complete
9beee0a5f923: Pull complete
97139e44b116: Pull complete
563f74e42351: Pull complete
Digest: sha256:b2d9f7cfde768d844fef738a6e1bb4dc5675bddf2565f296d7b76d1eabfd0218
Status: Downloaded newer image for tencentci/discuz:latest
docker.io/tencentci/discuz:latest
[root@localhost ~]# docker images tencentci/discuz #查看所拉取的镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
tencentci/discuz latest 4833f513a33c 13 months ago 463MB
2、运行镜像
[root@localhost ~]# docker run -P -d tencentci/discuz
8efb09e811f9acdf3cb4bf43ead6e76dbde01bd43dc639374cbb2ac015713aeb
3、数据库操作
这里要求使用数据库容器,但我写了两种方法:
方法一:yum安装
安装数据库
yum install mariadb-server -y
启动数据库
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# ss -lntup | grep 3306
tcp LISTEN 0 50 *:3306 *:* users:(("mysqld",pid=3998,fd=14))
进入mysql安全配置向导
mysql_secure_installation
后面就是一路y下去
创建数据库luntan
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
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 |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> create database luntan;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| luntan |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>
给容器授予mysql的权限
MariaDB [(none)]> grant all on *.* to 'root'@'%' identified by 'mysql';
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> select Host,User,Password from user ;
+-----------+------+-------------------------------------------+
| Host | User | Password |
+-----------+------+-------------------------------------------+
| localhost | root | *2E17BB090CAC112CADCCC603256E9D7A5E20E7FE |
| 127.0.0.1 | root | *2E17BB090CAC112CADCCC603256E9D7A5E20E7FE |
| ::1 | root | *2E17BB090CAC112CADCCC603256E9D7A5E20E7FE |
| % | root | *E74858DB86EBA20BC33D0AECAE8A8108C56B17FA |
+-----------+------+-------------------------------------------+
4 rows in set (0.00 sec)
MariaDB [mysql]> flush privileges; #刷新权限表
Query OK, 0 rows affected (0.00 sec)
[root@localhost ~]# mysql -u root -pmysql -h 192.168.15.133 #查看权限是否设置成功
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 20
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)]> exit
Bye
4、访问论坛
[root@localhost ~]# docker ps #查看进程端口号
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8efb09e811f9 tencentci/discuz "docker-php-entrypoi…" 40 seconds ago Up 39 seconds 0.0.0.0:49154->80/tcp, :::49154->80/tcp, 0.0.0.0:49153->443/tcp, :::49153->443/tcp optimistic_haibt
方法二:docker拉取数据库容器
(1)拉取:
运行数据库容器:
[root@localhost ~]# docker run -itd --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123 mysql
7897e256992ea64c067a706444f80a032105e4998576118784891dbaf031ef99
查看docker的ip地址:
[root@localhost ~]# docker inspect mysql | grep -i ipaddress
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.2",
"IPAddress": "172.17.0.2",
对运行的容器执行命令:
[root@localhost ~]# docker exec -it mysql bash
进入mysql:
root@7897e256992e:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27 MySQL Community Server - GPL
Copyright (c) 2000, 2021, 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.
创建用户qyx,并授予权限
mysql> create user qyx@'%' identified by '123';
Query OK, 0 rows affected (0.03 sec)
mysql> grant all privileges on *.* to qyx@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
测试是否成功创建用户并授予权限:
root@7897e256992e:/# mysql -uqyx -p -h 172.17.0.2
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.27 MySQL Community Server - GPL
Copyright (c) 2000, 2021, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)
创建数据库:
mysql> create database luntan;
Query OK, 1 row affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| luntan |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
论坛搭建成功!