侧边栏壁纸
博主头像
一揽芳华 博主等级

行动起来,活在当下

  • 累计撰写 265 篇文章
  • 累计创建 24 个标签
  • 累计收到 4 条评论

目 录CONTENT

文章目录

06.使用supervisord管理mysql

芳华是个男孩!
2024-10-14 / 0 评论 / 0 点赞 / 9 阅读 / 0 字
广告 广告

title: 06-管理mysql
order: 6

icon: lightbulb

1.启动一个容器,安装mysql服务

[root@172-0-110-100 mysql]# docker run -itd --name mysql -p 3306:3306 -p 9001:9001 --cpus 4 --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro  supervisor/os7:1.0 /usr/sbin/init

2.安装mysql服务

##基本登录安装配置
[root@172-0-110-100 mysql]# docker exec -it mysql bash
[root@0b2f26503c2f ~]# ./root/supervisor_startup.sh
[root@0b2f26503c2f ~]# yum -y install https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm && rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
[root@0b2f26503c2f ~]# yum -y install mysql-community-server

##启动mysql
[root@ed9f9ab6938d mysql]# systemctl start mysqld
[root@ed9f9ab6938d mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2023-09-14 07:00:22 UTC; 13s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 523 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 469 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 525 (mysqld)
   CGroup: /docker/ed9f9ab6938de0f84071378b406165854878cff0fdc6e59b7c2c8bf2851ae28c/system.slice/mysqld.service
           └─525 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Sep 14 07:00:07 ed9f9ab6938d systemd[1]: Starting MySQL Server...
Sep 14 07:00:22 ed9f9ab6938d systemd[1]: Started MySQL Server.

##配置mysql密码和远程访问权限等
-# 查看临时密码
[root@ed9f9ab6938d mysql]# grep 'temporary password' /var/log/mysqld.log
2023-09-14T07:00:09.810730Z 1 [Note] A temporary password is generated for root@localhost: a+or>H.Sk0)f  #密码:a+or>H.Sk0)f
-# 登录并修改密码
[root@ed9f9ab6938d mysql]#  mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.37-log

right (c) 2000, 2022, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Ab123../';


- #修改远程访问权限
mysql> use mysql;
mysql> select Host,User from user;
mysql> update user set Host='%' where User='root';
mysql> flush privileges;
mysql> grant all privileges on *.* to 'root'@'%' with grant option;

- #重启mysql服务
[root@ed9f9ab6938d mysql]# systemctl restart mysqld

3.测试连接

6.2.编写基于supervisor的mysql子进程文件

关闭mysql服务
[root@b08fad5067d7 mysql]# systemctl stop mysqld
```
编写子进程管理文件
[root@b08fad5067d7 mysql]# vim /etc/supervisord.d/mysql.ini 
[program:mysql]
directory=/usr/sbin/mysqld
command=/usr/sbin/mysqld
autostart=true
startsecs=10
autorestart=true 
startretries=3 
user=mysql
priority=999
stopsignal=INT
redirect_stderr=true
stdout_logfile_maxbytes=200MB
stdout_logfile_backups = 100
stdout_logfile=/var/log/supervisor/mysql.log
stopasgroup=true
killasgroup=true
```
启动supervisor程序
[root@b08fad5067d7 mysql]# supervisord -c /etc/supervisord.conf
[root@b08fad5067d7 mysql]# supervisorctl update  
```
浏览器测试

0
广告 广告

评论区