首先在主服务器上搭建ansible直接用云yum装就可以,

yum -y install ansible

如果copy报错一下的语句 "msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!"

需要在被分发的服务器上安装支持包

[root@www ~]# mount /dev/sr0 /media/cdrom/
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@www ~]# yum -y install libselinux-python

然后建立roles的标准化模块相应的目录

[root@ansible myroles]# tree /myroles/
/myroles/
├── nginx.yaml #nginx模组入口配置文件
└── roles
└── nginx #nginx原型模组目录
├── files
├── handlers
├── tasks
│ └── main.yaml #nginx模组的tasks任务配置文件
├── templates
└── vars
directories, files

Nginx的剧本书写,在myroles里,跟roles同级

---
- hosts: all
gather_facts: True
roles:
- nginx

然后在Nginx目录下files目录里放置安装包和,安装脚本文件

nginx的搭建脚本

#!/bin/bash
mkdir -p /media/cdrom
umount /dev/sr0 &>/dev/null
mount /dev/sr0 /media/cdrom &>/dev/null
dir=/etc/yum.repos.d
[ -d $dir ] || mkdir -p $dir
cd $dir
mv * /tmp/
cat >/etc/yum.repos.d/local.repo << KOF
[local]
name=localrepo
baseurl=file:///media/cdrom/
KOF
yum -y clean all &>/dev/null
[ $? -eq ] || echo "clean erro"
yum makecache &>/dev/null || echo "erro cache" which "wget"
[ $? -eq ] || /usr/bin/yum -y install wget &>/dev/null
/usr/bin/wget http://mirrors.aliyun.com/repo/epel-6.repo
[ $? -eq ] || (/bin/echo "yun源出错" && exit)
/usr/bin/yum -y clean all &>/dev/null
/usr/bin/yum makecache &>/dev/null
[ $? -eq ] || (/bin/echo "yun缓存错误" && exit)
/usr/bin/yum -y install pcre-deved openssl-devel &>/dev/null
[ $? -eq ] || /bin/echo "pcre error"
useradd -M -s /sbin/nologin nginx &>dev/null
cd ~
tar xf nginx-1.10..tar.gz -C /usr/src/
cd /usr/src/nginx-1.10./
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.10./ --with-http_stub_status_module --with-http_ssl_module && make && make install &>/dev/null

在tasks里创建个main.yaml主要任务剧本

- name: t1
copy: src=nginx-1.10..tar.gz dest=/root/
register: ttt
- debug: var=ttt
- name: t2
script: nginx.sh
register: rrr
- debug: var=rrr

回到mysoles里执行nginx.yaml剧本

[root@bogon myroles]# ansible-playbook nginx.yaml 

PLAY [all] *************************************************************************************************

TASK [Gathering Facts] *************************************************************************************
ok: [web1]
ok: [web2] TASK [nginx : t1] ******************************************************************************************
ok: [web2]
ok: [web1] TASK [nginx : debug] ***************************************************************************************
ok: [web1] => {
"ttt": {
"changed": false,
"checksum": "1bafb1557b8d5f992714c0dcbde77036bde98547",
"dest": "/root/nginx-1.10.2.tar.gz",
"diff": {
"after": {
"path": "/root/nginx-1.10.2.tar.gz"
},
"before": {
"path": "/root/nginx-1.10.2.tar.gz"
}
},
"failed": false,
"gid": ,
"group": "root",
"mode": "",
"owner": "root",
"path": "/root/nginx-1.10.2.tar.gz",
"secontext": "unconfined_u:object_r:admin_home_t:s0",
"size": ,
"state": "file",
"uid":
}
}
ok: [web2] => {
"ttt": {
"changed": false,
"checksum": "1bafb1557b8d5f992714c0dcbde77036bde98547",
"dest": "/root/nginx-1.10.2.tar.gz",
"diff": {
"after": {
"path": "/root/nginx-1.10.2.tar.gz"
},
"before": {
"path": "/root/nginx-1.10.2.tar.gz"
}
},
"failed": false,
"gid": ,
"group": "root",
"mode": "",
"owner": "root",
"path": "/root/nginx-1.10.2.tar.gz",
"secontext": "unconfined_u:object_r:admin_home_t:s0",
"size": ,
"state": "file",
"uid":
}
} TASK [nginx : t2] ******************************************************************************************
changed: [web2]
changed: [web1] TASK [nginx : debug] ***************************************************************************************
ok: [web1] => {
"rrr": {
"changed": true,
"failed": false,
"rc": ,
"stderr": "Shared connection to 192.168.200.131 closed.\r\n",
"stderr_lines": [
"Shared connection to 192.168.200.131 closed."
],
"stdout": "/usr/bin/wget\r\n--2018-11-12 19:02:03-- http://mirrors.aliyun.com/repo/epel-6.repo\r\nResolving mirrors.aliyun.com... failed: Name or service not known.\r\nwget: unable to resolve host address “mirrors.aliyun.com”\r\nyun源出错\r\n",
"stdout_lines": [
"/usr/bin/wget",
"--2018-11-12 19:02:03-- http://mirrors.aliyun.com/repo/epel-6.repo",
"Resolving mirrors.aliyun.com... failed: Name or service not known.",
"wget: unable to resolve host address “mirrors.aliyun.com”",
"yun源出错"
]
}
}
ok: [web2] => {
"rrr": {
"changed": true,
"failed": false,
"rc": ,
"stderr": "Shared connection to 192.168.200.133 closed.\r\n",
"stderr_lines": [
"Shared connection to 192.168.200.133 closed."
],
"stdout": "/usr/bin/wget\r\n--2018-11-12 16:03:20-- http://mirrors.aliyun.com/repo/epel-6.repo\r\nResolving mirrors.aliyun.com... 122.72.3.220, 122.72.3.219, 122.72.3.221, ...\r\nConnecting to mirrors.aliyun.com|122.72.3.220|:80... connected.\r\nHTTP request sent, awaiting response... 200 OK\r\nLength: 664 [application/octet-stream]\r\nSaving to: “epel-6.repo”\r\n\r\n\r 0% [ ] 0 --.-K/s \r100%[======================================>] 664 --.-K/s in 0s \r\n\r\n2018-11-12 16:03:21 (62.4 MB/s) - “epel-6.repo” saved [664/664]\r\n\r\n",
"stdout_lines": [
"/usr/bin/wget",
"--2018-11-12 16:03:20-- http://mirrors.aliyun.com/repo/epel-6.repo",
"Resolving mirrors.aliyun.com... 122.72.3.220, 122.72.3.219, 122.72.3.221, ...",
"Connecting to mirrors.aliyun.com|122.72.3.220|:80... connected.",
"HTTP request sent, awaiting response... 200 OK",
"Length: 664 [application/octet-stream]",
"Saving to: “epel-6.repo”",
"",
"",
" 0% [ ] 0 --.-K/s ",
"100%[======================================>] 664 --.-K/s in 0s ",
"",
"2018-11-12 16:03:21 (62.4 MB/s) - “epel-6.repo” saved [664/664]",
""
]
}
} PLAY RECAP *************************************************************************************************
web1 : ok= changed= unreachable= failed=
web2 : ok= changed= unreachable= failed=

这样Nginx服务就先简单的搭建成功,需要主要目前没有任何的配置文件和启动服务

接下来我搭建mysql

roles的模板,

[root@bogon ~]# tree /myroles/
/myroles/
├── mysql.retry
├── mysql.yaml
├── nginx.retry
├── nginx.yaml
└── roles
├── mysql
│?? ├── files
│?? │?? ├── mysql-5.5.-linux2.-x86_64.tar.gz
│?? │?? ├── mysql.sh
│?? │?? └── yum.sh
│?? ├── handlers
│?? ├── tasks
│?? │?? └── main.yaml
│?? ├── templates
│?? └── vars
├── nginx
│?? ├── files
│?? │?? ├── nginx-1.10..tar.gz
│?? │?? └── nginx.sh
│?? ├── handlers
│?? ├── tasks
│?? │?? └── main.yaml
│?? ├── templates
│?? └── vars
└── php
├── files
├── handlers
├── tasks
├── templates
└── vars

mysql.yaml的内容

---
- hosts: all
gather_facts: True
roles:
- mysql

tasks里边的任务

[root@bogon tasks]# vim main.yaml 

- name: t1
copy: src=mysql-5.5.-linux2.-x86_64.tar.gz dest=/root/
register: ttt
- debug: var=ttt
#- name: yum
# script: yum.sh
# register: zzz
#- debug: var=zzz
- name: t2
script: mysql.sh
register: rrr
- debug: var=rrr
~

files里边的脚本

yum的脚本

#!/bin/bash
mkdir -p /media/cdrom
umount /dev/sr0 &>/dev/null
mount /dev/sr0 /media/cdrom &>/dev/null
dir=/etc/yum.repos.d
[ -d $dir ] || mkdir -p $dir
cd $dir
mv * /tmp/
cat >/etc/yum.repos.d/local.repo << KOF
[local]
name=localrepo
baseurl=file:///media/cdrom/
KOF
yum -y clean all &>/dev/null
[ $? -eq ] || echo "clean erro"
yum makecache &>/dev/null || echo "erro cache"
which "wget"
[ $? -eq ] || /usr/bin/yum -y install wget &>/dev/null
/usr/bin/wget http://mirrors.aliyun.com/repo/epel-6.repo
[ $? -eq ] || (/bin/echo "yun源出错" && exit)
/usr/bin/yum -y clean all &>/dev/null
/usr/bin/yum makecache &>/dev/null
[ $? -eq ] || (/bin/echo "yun缓存错误" && exit)
/usr/bin/yum -y install pcre-deved openssl-devel &>/dev/null
[ $? -eq ] || /bin/echo "pcre error"

mysl的安装脚本(需要注意的是这里使用的是二进制压缩包,简单的脚本,不严谨,可以执行成功)

#!/bin/bash
groupadd mysql
useradd -s /sbin/nologin -g mysql -M mysql
cd ~
tar xf mysql-5.5.-linux2.-x86_64.tar.gz -C /usr/local/
cd /usr/local/
mv mysql-5.5.-linux2.-x86_64 mysql-5.5.
ln -s mysql-5.5. mysql
[ -d /usr/local/mysql/data ] || mkdir -p /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql
yum -y install libaio
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
cd /usr/local/mysql
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start

执行mysql剧本

[root@bogon myroles]# ansible-playbook mysql.yaml
[root@bogon myroles]# ansible-playbook mysql.yaml 

PLAY [all] *****************************************************************************************************************************************************************

TASK [Gathering Facts] *****************************************************************************************************************************************************
ok: [web1] TASK [mysql : t1] **********************************************************************************************************************************************************
ok: [web1] TASK [mysql : debug] *******************************************************************************************************************************************************
ok: [web1] => {
"ttt": {
"changed": false,
"checksum": "1861329e637aca5e143c436fd795d28ed8f10729",
"dest": "/root/mysql-5.5.32-linux2.6-x86_64.tar.gz",
"diff": {
"after": {
"path": "/root/mysql-5.5.32-linux2.6-x86_64.tar.gz"
},
"before": {
"path": "/root/mysql-5.5.32-linux2.6-x86_64.tar.gz"
}
},
"failed": false,
"gid": ,
"group": "root",
"mode": "",
"owner": "root",
"path": "/root/mysql-5.5.32-linux2.6-x86_64.tar.gz",
"secontext": "system_u:object_r:admin_home_t:s0",
"size": ,
"state": "file",
"uid":
}
} TASK [mysql : t2] **********************************************************************************************************************************************************
changed: [web1] TASK [mysql : debug] *******************************************************************************************************************************************************
ok: [web1] => {
"rrr": {
"changed": true,
"failed": false,
"rc": ,
"stderr": "Shared connection to 192.168.200.131 closed.\r\n",
"stderr_lines": [
"Shared connection to 192.168.200.131 closed."
],
"stdout": "groupadd: group 'mysql' already exists\r\nuseradd: user 'mysql' already exists\r\nmv: cannot move `mysql-5.5.32-linux2.6-x86_64' to `mysql-5.5.32/mysql-5.5.32-linux2.6-x86_64': Directory not empty\r\nln: creating symbolic link `mysql/mysql-5.5.32': File exists\r\nLoaded plugins: fastestmirror\r\nLoading mirror speeds from cached hostfile\r\nSetting up Install Process\r\nPackage libaio-0.3.107-10.el6.x86_64 already installed and latest version\r\nNothing to do\r\nInstalling MySQL system tables...\r\nOK\r\nFilling help tables...\r\nOK\r\n\r\nTo start mysqld at boot time you have to copy\r\nsupport-files/mysql.server to the right place for your system\r\n\r\nPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !\r\nTo do so, start the server, then issue the following commands:\r\n\r\n/usr/local/mysql/bin/mysqladmin -u root password 'new-password'\r\n/usr/local/mysql/bin/mysqladmin -u root -h www.sunan.com password 'new-password'\r\n\r\nAlternatively you can run:\r\n/usr/local/mysql/bin/mysql_secure_installation\r\n\r\nwhich will also give you the option of removing the test\r\ndatabases and anonymous user created by default. This is\r\nstrongly recommended for production servers.\r\n\r\nSee the manual for more instructions.\r\n\r\nYou can start the MySQL daemon with:\r\ncd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &\r\n\r\nYou can test the MySQL daemon with mysql-test-run.pl\r\ncd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl\r\n\r\nPlease report any problems with the /usr/local/mysql/scripts/mysqlbug script!\r\n\r\nStarting MySQL SUCCESS! \r\n",
"stdout_lines": [
"groupadd: group 'mysql' already exists",
"useradd: user 'mysql' already exists",
"mv: cannot move `mysql-5.5.32-linux2.6-x86_64' to `mysql-5.5.32/mysql-5.5.32-linux2.6-x86_64': Directory not empty",
"ln: creating symbolic link `mysql/mysql-5.5.32': File exists",
"Loaded plugins: fastestmirror",
"Loading mirror speeds from cached hostfile",
"Setting up Install Process",
"Package libaio-0.3.107-10.el6.x86_64 already installed and latest version",
"Nothing to do",
"Installing MySQL system tables...",
"OK",
"Filling help tables...",
"OK",
"",
"To start mysqld at boot time you have to copy",
"support-files/mysql.server to the right place for your system",
"",
"PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !",
"To do so, start the server, then issue the following commands:",
"",
"/usr/local/mysql/bin/mysqladmin -u root password 'new-password'",
"/usr/local/mysql/bin/mysqladmin -u root -h www.sunan.com password 'new-password'",
"",
"Alternatively you can run:",
"/usr/local/mysql/bin/mysql_secure_installation",
"",
"which will also give you the option of removing the test",
"databases and anonymous user created by default. This is",
"strongly recommended for production servers.",
"",
"See the manual for more instructions.",
"",
"You can start the MySQL daemon with:",
"cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &",
"",
"You can test the MySQL daemon with mysql-test-run.pl",
"cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl",
"",
"Please report any problems with the /usr/local/mysql/scripts/mysqlbug script!",
"",
"Starting MySQL SUCCESS! "
]
}
} PLAY RECAP *****************************************************************************************************************************************************************
web1 : ok= changed= unreachable= failed=

如果报错ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

是说明找不到sockt启动文件,第一个办法是修改配置文件的路径,

[root@www ~]# vim /etc/my.cnf 
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links= [mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

第二个办法是直接做个软连接就可以


ln -s /var/lib/mysql/* /tmp/

 

我们的mysql就安装成功了,接下来我们安装php

roles的树形结构

[root@bogon php]# tree /myroles/
/myroles/
├── mysql.retry
├── mysql.yaml
├── nginx.retry
├── nginx.yaml
├── php.retry
├── php.yaml
└── roles
├── mysql
│   ├── files
│   │   ├── mysql-5.5.-linux2.-x86_64.tar.gz
│   │   ├── mysql.sh
│   │   └── yum.sh
│   ├── handlers
│   ├── tasks
│   │   └── main.yaml
│   ├── templates
│   └── vars
├── nginx
│   ├── files
│   │   ├── nginx-1.10..tar.gz
│   │   └── nginx.sh
│   ├── handlers
│   ├── tasks
│   │   └── main.yaml
│   ├── templates
│   └── vars
└── php
├── files
│   ├── libiconv-1.14.tar.gz
│   ├── php-5.3..tar.gz
│   └── php.sh
├── handlers
├── tasks
│   └── main.yaml
├── templates
└── vars

php的剧本与roles平级的

[root@bogon myroles]# vim php.yaml
---
- hosts: all
gather_facts: True
roles:
- php

php的tasks的剧本

[root@bogon tasks]# vim main.yaml 

- name: t1
copy: src=php-5.3..tar.gz dest=/root/
register: ttt
- debug: var=ttt
- name: t3
copy: src=libiconv-1.14.tar.gz dest=/root/
register: ttt
- debug: var=ttt
- name: t2
script: php.sh
register: rrr
- debug: var=rrr

安装php的脚本

[root@bogon files]# pwd
/myroles/roles/php/files

[root@bogon files]# vim php.sh

#!/bin/bash
yum -y zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel install freetype-devel libpng-devel gd libcurl-devel libxslt-devel
cd ~
tar xf libiconv-1.14.tar.gz -C /usr/src
cd /usr/src/libiconv-1.14
./configure --prefix=/usr/local/libiconv && make && make install
yum -y install libmcrypt-devel mhash mcrypt
useradd -s /sbin/nologin -M www
cd ~
tar xf php-5.3..tar.gz -C /usr/src/
cd /usr/src/php-5.3. && ./configure --prefix=/usr/local/php5.3.28 --with-mysql=mysqlnd --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-zend-multibyte --enable-static --with-xsl --with-fpm-user=www --with-fpm-group=www --enable-ftp
make && make install
ln -s /usr/local/php5.3.28/ /usr/local/php
cd /usr/src/php-5.3.
cp php.ini-production /usr/local/php/lib/php.ini
cd /usr/local/php/etc/

cp php-fpm.conf.default php-fpm.conf
/usr/local/php/sbin/php-fpm

用ansible剧本搭建lnmp的更多相关文章

  1. ansible+playbook 搭建lnmp环境

    用三台机器 做ansible+playbook 搭建lnmp环境 IP分配 ansible 主机192.168.202.132 lnmp第一台主机 192.168.202.131 lnmp第一台主机 ...

  2. CentOS6.6搭建LNMP环境

    CentOS6.6搭建LNMP环境 1.设置yum源,本地安装依赖包 1 yum -y install gcc gcc-c++ automake autoconf libtool make 2.下载依 ...

  3. 源码搭建LNMP

      源码安装LNMP 作者:尹正杰   版权声明:原创作品,谢绝转载!否则将追究法律责任.       欢迎加入:高级运维工程师之路 598432640 前言:非常简单的一个平台LNMP,在生产实际环 ...

  4. CentOS下Web服务器环境搭建LNMP一键安装包

    CentOS下Web服务器环境搭建LNMP一键安装包 时间:2014-09-04 00:50来源:osyunwei.com 作者:osyunwei.com 举报 点击:3797次 最新版本:lnmp- ...

  5. CentOS 搭建LNMP服务器和LAMP服务器

    CentOS 搭建LNMP服务器 方法一:yum安装 1.更新YUM源 wget http://www.atomicorp.com/installers/atomic   #下载atomic自动更新Y ...

  6. CentOS源码安装搭建LNMP全过程(包括nginx,mysql,php,svn)【转】

    转自:http://blog.csdn.net/yanzi1225627/article/details/49123659 服务器环境为:CentOS6.5 64位 目标:搭建LNMP(Linux + ...

  7. 源码搭建lnmp平台

    lnmp平台是指利用linux操作系统,nginx服务器,mysql数据库和php语言搭建高性能web服务器,负载均衡器和邮件代理服务器. 原理图:‘

  8. 图文详解如何快捷搭建LNMP服务环境

    上一篇与大家一起学习了下如何搭建LAMP环境的知识,今天小编再和大家分享下如何快捷地搭建LNMP环境,并搭建起一个网站.Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/S ...

  9. Docker进阶之八:搭建LNMP网站平台实战

    搭建LNMP网站平台实战 LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写.L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可 ...

随机推荐

  1. Spark-RDD算子

    一.Spark-RDD算子简介 RDD(Resilient Distributed DataSet)是分布式数据集.RDD是Spark最基本的数据的抽象. scala中的集合.RDD相当于一个不可变. ...

  2. 【译】Using Objects to Organize Your Code

    耗了一个晚上吐血翻译不过也学到了不少...<使用对象来组织你的代码>,翻译中发现原作者在原文中有部分代码有误或不全,本文已修改和添加~ 丽贝卡·墨菲原文链接:http://rmurphey ...

  3. Vector、List、LinkedList

    Vector 遍历 Vector<String> vestor =new Vector<String>(); vestor.add("qq"); vesto ...

  4. INNODB锁(2)

    在上一篇文章写了锁的基本概述以及行锁的三种形式,这一篇的主要内容如下: 一致性非锁定读 自增长与锁 外键和锁 一致性性非锁定读 一致性非锁定读是InnoDB通过多版本并发控制(MVCC,multi v ...

  5. JS中的slice和splice

    1,slice  : 定义:接收一个或两个参数,它可以创建一个由当前数组中的一项或多项组成的新数组,注意是新数组哦~ 也就是说它不会修改原来数组的值. 用法:slice( para1 ),会截取从pa ...

  6. 20145221 《Java程序设计》第六周学习总结

    20145221 <Java程序设计>第六周学习总结 教材学习内容总结 第十一章部分 - 输入与输出 文件的读写 网络上传数据的基础 同样要先掌握父类中方法,核心类如下: 以上则是老师提出 ...

  7. JS封装简单后代选择器

    大概思路是这样的:通过判断传过来的参数是什么类型,如果是对象,那这里就是this(因为封装是自己用的,肯定不会随便乱传一个对象过来),如果是一个函数(匿名函数),那就是Dom加载(这里先不讲),如果是 ...

  8. 学习Zookeeper之第2章Zookeeper安装

    第 2 章 Zookeeper安装 2.1 本地模式安装部署 2.2 配置参数解读 第 2 章 Zookeeper安装 2.1 本地模式安装部署 1)安装前准备: (1)安装 jdk (2)通过 fi ...

  9. SDN原理 控制层 Controller控制器

    本文参照SDN原理视频而成:SDN原理 Controller 概念 从上面这个图片,我们能够知道,Controller 是一个非常重要的东西:承上启下,左右拓展. 从整个SDN的架构来看,控制器 处在 ...

  10. iframe.contentWindow介绍

    一.在使用iframe的页面,要操作这个iframe里面的DOM元素可以用: contentWindow.contentDocument(测试的时候chrome浏览器,要在服务器环境下) 1.先获取i ...