标签:add systemctl chkconfig gpg 安装 package bison rip remote
这里使用的没有联网安装 自己准备了安装包以及依赖关系(安装包都是放在了/sof,yum可以多个共存)
``
[root@localhost ~]# createrepo //sof
[root@localhost ~]# ls //sof
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# vim ansible.repo
[ansible]
name=ansible
baseurl=file:///root/app
enabled=1
gpgcheck=0
[root@localhost yum.repos.d]# yum -y install ansible
[root@localhost yum.repos.d]# ansible --version
ansible 2.4.2.0
``
生成秘钥
``ssh-keygen``
发送秘钥
``ssh-copy-id root@192.168.2.9``
尝试登陆一下是否可以免密登录
``ssh root@192.168.2.9``
注意:如果需要多台主机同时操作的话每个主机都需要传送秘钥
`/etc/ansible/hosts`
``
[mysqlserver]
192.168.2.9
192.168.2.17
192.168.2.18
``
测试一下是否可以ping通
`ansible all -m ping`
创建需要的目录
``
[root@www roles]# cd /etc/ansible/roles/
[root@www roles]# mkdir mysql
[root@www roles]# cd mysql/
[root@www mysql]# mkdir files
[root@www mysql]# mkdir handlers
[root@www mysql]# mkdir tasks
[root@www mysql]# mkdir templates
[root@www mysql]# mkdir vars
``
Files 里面存放普通文件安装包之类的(这里将mysql的安装包放到了里面)
这里只写了简单的mysql安装 所以没有使用上金甲模板和变量这些
`[root@www mysql]# vim tasks/main.yaml`
``
---
- name: yum install
yum: name=cmake,bison,ncurses-devel state=installed
- name: copy mysql
copy: src=mysql-5.5.22.tar.gz dest=/usr/src/mysql-5.5.22.tar.gz
- name: tar package
shell: cd /usr/src/ && tar -zxf mysql-5.5.22.tar.gz
- name: user add mysql
user: name=mysql shell=/sbin/nologin
- name: set mysql
shell: cd /usr/src/mysql-5.5.22 && cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc/ -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all && make && make install
- name: link mysqL
shell: ln -sf /usr/1ocal/mysql/bin/* /usr/local/bin/
- name: chown mysql
shell: chown -R mysql:mysql /usr/local/mysql/
- name: copy my
shell: cp -f /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
- name: initial mysql
shell: cd /usr/local/mysql/ && scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
- name: file mysql
shell: echo PATH=$PATH:/usr/local/mysql/bin >> /etc/profile
- name: source mysql
shell: source /etc/profile
- name: copy mysql.server
shell: cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
- name: mode mysql
file: path=/etc/rc.d/init.d/mysqld mode=755
- name: add server mysqld
shell: chkconfig --add mysqld
- name: start mysqld
shell: systemctl restart mysqld
``
``
[root@www mysql]# cd ../../
[root@www ansible]# vim mysql.yaml
``
``
---
- hosts: mysqlserver
remote_user: root
roles:
- mysql
``
``
[root@www ansible]# ansible-playbook mysql.yaml
``
标签:add systemctl chkconfig gpg 安装 package bison rip remote
原文地址:https://www.cnblogs.com/natural-baby/p/13221666.html