ansible+nginx

两台虚拟机
192.168.234.135
192.168.234.130

rpm -qa | grep ansible   # 检查是否有ansible的包
yum install ansible -y	 # 安装ansible
ssh-keygen -t rsa        # 创建公钥
ssh-copy-id root@192.168.234.135     # 给135拷贝密钥
ssh-copy-id root@192.168.234.130     # 给130拷贝密钥
# 拷贝完之后尝试连接一下任意一台机子
ssh root@192.168.234.130
# 修改配置文件加入ip
vim /etc/ansible/hosts
	[webservers]   	# 名字随便起
	192.168.234.135
	192.168.234.130
	:wq
# ping一下看通不通(绿色就是通了)
ansible webservers -m ping
# 创建nginx目录
mkdir lnmp
# 进入nginx目录
cd lnmp
# 拖包
nginx-1.12.0.tar.gz  # nginx包
tinyshopV2.5_data.zip # 电商包
wget http://10.30.5.70:8000/repo.sh
chmod +x repo.sh
# 解压
tar zxf nginx-1.12.0.tar.gz
cp nginx-1.12.0/conf/nginx.conf ./
# 修改nginx配置文件
vim nginx.conf
  location / {
            root   html;
            index  index.php index.htm;
        }

  location ~ \.php$ {
            root           /usr/local/nginx/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

---
- hosts: webservers
  vars:
  - nginx_user: www
  tasks:
  - name: 配置yum源
    script: repo.sh
  - name: 安装依赖环境
    yum: name=unzip,gcc,pcre-devel,zlib-devel,php,php-mysql,php-gd,mysql,mysql-server,php-fpm state=latest
  - name: 推送nginx源码包
    unarchive: src=nginx-1.12.0.tar.gz dest=/root/
  - name: 安装nginx
    shell: cd /root/nginx-1.12.0 && ./configure && make && make install
  - name: 推送配置文件
    template: src=nginx.conf dest=/usr/local/nginx/conf/nginx.conf
  - name: 创建用户
    user: name=www createhome=no shell=/sbin/nologin
  - name: 启动nginx
    shell: ss -nltp | grep -wq 80 || /usr/local/nginx/sbin/nginx
  - name: 上线电商
    unarchive: src=tinyshopV2.5_data.zip dest=/usr/local/nginx/html mode=777
  - name: 关闭防火墙
    service: name=iptables state=stopped
ansible-playbook --syntax-check lnmp.yml
ansible-playbook lnmp.yml

ansible webservers -m service -a 'name=php-fpm state=started enabled=yes'
chmod -R 777 lnmp.yml
ansible webservers -m service -a 'name=mysqld state=started enabled=yes'
ansible webservers -m shell -a 'chmod -R 777 /usr/local/nginx/html'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值