日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Ansible Playbook企业案例:利用 playbook 安装 nginx、安装和卸载 httpd、安装mysql

發(fā)布時間:2025/1/21 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Ansible Playbook企业案例:利用 playbook 安装 nginx、安装和卸载 httpd、安装mysql 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

playbook 命令

格式

ansible-playbook <filename.yml> ... [options]

常見選項

-C --check #只檢測可能會發(fā)生的改變,但不真正執(zhí)行操作 --list-hosts #列出運行任務(wù)的主機 --list-tags #列出tag --list-tasks #列出task --limit 主機列表 #只針對主機列表中的主機執(zhí)行 -v -vv -vvv #顯示過程

范例

ansible-playbook file.yml --check #只檢測 ansible-playbook file.yml ansible-playbook file.yml --limit websrvs

Playbook 初步

利用 playbook 創(chuàng)建 mysql 用戶

范例:mysql_user.yml

--- - hosts: dbsrvsremote_user: roottasks:- {name: create group, group: name=mysql system=yes gid=306}- name: create useruser: name=mysql shell=/sbin/nologin system=yes group=mysql uid=306 home=/data/mysql create_home=no
利用 playbook 安裝 nginx

范例:install_nginx.yml

--- # install nginx - hosts: websrvsremote_user: root tasks:- name: add group nginxuser: name=nginx state=present- name: add user nginxuser: name=nginx state=present group=nginx- name: Install Nginxyum: name=nginx state=present- name: web pagecopy: src=files/index.html dest=/usr/share/nginx/html/index.html- name: Start Nginxservice: name=nginx state=started enabled=yes
利用 playbook 安裝和卸載 httpd

范例:install_httpd.yml

--- #install httpd - hosts: websrvsremote_user: rootgather_facts: notasks:- name: Install httpdyum: name=httpd state=present- name: Install configure filecopy: src=files/httpd.conf dest=/etc/httpd/conf/- name: web htmlcopy: src=files/index.html dest=/var/www/html/- name: start serviceservice: name=httpd state=started enabled=yesansible-playbook install_httpd.yml --limit 10.0.0.8

范例:remove_httpd.yml

#remove_httpd.yml --- - hosts: websrvsremote_user: roottasks:- name: remove httpd packageyum: name=httpd state=absent- name: remove apache user user: name=apache state=absent- name: remove config filefile: name=/etc/httpd state=absent- name: remove web htmlfile: name=/var/www/html/index.html state=absent
利用 playbook 安裝mysql

范例:安裝mysql-5.6.46-linux-glibc2.12

[root@ansible ~]#ls -l /data/ansible/files/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz -rw-r--r-- 1 root root 403177622 Dec 4 13:05 /data/ansible/files/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz[root@ansible ~]#cat /data/ansible/files/my.cnf [mysqld] socket=/tmp/mysql.sock user=mysql symbolic-links=0 datadir=/data/mysql innodb_file_per_table=1 log-bin pid-file=/data/mysql/mysqld.pid[client] port=3306 socket=/tmp/mysql.sock[mysqld_safe] log-error=/var/log/mysqld.log[root@ansible ~]#cat /data/ansible/files/secure_mysql.sh #!/bin/bash /usr/local/mysql/bin/mysql_secure_installation <<EOFy magedu magedu y y y y EOF[root@ansible ~]#tree /data/ansible/files/ /data/ansible/files/ ├── my.cnf ├── mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz └── secure_mysql.sh0 directories, 3 files[root@ansible ~]#cat /data/ansible/install_mysql.yml --- # install mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz - hosts: dbsrvsremote_user: rootgather_facts: notasks:- name: install packagesyum: name=libaio,perl-Data-Dumper,perl-Getopt-Long- name: create mysql groupgroup: name=mysql gid=306 - name: create mysql useruser: name=mysql uid=306 group=mysql shell=/sbin/nologin system=yes create_home=no home=/data/mysql- name: copy tar to remote host and file mode unarchive: src=/data/ansible/files/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz dest=/usr/local/ owner=root group=root - name: create linkfile /usr/local/mysql file: src=/usr/local/mysql-5.6.46-linux-glibc2.12-x86_64 dest=/usr/local/mysql state=link- name: data dirshell: chdir=/usr/local/mysql/ ./scripts/mysql_install_db --datadir=/data/mysql --user=mysqltags: data- name: config my.cnfcopy: src=/data/ansible/files/my.cnf dest=/etc/my.cnf - name: service scriptshell: /bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld- name: enable serviceshell: /etc/init.d/mysqld start;chkconfig --add mysqld;chkconfig mysqld on tags: service- name: PATH variablecopy: content='PATH=/usr/local/mysql/bin:$PATH' dest=/etc/profile.d/mysql.sh- name: secure scriptscript: /data/ansible/files/secure_mysql.shtags: script

范例:install_mariadb.yml

--- #Installing MariaDB Binary Tarballs - hosts: dbsrvsremote_user: rootgather_facts: notasks:- name: create groupgroup: name=mysql gid=27 system=yes- name: create useruser: name=mysql uid=27 system=yes group=mysql shell=/sbin/nologin home=/data/mysql create_home=no- name: mkdir datadirfile: path=/data/mysql owner=mysql group=mysql state=directory- name: unarchive packageunarchive: src=/data/ansible/files/mariadb-10.2.27-linux-x86_64.tar.gz dest=/usr/local/ owner=root group=root- name: linkfile: src=/usr/local/mariadb-10.2.27-linux-x86_64 path=/usr/local/mysql state=link - name: install databaseshell: chdir=/usr/local/mysql ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql- name: config filecopy: src=/data/ansible/files/my.cnf dest=/etc/ backup=yes- name: service scriptshell: /bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld- name: start serviceservice: name=mysqld state=started enabled=yes- name: PATH variablecopy: content='PATH=/usr/local/mysql/bin:$PATH' dest=/etc/profile.d/mysql.sh

本文鏈接:http://www.yunweipai.com/34658.html

總結(jié)

以上是生活随笔為你收集整理的Ansible Playbook企业案例:利用 playbook 安装 nginx、安装和卸载 httpd、安装mysql的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。