海运的博客

SaltStack配置管理Nginx

发布时间:January 27, 2014 // 分类:Puppet // No Comments

配置仓库根目录:

file_roots:
  base:
    - /srv/salt

创建入口文件:

cat > /srv/salt/top.sls << EOF
base:
  '*':  #匹配所有受控主机
    - nginx
EOF

创建nginx sls:

mkdir -p /srv/salt/nginx
cat > /srv/salt/nginx/init.sls << EOF
nginx:
  pkg:
    - name: nginx
    - installed
  service:
    - running
    - enable: True
    - reload: True
    - require:
      - pkg: nginx
      - pkg: httpd
    - watch:
      - pkg: nginx
      - file: /etc/nginx/nginx.conf
      - file: /etc/nginx/conf.d/

httpd:
  pkg:
    - name: httpd
    - removed

/etc/nginx/nginx.conf:
  file.managed:
    - source: salt://nginx/nginx.conf
    - user: root
    - group: root
    - mode: 644
 
/etc/nginx/conf.d/:
  file.recurse:
    - source: salt://nginx/conf.d/
    - user: root
    - group: root
    - dir_mode: 755
    - file_mode: 644

/home/wwwlogs/:
  file.directory:
    - makedirs: True
    - user: nginx
    - group: nginx
    - mode: 0755
    - recurse:
      - user
      - group
      - mode
EOF

执行:

salt '*' state.highstate
或
salt '*' state.sls nginx

SaltStack通过SSH管理

发布时间:January 27, 2014 // 分类:Puppet // No Comments

cat > /etc/salt/roster << EOF
test:
  host: 192.168.1.1
  user: root
  password: redhat
EOF

通过salt-ssh执行,第一次执行后会添加auth key

salt-ssh '*' cmd.run "uptime"

自动化工具SaltStack

发布时间:January 27, 2014 // 分类:Puppet // No Comments

Master:

curl -L http://bootstrap.saltstack.org | sudo sh -s -- -M -N
yum search salt-ssh

Slave:

wget -O - http://bootstrap.saltstack.org | sudo sh
yum install salt-minion

客户端配置:

Master: 192.168.1.1
#识别ID
id: test

启动客户端:

/etc/init.d/salt-minion  start

服务器端确认:

salt-key -A

执行模块命令:

salt '*' test.ping

执行shell命令:

salt '*' cmd.run "uptime"

执行脚本命令:

mkdir -p /srv/salt/scripts/
cat > /srv/salt/scripts/test.sh << EOF
#!/bin/bash
echo  "test" > /tmp/test.txt
echo $1
echo $2
echo $3
EOF
salt '*' cmd.script salt://scripts/test.sh "aa bb cc"

同步服务器状态,安装git:

cat >/srv/salt/git.sls << EOF
git:
  pkg:
    - installed
EOF
salt '*' state.sls git

查看节点信息:

salt '*' grains.ls  查看grains分类
salt '*' grains.items 查看grains所有信息
salt '*' grains.item osrelease 查看grains某个信息

内置模块:http://docs.saltstack.com/ref/modules/all/index.html

CentOS使用remi源安装最新版PHP

发布时间:January 26, 2014 // 分类:CentOS // No Comments

remi:

rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

CentOS5:

rpm -ivh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm

CentOS7:

rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

安装后源默认禁用,如需启用可修改remi.repo或:

yum --enablerepo=remi-php55 install php

src:

http://rpms.famillecollet.com/SRPMS/

webtatic:

rpm -ivh http://repo.webtatic.com/yum/el6/latest.rpm 

src:

http://repo.webtatic.com/yum/el6/SRPMS/

PHP HTML解析类

发布时间:January 21, 2014 // 分类:PHP // No Comments

1.phpQuery

<?php
   require("phpQuery-onefile.php");
   phpQuery::newDocumentFile('https://www.haiyun.me/archives.html'); 

   //foreach (pq('body .main li')->find('a') as $a) {
   foreach (pq('body .main li a') as $a) {
      $hrefs[] = pq($a)->attr('href');
      $hrefs[] = pq($a)->text();
   }
   print_r($hrefs);
?>

记得释放内存:

phpQuery::$documents = array();
phpQuery::unloadDocuments();

2.基于tidy的HtmlParserModel,可解析不正规的HTML页面:

yum install php-tidy
git clone https://github.com/bupt1987/HtmlParserModel.git
<?php
   include_once "HtmlParserModel.php";
   $html = file_get_contents('http://www.amazon.com/s/node=3564986011');
   $html_dom = new HtmlParserModel($html);
   $p_array = $html_dom->find('a.title');
   foreach ($p_array as $p){
      echo $p->getPlainText();
   }
?>
分类
最新文章
最近回复
  • opnfense: 谢谢博主!!!解决问题了!!!我之前一直以为内置的odhcp6就是唯一管理ipv6的方式
  • liyk: 这个方法获取的IPv6大概20分钟之后就会失效,默认路由先消失,然后Global IPV6再消失
  • 海运: 不好意思,没有。
  • zongboa: 您好,請問一下有immortalwrt設定guest Wi-Fi的GUI教學嗎?感謝您。
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...