运维自动化之ansible playbook安装mysql
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了运维自动化之ansible playbook安装mysql,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4971字,纯文字阅读大概需要8分钟。
内容图文
![运维自动化之ansible playbook安装mysql](/upload/InfoBanner/zyjiaocheng/452/ed2d62ef9db1492b8a3fa7051d66dba3.jpg)
[root@ansible roles]# pwd /etc/ansible/roles [root@ansible roles]# mkdir -p mysql_install/{files,handlers,meta,tasks,templates,vars} [root@ansible roles]# tree mysql_install/ mysql_install/ ├── files ├── handlers ├── meta ├── tasks ├── templates └── vars
2.创建需要用到的vars
[root@ansible roles]# cat /etc/ansible/roles/mysql_install/vars/main.yml mysql_version: mysql-5.5.37
3.创建远程安装脚本
[root@ansible roles]# cat /etc/ansible/roles/mysql_install/templates/mysql_install.sh #!/bin/bash DATADIR=‘/data/mysql/data‘ VERSION=‘{{mysql_version}}‘ export LANG=zh_CN.UTF-8 #Source function library. . /etc/init.d/functions #camke install mysql5.5.X install_mysql(){ #read -p "please input a password for root: " PASSWD PASSWD=‘ly36843‘ if [ ! -d $DATADIR ];then mkdir -p $DATADIR fi yum install cmake make gcc-c++ bison-devel ncurses-devel -y id mysql &>/dev/null if [ $? -ne 0 ];then useradd mysql -s /sbin/nologin -M fi #useradd mysql -s /sbin/nologin -M #change datadir owner to mysql chown -R mysql.mysql $DATADIR cd #wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.38.tar.gz tar xf $VERSION.tar.gz cd $VERSION cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/$VERSION -DMYSQL_DATADIR=$DATADIR -DMYSQL_UNIX_ADDR=$DATADIR/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 make && make install if [ $? -ne 0 ];then action "install mysql is failed!" /bin/false exit $? fi sleep 2 #link ln -s /usr/local/$VERSION/ /usr/local/mysql ln -s /usr/local/mysql/bin/* /usr/bin/ #copy config and start file /bin/cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chmod 700 /etc/init.d/mysqld #init mysql /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=$DATADIR --user=mysql if [ $? -ne 0 ];then action "install mysql is failed!" /bin/false exit $? fi #check mysql /etc/init.d/mysqld start if [ $? -ne 0 ];then action "mysql start is failed!" /bin/false exit $? fi chkconfig --add mysqld chkconfig mysqld on /usr/local/mysql/bin/mysql -e "update mysql.user set password=password(‘$PASSWD‘) where host=‘localhost‘ and user=‘root‘;" /usr/local/mysql/bin/mysql -e "update mysql.user set password=password(‘$PASSWD‘) where host=‘127.0.0.1‘ and user=‘root‘;" /usr/local/mysql/bin/mysql -e "delete from mysql.user where password=‘‘;" /usr/local/mysql/bin/mysql -e "flush privileges;" #/usr/local/mysql/bin/mysql -e "select version();" >/dev/null 2>&1 if [ $? -eq 0 ];then echo "+---------------------------+" echo "+------mysql安装完成--------+" echo "+---------------------------+" fi #/etc/init.d/mysqld stop } install_mysql
4.创建任务
复制文件
[root@ansible roles]# cat /etc/ansible/roles/mysql_install/tasks/copy.yml - name: copy mysql source code to client copy: src={{mysql_version}}.tar.gz dest=/root/{{mysql_version}}.tar.gz owner=root group=root - name: copy mysql install script to client template: src=mysql_install.sh dest=/root/mysql_install.sh owner=root group=root mode=0755
解压安装
[root@ansible roles]# cat /etc/ansible/roles/mysql_install/tasks/install.yml - name: install mysql shell: /bin/sh /root/mysql_install.sh
创建包含文件
[root@ansible roles]# cat /etc/ansible/roles/mysql_install/tasks/main.yml - include: copy.yml - include: install.yml
最后的playbook结构是
[root@ansible roles]# tree /etc/ansible/roles/mysql_install/ /etc/ansible/roles/mysql_install/ ├── files │ └── mysql-5.5.37.tar.gz ├── handlers ├── meta ├── tasks │ ├── copy.yml │ ├── install.yml │ └── main.yml ├── templates │ └── mysql_install.sh └── vars └── main.yml
5.创建mysql的playbook配置文件
[root@ansible ~]# cat /etc/ansible/mysql_server_install.yml - hosts: mysql remote_user: root gather_facts: False roles: - mysql_install
本文出自 “ly36843运维” 博客,请务必保留此出处http://ly36843.blog.51cto.com/3120113/1671314
运维自动化之ansible playbook安装mysql
标签:运维自动化之ansible playbook安装mysql
本文系统来源:http://ly36843.blog.51cto.com/3120113/1671314
内容总结
以上是互联网集市为您收集整理的运维自动化之ansible playbook安装mysql全部内容,希望文章能够帮你解决运维自动化之ansible playbook安装mysql所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。