第十三周学习作业

Posted 三石头

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第十三周学习作业相关的知识,希望对你有一定的参考价值。

1、ansible-playbook实现mysql的二进制部署

准备安装介质和配置文件

[root@CentOS84 data]# tree file
file
├── my.cnf
└── mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
[root@CentOS84 data]# cat file/my.cnf
[mysqld]
datadir=/data/mysql
log_bin=1
server_id=1
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock

ansible-playbook安装脚本

[root@CentOS84 data]# cat mysql_install2.yaml
---
- hosts: db
remote_user: root
gather_facts: no

vars:
version: "mysql-5.7.35-linux-glibc2.12-x86_64"
suffix: "tar.gz"
file: "version.suffix"
password: "mysql123"

tasks:
- name: 创建用户组
group: name=mysql gid=306
- name: 创建用户并加入到组
user: name=mysql uid=306 group=mysql shell=/sbin/nologin system=yes create_home=no home=/data/mysql
- name: 拷贝并解压文件
unarchive: src=/data/file/file dest=/usr/local/
- name: 创建链接文件
file: src=/usr/local/version dest=/usr/local/mysql state=link owner=mysql group=mysql
- name: 配置环境变量
shell: "echo PATH=/usr/local/mysql/bin:$PATH > /etc/profile.d/mysql.sh"
- name: 环境变量生效
shell: source /etc/profile.d/mysql.sh
- name: 创建数据目录
file: name=/data/mysql state=directory owner=mysql group=mysql
- name: 拷贝配置文件
copy: src=/data/file/my.cnf dest=/etc/my.cnf
- name: 初始化数据文件
shell: mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
- name: 拷贝启动脚本
shell: /bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
- name: 启动mysql服务
shell: chkconfig --add mysqld && service mysqld start
- name: 更改root口令 password
shell: mysqladmin -uroot password password

执行过程如下:

[root@CentOS84 data]# ansible-playbook mysql_install2.yaml

PLAY [db] *****************************************************************************************************************************

TASK [创建用户组] **************************************************************************************************************************
changed: [10.10.10.12]
changed: [10.10.10.11]

TASK [创建用户并加入到组] **********************************************************************************************************************
changed: [10.10.10.12]
changed: [10.10.10.11]

TASK [拷贝并解压文件] ************************************************************************************************************************
changed: [10.10.10.11]
changed: [10.10.10.12]

TASK [创建链接文件] *************************************************************************************************************************
changed: [10.10.10.11]
changed: [10.10.10.12]

TASK [配置环境变量] *************************************************************************************************************************
changed: [10.10.10.12]
changed: [10.10.10.11]

TASK [环境变量生效] *************************************************************************************************************************
changed: [10.10.10.12]
changed: [10.10.10.11]

TASK [创建数据目录] *************************************************************************************************************************
changed: [10.10.10.12]
changed: [10.10.10.11]

TASK [拷贝配置文件] *************************************************************************************************************************
changed: [10.10.10.12]
changed: [10.10.10.11]

TASK [初始化数据文件] ************************************************************************************************************************
changed: [10.10.10.12]
changed: [10.10.10.11]

TASK [拷贝启动脚本] *************************************************************************************************************************
changed: [10.10.10.12]
changed: [10.10.10.11]

TASK [启动mysql服务] **********************************************************************************************************************
changed: [10.10.10.12]
changed: [10.10.10.11]

TASK [更改root口令 mysql123] **************************************************************************************************************
changed: [10.10.10.12]
changed: [10.10.10.11]

PLAY RECAP ****************************************************************************************************************************
10.10.10.11 : ok=12 changed=12 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
10.10.10.12 : ok=12 changed=12 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

登录验证:

[root@CentOS84 data]# ssh 10.10.10.11
Last login: Thu Mar 10 18:29:22 2022 from 10.10.10.10
[root@CentOS8411 ~]# mysql -uroot -pmysql123
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.35-log 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> select user,host,plugin,authentication_string from mysql.user;
+---------------+-----------+-----------------------+-------------------------------------------+
| user | host | plugin | authentication_string |
+---------------+-----------+-----------------------+-------------------------------------------+
| root | localhost | mysql_native_password | *F861720E101148897B0F5239DB926E756B1C28B3 |
| mysql.session | localhost | mysql_native_password 20155325 2017-2018 1 《信息安全系统设计基础》第十五周学习总结

20175306《信息安全系统设计基础》第十三周学习总结

20212911陈金翔-2022-3 网络攻防实践 第十一次(第十三周)作业

20155218 《信息安全系统设计基础》课程总结

201521123116 《java程序设计》第十三周学习总结

2017-2018-1 20155302 第十三周作业