Hi 你好,欢迎访问!登录
当前位置:首页 - 自动化运维 - 正文 忍人所不忍,能人所不能。

Linux自动化工具之安装lnmp

2020-03-16自动化运维90root76°c
A+ A-

会写jinja模板更简单, 笔者写的sls文件通俗易懂. 配置文件请点击链接: saltstack install lnmp

1. 创建lnmp所需目录

[[email protected]_210 ~]# cd /data/etc/salt/
[[email protected]_210 salt]# mkdir lnmp
[[email protected]_210 salt]# tree lnmp/
lnmp/
├── init.sls
├── memcache
│   ├── init.sls
│   ├── libevent
│   │   ├── files
│   │   │   └── libevent-2.0.22-stable.tar.gz
│   │   └── install.sls
│   ├── memcached
│   │   ├── files
│   │   │   └── memcached-1.4.31.tar.gz
│   │   ├── install.sls
│   │   └── service.sls
│   ├── php-memcache
│   │   ├── files
│   │   │   └── memcache-2.2.7.tgz
│   │   └── install.sls
│   └── user
│       └── create_90root.sls
├── mysql
│   ├── conf.sls
│   ├── files
│   │   ├── my.cnf
│   │   ├── mysql-5.6.32.tar.gz
│   │   └── mysqld
│   ├── init.sls
│   └── install.sls
├── nginx
│   ├── conf.sls
│   ├── files
│   │   ├── db_connect.php
│   │   ├── mem_connect.php
│   │   ├── nginx
│   │   ├── nginx-1.11.3.tar.gz
│   │   ├── nginx.conf
│   │   ├── nginx_log_cut.sh
│   │   ├── redis_connect.php
│   │   └── vhost.conf
│   ├── init.sls
│   └── install.sls
├── php
│   ├── config.sls
│   ├── files
│   │   ├── php-5.6.25.tar.gz
│   │   ├── php-fpm
│   │   ├── php-fpm.conf
│   │   └── php.ini
│   ├── init.sls
│   └── install.sls
└── redis
    ├── config.sls
    ├── files
    │   ├── redis
    │   ├── redis-2.2.5.tgz
    │   ├── redis-3.0.1.tar.gz
    │   ├── redis.conf
    │   └── tcl8.6.5-src.tar.gz
    ├── init.sls
    └── install.sls
[[email protected]_210 salt]# cat top.sls
base:
  '*':
    - lnmp.init

2. 查看nginx目录下文件

2.1 安装nginx的状态文件

[[email protected]_210 salt]# cd lnmp
[[email protected]_210 lnmp]# tree nginx/
nginx/
├── conf.sls
├── files
│   ├── db_connect.php
│   ├── mem_connect.php
│   ├── nginx
│   ├── nginx-1.11.3.tar.gz
│   ├── nginx.conf
│   ├── nginx_log_cut.sh
│   ├── redis_connect.php
│   └── vhost.conf
├── init.sls
└── install.sls
[[email protected]_210 lnmp]# cd nginx/
[[email protected]_210 nginx]# cat install.sls
nginx_source:
  file.managed:
    - name: /usr/local/src/nginx-1.11.3.tar.gz
    - unless: test -e /usr/local/src/nginx-1.11.3.tar.gz
    - user: root
    - group: root
    - source: salt://lnmp/nginx/files/nginx-1.11.3.tar.gz
nginx_pkg:
  pkg.installed:
    - pkgs:
      - openssl-devel
      - pcre-devel
      - zlib-devel
      - unzip
nginx_user:
  user.present:
    - name: www
    - createhome: False
    - shell: /sbin/nologin
nginx_extrace:
  cmd.run:
    - cwd: /usr/local/src
    - names:
      - tar zxf nginx-1.11.3.tar.gz && chown -R root:root nginx-1.11.3
    - unless: test -d /usr/local/src/nginx-1.11.3
    - require:
      - pkg: nginx_pkg
nginx_compile:
  cmd.run:
    - name: cd /usr/local/src/nginx-1.11.3 && ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-http_realip_module && make && make install
    - unless: test -d /usr/local/nginx
    - require:
      - cmd: nginx_extrace
      - user: nginx_user
create_dir:
  cmd.run:
    - names:
      - chown -R www:www /usr/local/nginx/html && mkdir -p /usr/local/nginx/conf/vhost
    - unless: test -d /usr/local/nginx/conf/vhost
    - require:
      - cmd: nginx_compile

2.2 nginx的配置状态文件

[[email protected]_210 nginx]# cat conf.sls
include:
  - lnmp.nginx.install
nginx_conf:
  file.managed:
    - name: /usr/local/nginx/conf/nginx.conf
    - source: salt://lnmp/nginx/files/nginx.conf
    - user: root
    - group: root
ninx_vhost_conf:
  file.managed:
    - name: /usr/local/nginx/conf/vhost/www.conf
    - source: salt://lnmp/nginx/files/vhost.conf
    - user: root
    - group: root
nginx_connect_memcached:
  file.managed:
    - name: /usr/local/nginx/html/mem_connect.php
    - source: salt://lnmp/nginx/files/mem_connect.php
    - user: www
    - group: www
nginx_connect_db:
  file.managed:
    - name: /usr/local/nginx/html/db_connect.php
    - source: salt://lnmp/nginx/files/db_connect.php
    - user: www
    - group: www
nginx_connect_redis:
  file.managed:
    - name: /usr/local/nginx/html/redis_connect.php
    - source: salt://lnmp/nginx/files/redis_connect.php
    - user: www
    - group: www
nginx_service:
  file.managed:
    - name: /etc/init.d/nginx
    - user: root
    - group: root
    - mode: 755
    - source: salt://lnmp/nginx/files/nginx
  cmd.run:
    - names:
      - /sbin/chkconfig --add nginx && /sbin/chkconfig nginx on
    - unless: /sbin/chkconfig --list nginx
  service.running:
    - name: nginx
    - enable: True
    - reload: True
    - watch:
      - file: /usr/local/nginx/conf/vhost/*.conf
nginx_log_cut:
  file.managed:
    - name: /usr/local/nginx/sbin/nginx_log_cut.sh
    - user: root
    - mode: 755
    - source: salt://lnmp/nginx/files/nginx_log_cut.sh

2.3 nginx的引导文件

[[email protected]_210 nginx]# cat init.sls
include:
  - lnmp.nginx.install
  - lnmp.nginx.conf

2.4 nginx/file目录下的部分文件(测试mem、redis、db)

[[email protected]_210 nginx]# cd files/
[[email protected]_210 files]# cat db_connect.php
<?php
$con = mysql_connect("127.0.0.1","root","");
if (!$con){
  die('Could not connect: ' . mysql_error());
  }else{
  die('mysql access Success.');
}
mysql_close($con);
?>
[[email protected]_210 files]# cat mem_connect.php
<?php
$memcache = new Memcache();
$memcache->connect('127.0.0.1',11211);
$memcache->set('key','memcached connect success.',0,60);
$get_value = $memcache->get('key');
echo $get_value;
?>
[[email protected]_210 files]# cat redis_connect.php
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$redis->auth('123.com');
$redis->select(1);
$ret = $redis->set('www.90root.com','90root');
var_dump($ret);
$allkeys = $redis->keys('*');
print_r($allkeys)
?>

2.5 nginx的主配置文件

[[email protected]_210 files]# cat nginx.conf
user www;
worker_processes 4;
error_log logs/nginx_error.log notice;
pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events{
       use epoll;
       worker_connections 65535;
}
http{
       include       mime.types;
       default_type  application/octet-stream;
       charset  utf-8;
       server_names_hash_bucket_size 128;
       client_header_buffer_size 32k;
       large_client_header_buffers 4 32k;
       client_max_body_size 128m;
       sendfile on;
       tcp_nopush     on;
       keepalive_timeout 60;
       tcp_nodelay on;
       server_tokens off;
       client_body_buffer_size  512k;
       gzip on;
       gzip_min_length  1k;
       gzip_buffers     4 16k;
       gzip_http_version 1.1;
       gzip_comp_level 2;
       gzip_types      text/plain application/x-javascript text/css application/xml;
       gzip_vary on;
       log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                         '$status $body_bytes_sent "$http_referer" '
                         '"$http_user_agent" "$http_x_forwarded_for" "$host"' ;
       include vhost/*.conf;
}

2.6 nginx的虚拟主机配置文件

[[email protected]_210 files]# cat vhost.conf
server
        {
                listen       80;
                server_name 127.0.0.1;
                index index.html index.htm;
                root  html;
                location /status {
                       stub_status on;
                }
        location ~\.php {
                root    html;
                fastcgi_pass    127.0.0.1:9000;
                fastcgi_index   index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
       }
        access_log  logs/www_access.log  main;
}

2.7 nginx的启动脚本

[[email protected]_210 files]# cat nginx
#!/bin/sh
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() {
        echo -n $"Starting $prog: "
        mkdir -p /dev/shm/nginx_temp
        daemon $NGINX_SBIN -c $NGINX_CONF
        RETVAL=$?
        echo
        return $RETVAL
}
stop() {
        echo -n $"Stopping $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -TERM
        rm -rf /dev/shm/nginx_temp
        RETVAL=$?
        echo
        return $RETVAL
}
reload(){
        echo -n $"Reloading $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -HUP
        RETVAL=$?
        echo
        return $RETVAL
}
restart(){
        stop
        start
}
configtest(){
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|configtest}"
        RETVAL=1
esac
exit $RETVAL

3. 查看mysql目录下文件

[[email protected]_210 lnmp]# tree mysql/
mysql/
├── conf.sls
├── files
│   ├── my.cnf
│   ├── mysql-5.6.32.tar.gz
│   └── mysqld
├── init.sls
└── install.sls

3.1 安装mysql的状态文件

[[email protected]_210 lnmp]# cd mysql/
[[email protected]_210 mysql]# cat install.sls
#mysql pkg.install
mysql_pkg:
  pkg.installed:
    - names:
      - gcc
      - gcc-c++
      - autoconf
      - automake
      - openssl
      - openssl-devel
      - zlib
      - zlib-devel
      - ncurses-devel
      - libtool-ltdl-devel
      - cmake
#install source mysql
mysql_source:
  file.managed:
    - name: /usr/local/src/mysql-5.6.32.tar.gz
    - unless: test -e /usr/local/src/mysql-5.6.32.tar.gz
    - source: salt://lnmp/mysql/files/mysql-5.6.32.tar.gz
#tar source mysql
extract_mysql:
  cmd.run:
    - cwd: /usr/local/src
    - names:
      - tar zxf mysql-5.6.32.tar.gz && chown -R root:root mysql-5.6.32
    - unless: tests -d /usr/local/src/mysql-5.6.32
    - require:
      - file: mysql_source
#useradd for mysql
mysql_user:
  user.present:
    - name: mysql
    - uid: 1024
    - createhome: False
    - gid_from_name: True
    - shell: /sbin/nologin
#mysql source install
mysql_commpile:
  cmd.run:
    - name: cd /usr/local/src/mysql-5.6.32 && cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6 -DMYSQL_DATADIR=/usr/local/mysql-5.6/data -DMYSQL_UNIX_ADDR=/usr/local/mysql-5.6/data/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH-BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGING=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFIL=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0 && make && make install && /usr/local/mysql-5.6/scripts/mysql_install_d --basedir=/usr/local/mysql-5.6/ --datadir=/usr/local/mysql-5.6/data/ --user=mysql
    - require:
      - cmd: extract_mysql
      - pkg: mysql_pkg
    - unless: test -d /usr/local/mysql-5.6

3.2 mysql的配置状态文件

[[email protected]_210 mysql]# cat conf.sls
include:
  - lnmp.mysql.install
#mysql for config
mysql_cnf:
  file.managed:
    - name: /etc/my.cnf
    - user: root
    - mode: 755
    - source: salt://lnmp/mysql/files/my.cnf
#myql server
mysql_service:
  file.managed:
    - name: /etc/init.d/mysqld
    - source: salt://lnmp/mysql/files/mysqld
    - user: root
    - mode: 755
  cmd.run:
    - names:
      - /sbin/chkconfig --add mysqld
      - /sbin/chkconfig --level 35 mysqld on
    - unless: /sbin/chkconfig --list mysqld

3.3 mysql的引导文件

[[email protected]_210 mysql]# cat init.sls
include:
  - lnmp.mysql.install
  - lnmp.mysql.conf

3.4 mysql/file目录下的部分文件

[[email protected]_210 files]# cat my.cnf
[mysqld]
socket=/usr/local/mysql-5.6/data/mysql.sock
datadir=/usr/local/mysql-5.6/data
symbolic-links=0
log-error=/var/log/mysql_error.log
pid-file=/usr/local/mysql-5.6/data/mysqld.pid
slow-query-log-file = /var/log/mysql_slow_querys.log
skip-name-resolve
skip-grant-tables

3.5 mysql的引导文件

[[email protected]_210 mysql]# cat init.sls
include:
  - lnmp.mysql.install
  - lnmp.mysql.conf

3.6 mysql/file目录下的部分文件

[[email protected]_210 mysql]# tree files/
files/
├── my.cnf
├── mysql-5.6.32.tar.gz
└── mysqld

mysql启动脚本内容太多, 再此不粘贴

4. 查看PHP目录下文件

[[email protected]_210 lnmp]# tree php/
php/
├── config.sls
├── files
│   ├── php-5.6.25.tar.gz
│   ├── php-fpm
│   ├── php-fpm.conf
│   └── php.ini
├── init.sls
└── install.sls

4.1 安装PHP的状态文件

[[email protected]_210 lnmp]# cd php/
[[email protected]_210 php]# cat install.sls
pkg-php:
  pkg.installed:
    - names:
      - mysql-devel
      - openssl-devel
      - swig
      - libjpeg-turbo
      - libjpeg-turbo-devel
      - libpng
      - libpng-devel
      - freetype
      - freetype-devel
      - libxml2
      - libxml2-devel
      - zlib
      - libcurl
      - libcurl-devel
      - libmcrypt
      - libmcrypt-devel
      - bzip2
      - bzip2-devel
php_source:
  file.managed:
    - name: /usr/local/src/php-5.6.25.tar.gz
    - source: salt://lnmp/php/files/php-5.6.25.tar.gz
    - user: root
    - group: root
php_extrace:
  cmd.run:
    - cwd: /usr/local/src
    - names:
      - tar zxf php-5.6.25.tar.gz && chown -R root:root php-5.6.25
    - unless: test -d /data/Software/php-5.6.25
    - require:
      - pkg: pkg-php
php_compile:
  cmd.run:
    - names:
      - cd /usr/local/src/php-5.6.25 && ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-exif --disable-ipv6 --with-pear --with-curl --enable-bcmath --enable-mbstring --enable-sockets --with-gettext && make && make install
    - require:
      - file: php_source
    - unless: test -d /usr/local/php-fpm
php_plugin:
  cmd.run:
    - names:
      - cd /usr/local/src/php-5.6.25/ext/pdo_mysql/ && /usr/local/php-fpm/bin/phpize && ./configure --with-php-config=/usr/local/php-fpm/bin/php-config && make && make install
    - require:
      - cmd: php_compile

4.2 PHP的配置状态文件

[[email protected]_210 php]# cat config.sls
include:
  - lnmp.php.install
php-ini:
  file.managed:
    - name: /usr/local/php-fpm/etc/php.ini
    - source: salt://lnmp/php/files/php.ini
php-fpm:
  file.managed:
    - name: /usr/local/php-fpm/etc/php-fpm.conf
    - source: salt://lnmp/php/files/php-fpm.conf
php-service:
  file.managed:
    - name: /etc/init.d/php-fpm
    - source: salt://lnmp/php/files/php-fpm
    - user: root
    - group: root
    - mode: 755
  cmd.run:
    - name: chkconfig --add php-fpm
    - unless: chkconfig --list | grep php-fpm
    - require:
      - file: php-service
  service.running:
    - name: php-fpm
    - enable: True
    - require:
      - cmd: php-service
    - watch:
      - file: php-ini
      - file: php-fpm

4.3 PHP的引导文件

[[email protected]_210 php]# cat init.sls
include:
  - lnmp.php.config
  - lnmp.php.install

4.4 php/file目录下的部分文件

[[email protected]_210 php]# tree files/
files/
├── php-5.6.25.tar.gz
├── php-fpm
├── php-fpm.conf
└── php.ini

4.5 php的引导文件

[[email protected]_210 php]# cat init.sls
include:
  - lnmp.php.config
  - lnmp.php.install

文件内容过多,请看文章结尾的链接地址

5. 查看memcached目录下文件

[[email protected]_210 lnmp]# tree memcache/
memcache/
├── init.sls
├── libevent
│   ├── files
│   │   └── libevent-2.0.22-stable.tar.gz
│   └── install.sls
├── memcached
│   ├── files
│   │   └── memcached-1.4.31.tar.gz
│   ├── install.sls
│   └── service.sls
├── php-memcache
│   ├── files
│   │   └── memcache-2.2.7.tgz
│   └── install.sls
└── user
    └── create_90root.sls

5.1 安装libevent的状态文件

[[email protected]_210 lnmp]# cd memcache/libevent/
[[email protected]_210 libevent]# cat install.sls
libevent-source:
  file.managed:
    - name: /usr/local/src/libevent-2.0.22-stable.tar.gz
    - unless: test -e /usr/local/src/libevent-2.0.22-stable.tar.gz
    - source: salt://lnmp/memcache/libevent/files/libevent-2.0.22-stable.tar.gz
    - user: root
    - group: root
    - mode: 644
libevent-extrace:
  cmd.run:
    - cwd: /usr/local/src
    - names:
      - tar zxf libevent-2.0.22-stable.tar.gz && chown -R root:root libevent-2.0.22-stable
    - unless: test -d /usr/local/src/libevent-2.0.22-stable
    - require:
      - file: libevent-source
libevent-compile:
  cmd.run:
    - name: cd /usr/local/src/libevent-2.0.22-stable && ./configure --prefix=/usr/local/libevent && make && make install
    - unless: test -d /usr/local/libevent
    - require:
      - cmd: libevent-extrace
[[email protected]_210 libevent]# tree files/
files/
└── libevent-2.0.22-stable.tar.gz

5.2 安装memcached的状态文件

[[email protected]_210 lnmp]# cd ../memcached
[[email protected]_210 memcached]# cat install.sls
include:
  - lnmp.memcache.libevent.install
memcached-source:
  file.managed:
    - name: /usr/local/src/memcached-1.4.31.tar.gz
    - unless: test -e /usr/local/src/memcached-1.4.31.tar.gz
    - source: salt://lnmp/memcache/memcached/files/memcached-1.4.31.tar.gz
    - user: root
    - group: root
    - mode: 644
memcached-extrace:
  cmd.run:
    - cwd: /usr/local/src
    - names:
      - tar zxf memcached-1.4.31.tar.gz && chown -R root:root memcached-1.4.31
    - unless: test -d /usr/local/src/memcached-1.4.31
    - require:
      - file: memcached-source
memcached-install:
  cmd.run:
    - name: cd /usr/local/src/memcached-1.4.31 && ./configure --prefix=/usr/local/memcached --enable-64bit --with-libevent=/usr/local/libevent && make && make install
    - unless: test -d /usr/local/memcached
    - require:
      - cmd: memcached-extrace

5.3 memcached的启动状态文件

[[email protected]_210 memcached]# cat service.sls
include:
  - lnmp.memcache.memcached.install
  - lnmp.memcache.user.create_90root
  - lnmp.memcache.libevent.install
memcached-service:
  cmd.run:
    - name: /usr/local/memcached/bin/memcached -d -m 128 -p 11211 -c 8096 -u 90root
    - unless: netstat -anpt | grep 11211
    - require:
      - cmd: memcached-install
      - user: 90root-user-group

5.4 memcached/file目录下的文件

[[email protected]_210 memcached]# tree files/
files/
└── memcached-1.4.31.tar.gz

5.5 安装php的扩展memcache

[[email protected]_210 memcached]# cd ../php-memcache/
[[email protected]_210 php-memcache]# cat install.sls
memcache_plugin:
  file.managed:
    - name: /usr/local/src/memcache-2.2.7.tgz
    - source: salt://lnmp/memcache/php-memcache/files/memcache-2.2.7.tgz
    - user: root
    - group: root
memcache_extrace:
  cmd.run:
    - cwd: /usr/local/src
    - names:
      - tar zxf memcache-2.2.7.tgz && chown -R root:root memcache-2.2.7
    - unless:
      - file: memcache_plugin
memcache_compile:
  cmd.run:
    - names:
      - cd /usr/local/src/memcache-2.2.7 && /usr/local/php-fpm/bin/phpize && ./configure --enable-memcache --with-php-config=/usr/local/php-fpm/bin/php-config && make && make install
    - unless: test -f /usr/local/php-fpm/lib/php/extensions/*/memcache.so
    - require:
      - cmd: memcache_extrace
/usr/local/php-fpm/etc/php.ini:
  file.append:
    - text:
      - extension=memcache.so
      - extension=redis.so
[[email protected]_210 php-memcache]# tree files/
files/
└── memcache-2.2.7.tgz

5.6 创建memcached的监听用户

[[email protected]_210 php-memcache]# cd ../user/
[[email protected]_210 user]# cat create_90root.sls
90root-user-group:
  group.present:
    - name: 90root
    - gid: 1000
  user.present:
    - name: 90root
    - fullname: 90root
    - shell: /sbin/nologin
    - uid: 1000
    - gid: 1000
    - createhome: True

5.7 memcached的引导文件

[[email protected]_210 memcache]# cat init.sls
include:
  - lnmp.memcache.memcached.service
  - lnmp.memcache.php-memcache.install

6. 查看redis目录下文件

[[email protected]_210 user]# cd ../..
[[email protected]_210 lnmp]# tree redis/
redis/
├── config.sls
├── files
│   ├── redis
│   ├── redis-2.2.5.tgz
│   ├── redis-3.0.1.tar.gz
│   ├── redis.conf
│   └── tcl8.6.5-src.tar.gz
├── init.sls
└── install.sls

6.1 安装redis的状态文件

[[email protected]_210 redis]# cat install.sls
## Install config and install tcl
tcl_source:
  file.managed:
    - name: /usr/local/src/tcl8.6.5-src.tar.gz
    - source: salt://lnmp/redis/files/tcl8.6.5-src.tar.gz
    - user: root
    - group: root
tcl_extrace:
  cmd.run:
    - cwd: /usr/local/src
    - names:
       - tar zxf tcl8.6.5-src.tar.gz && chown -R root:root tcl8.6.5
    - unless: test -d /usr/local/src/tcl8.6.5
    - require:
      - file: tcl_source
tcl_compile:
  cmd.run:
    - names:
      - cd /usr/local/src/tcl8.6.5/unix && ./configure && make && make install
    - unless: test -d /usr/local/tcl
    - require:
      - cmd: tcl_extrace
## Install config and install redis-php
redis_php_source:
  file.managed:
    - name: /usr/local/src/redis-3.0.1.tar.gz
    - source: salt://lnmp/redis/files/redis-3.0.1.tar.gz
    - user: root
    - group: root
redis_php_extrace:
  cmd.run:
    - cwd: /usr/local/src
    - names:
      - tar zxf redis-3.0.1.tar.gz && chown -R root:root redis-3.0.1 && mkdir -p /usr/local/src/redis-3.0.1/var
    - unless: test -d /usr/local/src/redis-3.0.1
    - require:
      - file: redis_php_source
redis_php_compila:
  cmd.run:
    - names:
      - cd /usr/local/src/redis-3.0.1 && make && make install
    - require:
      - cmd: redis_php_extrace
## Install config and install redis
redis_source:
  file.managed:
    - name: /usr/local/src/redis-2.2.5.tgz
    - source: salt://lnmp/redis/files/redis-2.2.5.tgz
    - user: root
    - group: root
redis_extrace:
  cmd.run:
    - cwd: /usr/local/src
    - names:
      - tar zxf redis-2.2.5.tgz && chown -R root:root redis-2.2.5
    - unless: test -d /usr/local/src/redis-2.2.5
    - require:
      - file: redis_source
redis_compila:
  cmd.run:
    - names:
      - cd /usr/local/src/redis-2.2.5 && /usr/local/php-fpm/bin/phpize && ./configure --with-php-config=/usr/local/php-fpm/bin/php-config && make && make install
    - unless: test -f /usr/local/php-fpm/lib/php/extensions/*/redis.so
    - require:
      - cmd: redis_extrace

6.2 redis的配置状态文件

[[email protected]_210 redis]# cat config.sls
include:
  - lnmp.redis.install
redis-config:
  file.managed:
    - name: /etc/redis.conf
    - source: salt://lnmp/redis/files/redis.conf
    - user: root
    - group: root
redis-service:
  file.managed:
    - name: /etc/init.d/redis
    - source: salt://lnmp/redis/files/redis
    - user: root
    - group: root
    - mode: 755
  cmd.run:
    - names:
      - chkconfig --add redis && chkconfig redis on
    - unless: chkconfig --list | grep redis
    - require:
      - file: redis-service
  service.running:
    - name: redis
    - enable: True
    - restart: True
    - watch:
      - file: redis-config

6.3 redis的引导文件

[[email protected]_210 redis]# cat init.sls
include:
  - lnmp.redis.config
  - lnmp.redis.install

6.4 redis/file目录下的部分文件

[[email protected]_210 redis]# tree files/
files/
├── redis
├── redis-2.2.5.tgz
├── redis-3.0.1.tar.gz
├── redis.conf
└── tcl8.6.5-src.tar.gz
  移步手机端
Linux自动化工具之安装lnmp

1、打开你手机的二维码扫描APP
2、扫描左则的二维码
3、点击扫描获得的网址
4、可以在手机端阅读此文章
标签:

发表评论

选填

必填

必填

选填

请拖动滑块解锁
>>


  用户登录