zoukankan      html  css  js  c++  java
  • 使用模板

    使用模板:
    
    一个模板是一个文本文件包含特定变量或者Perl代码
    
    因此这个技术可以生成动态的配置文件。
    
    比如 如果你需要配置apache 只侦听特定的网络设备(比如eth0) 那么模板就是你需要的
    
    
    默认的模板引擎是一个特殊的Rex模板引擎。
    
    语法有点像php或者erb
    
    但是你可以使用任何模板引擎
    
    
    比如:
    
    Hello <%= $name %>!
    
    如果$name 包含"World" 这个模板会生成字符串Hello World!
    
    使用模板:
    
    
    首先你创建它:
    
    [root@node01 my-first-rex-project]# ls -ltr
    total 48
    -rw-r--r-- 1 root root 20480 Apr 29  2017 rex.tar
    -rw-r--r-- 1 root root  1318 Apr 29  2017 Rexfile.bak
    -rw-r--r-- 1 root root     0 Apr 29  2017 {parameter1}
    -rw-r--r-- 1 root root     0 Apr 29  2017 {parameter2}
    -rw-r--r-- 1 root root     0 Apr 29  2017 a1.sh
    drwxr-xr-x 2 root root  4096 Apr 29  2017 script
    -rw-r--r-- 1 root root  1640 May  3  2017 Rexfile.0523
    drwxr-xr-x 4 root root  4096 Jun 15 07:48 lib
    -rw-r--r-- 1 root root   305 Jun 15 08:11 ntp.conf
    -rw-r--r-- 1 root root  1225 Jun 19 03:33 Rexfile
    drwxr-xr-x 2 root root  4096 Jun 19 09:21 files
    
    
    $ mkdir files
    $ vim files/my.cnf.tpl
    
    [mysqld]
    datadir                 = /var/lib/mysql
    socket                  = /var/run/mysqld/mysqld.sock
    user                    = mysql
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links          = 0
    datadir                 = /var/lib/mysql
    tmpdir                  = /tmp
    skip-external-locking
    max_allowed_packet      = 64M
    thread_stack            = 192K
    max_connections         = <%= exists $conf->{"max_connections"} ? $conf->{"max_connections"} : "1000" %>
    
    max_connect_errors      = 1000
    table_cache             = <%= exists $conf->{"table_cache"} ? $conf->{"table_cache"} : "5000" %>
    table_open_cache        = <%= exists $conf->{"table_open_cache"} ? $conf->{"table_open_cache"} : "5000" %>
    thread_concurrency      = 10
    
    然后你可以在你的rexfile中引用它
    
    [root@node01 my-first-rex-project]# rex -H 192.168.137.3 prepare_databases
    
    task "prepare_databases",  sub {
       file "/tmp/my.cnf",
          owner   => "mqm",
          group   => "mqm",
          mode    => "644",
          content => template("files/my.cnf.tpl", conf => {
                                 max_connections => "500",
                                 table_cache     => "2500",
                              });
    };
  • 相关阅读:
    Mysql 之根据经纬度按距离排序
    Python的列表和元组
    go实现堆排序、快速排序、桶排序算法
    微信Hook劫获protobuf数据
    手机号批量查询微信昵称/网名/名称
    保存整个网页的内容
    天地图官网引入文件
    Postman-动态传参
    JAVA FileOutputStream与BufferedOutputStream的区别
    JAVA中sleep()和wait()的区别
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348704.html
Copyright © 2011-2022 走看看