Ansible【自动部署phpmyadmin】

news/2024/11/7 21:06:09/
ansible10.0.0.20
lbserver10.0.0.10
web01

10.0.0.30

web0210.0.0.31
redis10.0.0.50
mysql10.0.0.60

【1】环境准备

[root@ansible ~]# mkdir phpmyadmin
[root@ansible ~]# cd phpmyadmin/
[root@ansible phpmyadmin]# cp /etc/ansible/ansible.cfg ./
[root@ansible phpmyadmin]# cp /etc/ansible/hosts ./
[defaults]
inventory      = ./hosts
......[root@ansible phpmyadmin]# vim /etc/hosts
.....
.....
10.0.0.10 lbserver
10.0.0.30 web01
10.0.0.31 web02
10.0.0.50 redis
10.0.0.60 mysql[root@ansible phpmyadmin]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.0.0.10
[root@ansible phpmyadmin]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.0.0.30
[root@ansible phpmyadmin]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.0.0.31
[root@ansible phpmyadmin]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.0.0.50
[root@ansible phpmyadmin]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.0.0.60## 主机清单
[webserver]
web01 ansible_ssh_host=10.0.0.30
web02 ansible_ssh_host=10.0.0.31[lbserver]
lbserver ansible_ssh_host=10.0.0.10[redis]
redis ansible_ssh_host=10.0.0.50[mysql]
mysql ansible_ssh_host=10.0.0.60

【2】准备web01、web02配置文件

  • nginx.conf.j2
user  www;
worker_processes  auto;error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;events {worker_connections  1024;
}http {include       /etc/nginx/mime.types;default_type  application/octet-stream;log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  /var/log/nginx/access.log  main;sendfile        on;keepalive_timeout  65;include /etc/nginx/conf.d/*.conf;
}
  •  phpmy.conf.j2
server {listen 80;server_name www.php-myadmin.org;root /code/phpmy;location / {index index.php;}location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}
  • php.ini.j2
;session.save_handler = files
session.save_handler = redis
session.save_path = "tcp://10.0.0.50:6379?&weight=1&timeout=2.5"
  • www.conf.j2
;php_value[session.save_handler] = files
;php_value[session.save_path]    = /var/lib/php/session
php_value[soap.wsdl_cache_dir]  = /var/lib/php/wsdlcache

【3】准备lb-server配置文件

  • nginx.conf.j2
user  www;
worker_processes  auto;error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;events {worker_connections  1024;
}http {include       /etc/nginx/mime.types;default_type  application/octet-stream;log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  /var/log/nginx/access.log  main;sendfile        on;keepalive_timeout  65;include /etc/nginx/conf.d/*.conf;
}
  • lb-phpmy.conf.j2
upstream phpmy {server 10.0.0.30:80;server 10.0.0.31:80;
}
server {listen 80;server_name www.php-myadmin.org;location / {proxy_pass http://phpmy;include proxy_params;}
}

proxy_params.j2

proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_connect_timeout 60s;      # nginx连接后端的超时时间
proxy_read_timeout 60s;         # 响应头部超时时间
proxy_send_timeout 60s;         # 响应数据主体的超时时间
proxy_buffering on;             # 开启缓冲区
proxy_buffer_size 8k;           # 缓冲区Header大小
proxy_buffers 4 64k;            # 缓冲区数量 * 大小 = 最大接收

【4】准备redis配置文件

  • redis.conf.j2
bind 127.0.0.1 10.0.0.50

【5】准备mysql配置文件

  • my.cnf.j2
[mysqld]
user=mysql
basedir=/usr/local/mysql
log-bin=mysql_bin
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
server_id=6
port=3306
[mysql]
socket=/tmp/mysql.sock
  • mysqld.service.j2
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
  • profile.j2
# /etc/profile# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.pathmunge () {case ":${PATH}:" in*:"$1":*);;*)if [ "$2" = "after" ] ; thenPATH=$PATH:$1elsePATH=$1:$PATHfiesac
}if [ -x /usr/bin/id ]; thenif [ -z "$EUID" ]; then# ksh workaroundEUID=`/usr/bin/id -u`UID=`/usr/bin/id -ru`fiUSER="`/usr/bin/id -un`"LOGNAME=$USERMAIL="/var/spool/mail/$USER"
fi# Path manipulation
if [ "$EUID" = "0" ]; thenpathmunge /usr/sbinpathmunge /usr/local/sbin
elsepathmunge /usr/local/sbin afterpathmunge /usr/sbin after
fiHOSTNAME=`/usr/bin/hostname 2>/dev/null`
HISTSIZE=1000
if [ "$HISTCONTROL" = "ignorespace" ] ; thenexport HISTCONTROL=ignoreboth
elseexport HISTCONTROL=ignoredups
fiexport PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL# By default, we want umask to get set. This sets it for login shell
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; thenumask 002
elseumask 022
fifor i in /etc/profile.d/*.sh ; doif [ -r "$i" ]; thenif [ "${-#*i}" != "$-" ]; then . "$i"else. "$i" >/dev/nullfifi
doneunset i
unset -f pathmunge
export PATH=/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

【5】编写playbook

- hosts: mysqltasks:- name: Install Mysqlunarchive:src: ./file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gzdest: /usr/local/owner: rootgroup: rootmode: '0755'creates: /usr/local/mysql- name: aliasshell:cmd: mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysqlcreates: /usr/local/mysql- name: Configure Exportcopy:src: ./file/profile.j2dest: /etc/profileowner: rootgroup: rootmode: '644'- name: Sourceshell: source /etc/profile- name: Groupaddgroup:name: mysqlgid: '777'state: present- name: Useradduser:name: mysqluid: '777'group: '777'shell: /sbin/nologincreate_home: falsesystem: truestate: present- name: Data Dirfile:path: /usr/local/mysql/dataowner: mysqlgroup: mysqlstate: directorymode: '0755'recurse: yes- name: Init Mysqlshell:cmd: /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/datacmd: echo "111" >> /usr/local/mysql/data/111creates: /usr/local/mysql/data/111- name: Cp Commandshell:cmd: cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldcreates: /etc/init.d/mysqld- name: Configure Mysqlcopy:src: ./file/my.cnf.j2dest: /etc/my.cnfowner: rootgroup: rootmode: '0644'notify: Restart Mysql- name: System Mysqlcopy:src: ./file/mysqld.service.j2dest: /etc/systemd/system/mysqld.serviceowner: rootgroup: rootmode: '0644'notify: Daemon-reload- name: Start Mysqlsystemd:name: mysqldstate: startedenabled: yeshandlers:- name: Restart Mysqlsystemd:name: mysqldstate: restarted- name: Daemon-reloadsystemd:state: daemon-reload- hosts: redistasks:- name: Install Redis yum:name: redisstate: present- name: Configure Rediscopy:src: ./file/redis.conf.j2dest: /etc/redis.confowner: redisgroup: redismode: '0640'notify: Restart Redis- name: Start Redissystemd:name: redisstate: startedenabled: yeshandlers:- name: Restart Redissystemd:name: redisstate: restarted- hosts: webservertasks:- name: Nginx Repoyum_repository:name: ansible_nginxdescription: ansible_nginx_repobaseurl: http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck: nogpgkey: https://nginx.org/keys/nginx_signing.key- name: PHP Repoyum_repository:name: ansible_phpdescription: ansible__php_repobaseurl: http://us-east.repo.webtatic.com/yum/el7/x86_64/gpgcheck: no- name: Install Nginx PHPyum:name: "{{ packages }}"state: presentvars:packages:- nginx- php71w- php71w-cli- php71w-common- php71w-devel- php71w-embedded- php71w-gd- php71w-mcrypt- php71w-mbstring- php71w-pdo- php71w-xml- php71w-fpm- php71w-mysqlnd- php71w-opcache- php71w-pecl-memcached- php71w-pecl-redis- php71w-pecl-mongodb- name: Configure Nginx.confcopy:src: ./file/nginx.conf.j2dest: /etc/nginx/nginx.confowner: rootgroup: rootmode: '0644'notify: Restart Nginx      - name: Configure Nginx phpmy.confcopy:src: ./file/phpmy.conf.j2dest: /etc/nginx/conf.d/phpmy.confowner: rootgroup: rootmode: '0644'notify: Restart Nginx- name: Configure PHP WWW.CONFcopy:src: ./file/www.conf.j2dest: /etc/php-fpm.d/www.confowner: rootgroup: rootmode: '0644'notify: Restart PHP- name: Configure PHP.inicopy: src: ./file/php.ini.j2dest: /etc/php.iniowner: rootgroup: rootmode: '0644'notify: Restart PHP- name: Groupadd wwwgroup:name: wwwgid: 666state: present- name: Useradd wwwuser:name: wwwuid: 666group: 666shell: /sbin/nologincreate_home: falsesystem: truestate: present- name: Code Dirfile:path: /codeowner: wwwgroup: wwwstate: directorymode: '0755'- name: Unzip phpmyadminunarchive:src: ./file/phpMyAdmin-4.9.11-all-languages.zipdest: /code/owner: wwwgroup: wwwmode: '0755'creates: /code/phpMyAdmin-4.9.11-all-languages- name: Linkshell:cmd: ln -s /code/phpMyAdmin-4.9.11-all-languages /code/phpmycreates: /code/phpmy- name: Configure phpmycopy:src: ./file/config.sample.inc.php.j2dest: /code/phpmy/config.inc.phpowner: wwwgroup: wwwmode: '0644'- name: Sessionshell:cmd: chown -R www.www /var/lib/php/session/- name: Start Nginxsystemd:name: nginxstate: startedenabled: yes- name: Start PHPsystemd:name: php-fpmstate: startedenabled: yeshandlers:- name: Restart Nginxsystemd:name: nginxstate: restarted- name: Restart PHPsystemd:name: php-fpmstate: restarted- hosts: lbservertasks:- name: Nginx Repoyum_repository:name: ansible_nginxdescription: ansible_nginx_repobaseurl: http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck: nogpgkey: https://nginx.org/keys/nginx_signing.key- name: Install Nginxyum:name: nginxstate: present- name: Configure Nginxcopy:src: ./file/nginx.conf.j2dest: /etc/nginx/nginx.confowner: rootgroup: rootmode: '0644'notify: Restart Nginx- name: Configure lbcopy:src: ./file/lb-phpmy.conf.j2dest: /etc/nginx/conf.d/lb-phpmy.confowner: rootgroup: rootmode: '0644'notify: Restart Nginx- name: Configure Paramscopy:src: ./file/proxy_params.j2dest: /etc/nginx/proxy_paramsowner: rootgroup: rootmode: '0644'notify: Restart Nginx- name: Groupadd wwwgroup:name: wwwgid: 666state: present- name: Useradd wwwuser:name: wwwuid: 666group: 666shell: /sbin/nologincreate_home: falsesystem: truestate: present- name: Start Nginxsystemd:name: nginxstate: startedenabled: yeshandlers:- name: Restart Nginxsystemd:name: nginxstate: restarted


http://www.ppmy.cn/news/560043.html

相关文章

Redis:redis基于各大实战场景下的基本使用

文章目录 前言String 命令实战1.业务缓存对应redis中的指令伪代码 2.分布式锁对应redis中的指令伪代码 3.限流对应redis中的指令伪代码 List 命令实战1.提醒功能对应Redis中的指令伪代码 2.热点列表对应Redis中的指令伪代码 Hash 命令实战1.用户资料缓存对应redis中的指令伪代码…

win10查看端口是否被占用,被哪一个程序占用(图文)

window系统中有时候我们会出现需要的端口号被占用,但不知道具体是哪个程序占用的。这时我们需要找到使用此端口的程序。 方法如下: 1)以管理员身份打开命令提示符窗口(开始-运行)。 2)使用命令查看端口使…

h5手写签名示例

前言 业务中需要用户进行签字&#xff0c;如何让用户在手机端进行签字&#xff1f; 示例如下 代码已分享至Gitee: https://gitee.com/lengcz/qianming 原示例&#xff1a; https://www.jq22.com/jquery-info13488 H5实现手写签字 创建一个html页面 <!DOCTYPE html> …

用FlashCache加速MySQL

SSD与FlashCaceh相关参考资料推荐&#xff1a; 《Mysql基于SSD_flashcache优化实践》 《SSD RAID卡和PCI-E flash卡在淘宝的应用实践》 《淘宝商品库MySQL优化实践》 《混合存储测试结果》 国内的姜承尧开发一个INNODB的二级缓存&#xff08;InnoDB Secondary Buffer Pool)&am…

5G加速卡

加速卡概念 加速卡的作用就是为CPU“减负”。 CPU专为顺序串行处理设计&#xff0c;FPGA/GPU的核心专为同时处理多任务而设计。FPGA/GPU包含普通CPU更多的处理单元、更大的带宽&#xff0c;在处理过程中能够发挥更大的效能。 加速卡的工作机理如下&#xff1a; 1&#xff09;C…

NorFlash的存储原理

NorFlash是E2PROM中的一种&#xff0c;利用特殊的浮栅MOS场效应晶体管进行编程。它是一个 N 沟道增强型的 MOS 管&#xff0c;有 Gf 和 Gc 两个栅极。 Gc 为控制栅&#xff0c;它有引出线。 Gf 栅极没有引出线&#xff0c;而是被包围在二氧化硅中&#xff0c;称之为浮栅&#x…

英飞凌 AURIX TC3XX 系列单片机的 NVM-Flash 功能代码实现

前言 上一篇介绍了 Flash 的一些基本知识,这一篇主要如何进一步封装 illD 库的Flash驱动代码,并进行使用。以 TC37X 为例子,附完整代码实现。 通过封装可以快速上手使用,同时在一定程度上提高 Flash 的使用寿命 接口设计 根据PFlash和DFlash的擦除特性,PFlash擦除后不能…

加速基于flash的嵌入式应用程序

大多数现代嵌入式软件应用程序都是从闪存存储和执行的。闪存为基于微控制器的应用程序提供了一种廉价且快速的存储介质。但这些应用程序通常是实时应用程序&#xff0c;其中执行时间和确定性行为至关重要。虽然闪存速度很快&#xff0c;但不如从RAM执行代码快。为了加快基于fla…