海运的博客

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('http://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();
   }
?>
分类
最新文章
最近回复
  • 头很黑: 除了发送eth转账 ,还能转账其他的代币吗 比如eos
  • 米扑博客: 总结的很棒
  • 米扑博客: 很赞的博客
  • 常易北: 满分顶楼主!!!我也是,现在网上瞎几把扫别人云主机的智障太多了!
  • track: NAT 部分没处理,这块感觉有问题。
  • yu: 查到有用的资料很幸福!
  • boscotsang: 请问下服务器端如何控制权限让通过权限认证的客户端才能连接?现在这样只要有自编译的客户端程序都可...
  • yck932: 大侠,请问哪里有 tunnels 详细参考资料,谢谢
  • bubble: 现在linux 4.9以上的内核有个bbr的参数,用这个bbr比用锐速效果更好,可参考我的博文...
  • wang: openwrt 只有 tmp/etc/miniupnpd.conf 修改后又重置了,其他路径找...