通过ansible roles配置lnmp环境,nginx通过源码编译安装,php通过源码编译安装,MySQL通过yum安装(mysql源码编译超级慢)支持系统(CentOS6.x和centos7.x系列)
说明: 将nginx和php源码包放到对应的角色文件下的files目录下,通过vars/main.yml控制安装的版本和路径。如下:
[root@ansible roles]# cat nginx/vars/main.yml DOWNLOAD_DIR: "/usr/local/src/" #软件包拷贝到目标主机的存放路径 INSTALL_DIR: "/usr/local/" #安装路径 NGINX_VERSION: "1.12.2" #软件包版本 USER: "nginx" #运行的用户 GROUP: "nginx" #运行的组
角色编写这里角色都统一放在了/etc/ansible/roles下
安装编译时所需要用到的依赖包
[root@ansible ~]# cd /etc/ansible/roles/
[root@ansible roles]# cat init_pkg.yml #安装源码编译php、nginx时所需要用到的依赖包 --- - hosts: all remote_user: root tasks: - name: Install Package yum: name={{ item }} state=installed with_items: - gcc-c++ - glibc - glibc-devel - glib2 - glib2-devel - pcre - pcre-devel - zlib - zlib-devel - openssl - openssl-devel - libpng - libpng-devel - freetype - freetype-devel - libxml2 - libxml2-devel - bzip2 - bzip2-devel - ncurses - curl - gdbm-devel - libXpm-devel - libX11-devel - gd-devel - gmp-devel - readline-devel - libxslt-devel - expat-devel - xmlrpc-c - libcurl-devel
nginx roles1)创建相应文件夹
[root@ansible roles]# mkdir -p nginx/{files,handlers,tasks,templates,vars}
2)最终编写效果
[root@ansible roles]# tree nginx nginx ├── files │ ├── nginx-1.12.2.tar.gz │ └── nginx-1.16.0.tar.gz ├── handlers │ └── main.yml ├── tasks │ ├── config.yml │ ├── copypkg.yml │ ├── group.yml │ ├── install.yml │ ├── main.yml │ ├── service.yml │ └── user.yml ├── templates │ ├── nginx.conf.j2 │ ├── nginx_init.j2 │ └── nginx.service.j2 └── vars └── main.yml 5 directories, 14 files
php roles1)创建相应文件夹
[root@ansible roles]# mkdir -p php/{files,handlers,tasks,templates,vars}
2)最终编写效果
[root@ansible roles]# tree php php ├── files │ └── php-5.6.40.tar.gz ├── handlers │ └── main.yml ├── tasks │ ├── config.yml │ ├── copypkg.yml │ ├── group.yml │ ├── install.yml │ ├── main.yml │ ├── service.yml │ └── user.yml ├── templates │ ├── php-fpm.conf.j2 │ ├── php-fpm.init.j2 │ ├── php-fpm.service.j2 │ └── php.ini.j2 └── vars └── main.yml 5 directories, 14 files
mysql roles1)创建相应文件夹
[root@ansible roles]# mkdir -p mysql/{files,handlers,tasks,templates,vars}
2)最终编写效果
[root@ansible roles]# tree mysql mysql ├── files ├── handlers │ └── main.yml ├── tasks │ ├── config.yml │ ├── install.yml │ ├── main.yml │ └── service.yml ├── templates │ ├── my.cnf6.j2 │ └── my.cnf7.j2 └── vars 5 directories, 7 files
角色执行playbook文件编写