一.docker部署mysql5.7数据库
docker pull mysql:5.7
mkdir -p /data/mysql/data /data/mysql/logs /data/mysql/conf
touch /data/mysql/conf/my.cnf
docker run --restart=always -p 13306:3306 --name mysql -v /data/mysql/conf:/etc/mysql/conf.d -v /data/mysql/logs:/logs -v /data/mysql/data:/var/lib/mysql -v /etc/localtime:/etc/localtime:ro -e MYSQL_ROOT_PASSWORD=111111 -d mysql:5.7
docker exec -it mysql bash
二.创建wordpress用户
1、root登录服务器 进入数据库 mysql -u root -p111111
2、创建数据库 create database wordpress; shop 为数据库名称
3、查看创建数据库 show databases; (小命令 use shop; 进入数据库 show table;)
4、创建数据库的用户
create user 'wordpress'@'%' identified by '111111';
'wordpress' 用户名称
'111111' 用户密码
@后的命令解释
'%' - 所有情况都能访问
'localhost' - 本机才能访问
'111.222.33.44' - 指定 ip 才能访问
5、给予新用户的授予权限
grant all on wordpress.* to wordpress@'%' identified by "111111";
all 可以替换为 select,delete,update,create,drop
数据库名 所有的 用*
数据库表 所有的 用*
6、查看权限
show grants for 'wordpress'@'%' (如果定义了指定ip 访问 就需要更改为ip地址)
7、删除用户
drop user 用户名称
8、修改用户
rename user '用户名称'@'ip地址/%' to '新用户'@'ip地址/%';
9、修改密码
set password for '用户名'@'IP地址' = Password('新密码');
三.docker部署wordpress服务
docker run -itd --name=wordpress --restart=always -v /data/wordpress/html:/var/www/html --link mysql:mysql -p 8888:80 -d wordpress:6.3
http://192.168.1.1:8888/
http://192.168.1.1:8888/wp-login.php #登录wordpress
重点就是将数据库连接配置设置好就行,没啥技术难点
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-wordpress
labels:
app: wordpress
env: test
team: scorpio
role: service
spec:
selector:
matchLabels:
app: wordpress
env: test
team: scorpio
role: service
replicas: 1
strategy:
rollingUpdate:
maxSurge: 20%
maxUnavailable: 5%
type: RollingUpdate
template:
metadata:
name: wordpress
annotations:
proxy.istio.io/config: |
terminationDrainDuration: "35s"
labels:
app: wordpress
env: test
team: scorpio
role: service
spec:
terminationGracePeriodSeconds: 65
containers:
- name: wordpress
image: wordpress:6.3
imagePullPolicy: IfNotPresent
env:
- name: WORDPRESS_DB_HOST
value: '192.168.1.1:13306'
- name: WORDPRESS_DB_USER
value: 'root'
- name: WORDPRESS_DB_PASSWORD
value: 'wordpress'
- name: WORDPRESS_DB_NAME
value: 'wordpress'
- name: TZ
value: Asia/Shanghai
ports:
- containerPort: 80
name: http-port
# livenessProbe:
# httpGet:
# path: /actuator/health
# port: http-port
# initialDelaySeconds: 10
# timeoutSeconds: 30
# periodSeconds: 30
# failureThreshold: 3
# readinessProbe:
# httpGet:
# path: /actuator/health
# port: http-port
# initialDelaySeconds: 10
# timeoutSeconds: 30
# failureThreshold: 3
volumeMounts:
- name: var-www-html
mountPath: /var/www/html
volumes:
- name: var-www-html
hostPath:
path: /data/var/www/html
type: DirectoryOrCreate
---
apiVersion: v1
kind: Service
metadata:
name: test-wordpress
labels:
app: wordpress
env: test
team: scorpio
role: service
spec:
type: ClusterIP
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: wordpress
env: test
team: scorpio
role: service
registry.cn-shenzhen.aliyuncs.com/gemdale/wordpress:6.3.0-php8.2-apache #这个镜像是wordpress6.3推入本地镜像仓库的镜像