windows定时删除文件
技术学习/Windows相关 2012/03/15 17:30cd "D:\FTP-Site\ATP4"
forfiles -p "D:\FTP-Site\PCE-ITSAP\ATP4" -s -m *.* -d -62 -c "cmd /c del @path /f /q"
需要个性化定制脚本,详细条件参数, 请自行输入 forfiles /? 查看。
C:\Users\Gavin Zheng>forfiles /?
FORFILES [/P pathname] [/M searchmask] [/S]
[/C command] [/D [+ | -] {MM/dd/yyyy | dd}]
Description:
Selects a file (or set of files) and executes a
command on that file. This is helpful for batch jobs.
Parameter List:
/P pathname Indicates the path to start searching.
The default folder is the current working
directory (.).
/M searchmask Searches files according to a searchmask.
The default searchmask is '*' .
/S Instructs forfiles to recurse into
subdirectories. Like "DIR /S".
/C command Indicates the command to execute for each file.
Command strings should be wrapped in double
quotes.
The default command is "cmd /c echo @file".
The following variables can be used in the
command string:
@file - returns the name of the file.
@fname - returns the file name without
extension.
@ext - returns only the extension of the
file.
@path - returns the full path of the file.
@relpath - returns the relative path of the
file.
@isdir - returns "TRUE" if a file type is
a directory, and "FALSE" for files.
@fsize - returns the size of the file in
bytes.
@fdate - returns the last modified date of the
file.
@ftime - returns the last modified time of the
file.
To include special characters in the command
line, use the hexadecimal code for the character
in 0xHH format (ex. 0x09 for tab). Internal
CMD.exe commands should be preceded with
"cmd /c".
/D date Selects files with a last modified date greater
than or equal to (+), or less than or equal to
(-), the specified date using the
"MM/dd/yyyy" format; or selects files with a
last modified date greater than or equal to (+)
the current date plus "dd" days, or less than or
equal to (-) the current date minus "dd" days. A
valid "dd" number of days can be any number in
the range of 0 - 32768.
"+" is taken as default sign if not specified.
/? Displays this help message.
Examples:
FORFILES /?
FORFILES
FORFILES /P C:\WINDOWS /S /M DNS*.*
FORFILES /S /M *.txt /C "cmd /c type @file | more"
FORFILES /P C:\ /S /M *.bat
FORFILES /D -30 /M *.exe
/C "cmd /c echo @path 0x09 was changed 30 days ago"
FORFILES /D 01/01/2001
/C "cmd /c echo @fname is new since Jan 1st 2001"
FORFILES /D +6/25/2011 /C "cmd /c echo @fname is new today"
FORFILES /M *.exe /D +1
FORFILES /S /M *.doc /C "cmd /c echo @fsize"
FORFILES /M *.txt /C "cmd /c if @isdir==FALSE notepad.exe @file"
Apache、lighttpd日志记录经过Squid后用户真实IP
技术学习/linux学习 2012/03/06 14:34forwarded_for on ( 默认就是这个值,可以忽略)
Apache、lighttpd配置
LogFormat "%h \"%{X-Forwarded-For}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
# 原理很简单:
Squid 设置 forwarded_for on ,会添加 X-Forwarded-For 这个请求头,里面的值就是 用户的IP,如果有多个IP 用 ", " 来分割
Apache 记录 X-Forwarded-For 这个头的值。
64位windows 7操作系统下安装oracle client
技术学习/Oracle学习 2012/02/16 11:18经过网上查询和实际安装,终于在windows 7 64位下安装了 oracle client,所以把方法总结下与大家分享:
ORACLE_CLIENT_WINDOWS7_X64下载地址
http://download.oracle.com/otn/nt/oracle10g/10204/10204_vista_w2k8_x64_production_client.zip
操作系统: windows 7 64位
oracle client 版本:10204_vista_w2k8_x64_production_client
在windows 7 64位下安装的方法:
[Certified Versions]
#You can customise error message shown for failure, provide value for CERTIFIED_VERSION_FAILURE_MESSAGE
Windows=5.0,5.1,5.2,6.0,6.1 (在window后面添加 6.1)
[Windows-6.0-optional]
#Minimum display colours for OUI to run
MIN_DISPLAY_COLORS=256
#Minimum CPU speed required for OUI
#CPU=300
client\stage\prereq\client\refhost.xml
client\stage\prereq\client_prereqs\client\refhost.xml
在- <!-- Microsoft Windows Vista
-->
- <OPERATING_SYSTEM>
<VERSION VALUE="6.0" />
</OPERATING_SYSTEM>选项后面添加如下选项:
-->
- <OPERATING_SYSTEM>
<VERSION VALUE="6.1" />
</OPERATING_SYSTEM>
编译安装mysql 5.5.15
技术学习/系统管理 2011/12/09 13:42环境概述
操作系统:debian 6.0.2
数据库:mysql community server 5.5.15
第一次使用debian,采用默认安装模式,安装用了很长时间,大多数时间都花在了下载软件包上。这样后面需要的很多软件包都需要通过apt-get来安装。
安装准备
Bison下载,Bison是Mysql必需的语法分析器:http://www.gnu.org/software/bison/
Mysql community server 5.5.15下载:http://dev.mysql.com/downloads/mysql/5.5.html#downloads
Cmake下载:从Mysql5开始,开始使用cmake为mysql的默认编译工具 http://www.cmake.org/cmake/resources/software.html
下载 cmake-2.8.5-Linux-i386.sh文件就可以了,这是可以脚本可以直接安装cmake。
Make安装,默认情况下debian没有安装make编译工具,可以通过apt-get install make安装。
gcc,g++安装 这两个编译器,cmake会用到。
apt-get install gcc
apt-get install g++
m4下载 debian默认的m4版本太低,在编译Bison的时候会出错,所以在编译Bison之前,先升级m4
http://www.gnu.org/software/m4/
创建mysql用户组
groupadd mysql
useradd -g mysql -r -m -s /bin/bash mysql
passwd mysql
这一步不是必须的,但推荐创建这个账户和组,将来可以让mysql数据库在这个账户下运行,避免在root下运行软件。
编译安装Mysql软件
安装升级m4
tar zxvf m4-1.4.16.tar.gz
cd m4-1.4.16
./configure
make
make install
cmake安装
root@debian:~# sh cmake-2.8.5-Linux-i386.sh
CMake Installer Version: 2.8.5, Copyright (c) Kitware
This is a self-extracting archive.
The archive will be extracted to: /root
.............
Do you accept the license? [yN]:
y
By default the CMake will be installed in:
"/root/cmake-2.8.5-Linux-i386"
Do you want to include the subdirectory cmake-2.8.5-Linux-i386?
Saying no will install in: "/root" [Yn]:
Y
Using target directory: /root/cmake-2.8.5-Linux-i386
Extracting, please wait…
Unpacking finished successfully
到此安装完毕,默认解压在$HOME/cmake-verioin-Linux-i386目录,可以将此目录copy到系统/usr/local下面。
Bison安装
tar zxvf bison-2.5.tar.gz
cd bison-2.5
./configure
make
make install
mysql community 5.5.15编译安装
tar zxvf mysql-5.5.15.tar.gz
cd mysql-5.5.15
cmake .
make
make install
在安装cmake .的过程中,有可能会出现错误:
CMake Error at cmake/readline.cmake:83 (MESSAGE):
Curses library not found. Please install appropriate package,
remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:127 (FIND_CURSES)
cmake/readline.cmake:217 (MYSQL_USE_BUNDLED_LIBEDIT)
CMakeLists.txt:257 (MYSQL_CHECK_READLINE)
我这里是缺少libncurses5-dev这个数据包,可以通过apt-get install libncurses5-dev来安装。
如果没有安装上面提到的gcc、g++,有可能会提示下面的错误:
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error: Internal CMake error, TryCompile configure of cmake failed
– Performing Test HAVE_PEERCRED – Failed
Warning: Bison executable not found in PATH
– Configuring incomplete, errors occurred!
如果在make中提示错误,也是缺少软件包造成的。我碰到的就是上面两种错误。
Mysql数据库初始化
mysql安装过程中默认会在/etc/mysql目录copy一个my.cnf配置文件。根据自己的需要修改这个文件。
………………..
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3308
basedir = /usr/local/mysql
datadir = /app/mysql
……………………..
安装mysql权限表和默认系统schema,在前面的cmake过程中如果没有指定mysql安装目录,默认情况下会安装在/usrl/local下面:
root@debian:/home/mysql/mysql-5.5.15# cd /usr/local/mysql/
设置mysql默认用户组
chown -R mysql:mysql .
初始化mysql数据库
root@debian:/usr/local/mysql# cd /usr/local/mysql
root@debian:/usr/local/mysql# scripts/mysql_install_db –defaults_file=/etc/mysql/my.cnf –user=mysql &
Mysql测试:
root@debian:/usr/local/mysql# mysqladmin version
mysqladmin Ver 8.42 Distrib 5.1.49, for debian-linux-gnu on i486
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Server version 5.5.15
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/run/mysqld/mysqld.sock
Uptime: 1 hour 14 min 43 sec
Threads: 1 Questions: 3 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.000
root@debian:/usr/local/mysql# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.15 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
安装完毕。
【转】用linux设置iptables做网关
技术学习/linux学习 2011/10/31 15:36周海汉 /文
2010-3-25
http://blog.csdn.net/ablo_zhou
为了安全起见,web服务器,数据库,计费等有重要内容的机器,可能是藏在防火墙后面的,甚至没有外网地址。在此,我们假定需要给一台只有内网地址的web服务器设置linux网关,让外网可以访问web,但又屏蔽其他端口的访问。
iptables是linux 2.4以上内核自带的防火墙,可以用于阻挡非法的端口和IP访问,也可以用于做网关设备,配置NAT/防火墙,做port forward.
iptables 的逻辑,由表tables,链chains,规则rules组成。根据报文头进行相应的处理。系统接受到包时,底层路由根据目的地分发。如果目的地是本机,则进入INPUT链。本机处理完,再进入OUTPUT链,发送出去。如果目的地不是本机,则进入FORWARD链,符合规则,则转发出去。
设备设置:
web site ip port: 192.168.12.50 80 (windows IIS server or linux apache)
gateway public ip(eth0): 210.211.22.20, private ip(eth1): 192.168.12.10 (centos 5.2)
现在我们希望访问http://210.211.22.20 即可访问http://192.168.12.50:80.
1.gateway上设置允许IP转送:
vi /etc/sysctl.conf
设置:
net.ipv4.ip_forward = 1
执行
sysctl -p
应该看到
net.ipv4.ip_forward = 1
2.gateway上设置iptables
- #nat表,PREROUTING链,设置对eth0的目标端口是80的tcp协议,放到DNAT,forward到192.168.12.50:80
- iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.12.50:80
- #filter表,对接到的eth0的,从eth1转到192.168.12.50:80
- iptables -A FORWARD -p tcp -i eth0 -o eth1 -d 192.168.12.50 --dport 80 -j ACCEPT
- #但是,也要做nat变换,维护一份映射表,从eth1送出时采用内网地址,回来时变为公网地址。否则外网会收不到回复。
- iptables -t nat -A POSTROUTING -j MASQUERADE -o eth1
设置完毕,执行service iptables save
此时,从外网访问http://210.211.22.20已经可以看到内网的网页。
3.举一反三,根据需要,可以将端口设置为数据库的1433或ftp的20,21,smtp和pop的25,110等,协议和转发需要稍有改动和调试。
例如,设置mssql数据库的代理。
- #1.在nat表设置PREROUTING链,这里没有 -o选项。
- iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 1433 -j DNAT --to 192.168.12.123:1433
- #2.设置filter表
- iptables -A FORWARD -p tcp -i eth0 -o eth1 --dport 1433 -d 192.168.12.123 -j ACCEPT
- #3.nat变换,如果有了就可以不设置
- iptables -t nat -A POSTROUTING -j MASQUERADE -o eth1
Linux 下 strace 命令用法总结
技术学习/linux学习 2011/07/22 17:501 功能说明
strace 命令是一种强大的工具, 能够显示任何由用户空间程式发出的系统调用. strace 显示这些调用的参数并返回符号形式的值. strace 从内核接收信息, 而且无需以任何特别的方式来构建内核. strace 的每一行输出包括系统调用名称, 然后是参数和返回值.
下面记录几个常用option:
-f -F选项告诉strace同时跟踪fork和vfork出来的进程
-o xxx.txt 输出到某个文档.
-e execve 只记录 execve 这类系统调用.
2 详细用法
usage: strace [-dffhiqrtttTvVxx] [-a column] [-e expr] ... [-o file]
[-p pid] ... [-s strsize] [-u username] [-E var=val] ...
[command [arg ...]]
or: strace -c [-e expr] ... [-O overhead] [-S sortby] [-E var=val] ...
[command [arg ...]]
【转帖】Hadoop分布式集群搭建
技术学习/linux学习 2011/07/14 13:54转自:http://hi.baidu.com/%B5%E3%BE%A6it/blog/item/bdba1c85f713c005b21bba5a.html
简介: Hadoop是Apache开源组织的一个并行分布式计算开源框架,借助hadoop框架程序员很容易的实现大规模计算机并行分布式计算。hadoop主要包含MapReduce和HDFS,
MapReduce是基于Google MapReduce论文的开源java实现, map就是将任务分解,然后交给大规模计算机集群去运算,reduce负责合并计算结果。
HDFS: 基于google GFS分布式文件系统论文的开源实现,是hadoop底层存储组件。
环境: RedHat as 5
配置机器:
namenode:10.0.0.114, 机器名: mika
datanode: 10.0.0.115 机器名: c1
配置JDK
下载linux jdk安装包: http://download.oracle.com/otn-pub/java/jdk/6u25-b06/jdk-6u25-linux-i586.bin ,
提升bin权限: $ sudo chmod +x jdk-6u25-linux-i586.bin
安装bin文件 $ ./jdk-6u25-linux-i586.bin, 确认后安装即可。
设置java运行环境变量, 我的jdk安装在opt下
$ sudo vi /etc/profile 添加下面的设置:
JAVA_HOME="/opt/jdk1.6.0_25"
PATH=$JAVA_HOME/bin:$PATH
CALSSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CALSSPATH
修改保存,然后输入source /etc/profile 激活修改后的java环境变量。
2. 修改hosts文件
name节点,可以通过机器名访问data节点, 添加如下内容:
10.0.0.114 mika
10.0.0.115 c1
data节点,c1添加如下内容:
10.0.0.114 mika
10.0.0.115 c1
3. 设置ssh实现免密码登录
redhat 默认是安装ssh的, 如果没有请先安装ssh服务。
在name节点 生成ssh key,
$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa 生成密钥对,
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys 复杂公钥到authorized_keys文件
scp命令将公钥拷贝到c1数据节点:
$ scp ~/.ssh/authorized_keys c1:/~/.ssh
测试name节点无密码登录c1机器: ssh c1, 出现欢迎登录,配置成功。
4. 配置hadoop
下载最新hadoop最新稳定发行版: http://www.apache.org/dyn/closer.cgi/hadoop/common/ , 解压后修改conf/hadoop-env.sh内的JAVA_HOME,修改为/opt/opt/jdk1.6.0_25
输入命令 bin/hadoop 出现命令使用说明
接下来配置完全分布式集群,所有机器的hadoop安装路径相同:
修改core-site.xml文件:<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://mika:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/opt/hadoop/tmp</value>
</property>
</configuration>
注意: 需要更改hadoop.tmp.dir默认的指向, 默认指向tmp目录下, 有可能会出现其他问,有时候会出现发现不了datanode的问题。
修改hdfs-site.xml 文件:<?xml-stylesheet type=”text/xsl” href=”configuration.xsl”?>
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>mika:9001</value>
</property>
</configuration>
修改masters: 添加一行内容 mika
修改slaves: 添加一行内容 c1
然后scp将masters,slaves, core-site.xml, hdfs-site.xml, mapred-site.xml 复制到 c1节点
格式化新的分布式文件系统:bin/hadoop namenode -format
在分配的NameNode上,启动hdfsbin/start-dfs.sh
在分配的JobTracker上, 启动mapredbin/start-mapred.sh
JPS查看namenode服务是否启动
浏览NameNode和JobTracker的网络接口,它们的地址默认为:
NameNode - http://mika:50070/JobTracker - http://mika:50030/
备注: 如果新加一个节点c2(10.0.0.116), 该如何设置?
在name节点的hosts里加入 10.0.0.116 c2, 然后在name和c2节点的slaves里添加c2 ,然后在c2节点里启动输入:
bin/start-daemon start datanode
bin/start-daemon start tasktrack
【转】Debian Linux下安装iscsi targets
技术学习/linux学习 2011/07/13 14:27转自 http://hi.baidu.com/shxr/blog/item/d55372cf7486c237f8dc61dd.html
debian 下安装iscsi targets
服务端IP:192.168.128.143
客户端IP:192.168.128.144
服务端设置:
1、安装 iscsi targets
apt-get install iscsitarget
2、安装内核模块
#uname -a
Linux debian52 2.6.26-2-686
选择安装与内核相符的 iscsitarget-modules
#aptitude search iscsitarge
#apt-get install iscsitarget-modules-2.6.26-2-686
3、配置 /etc/ietd.conf
我的配置如下:
Target iqn.2001-04.cn.shxr:storage.disk1
Lun 0 Path=/dev/sdb,Type=fileio
Lun 1 Path=/dev/sdc,Type=fileio
MaxConnections 10
InitialR2T Yes
可以根据需要设置多个Target
4、为了安全需要可以加入认证
认证文件:/etc/initiators.allow
/etc/initiators.deny
5、设置开机自动启动
vi /etc/default/iscsitarget
ISCSITARGET_ENABLE=true
6、 /etc/init.d/iscsitarget start
7、查看客户端连接状态
cat /proc/net/iet/session
注:如果服务器端硬盘做的是逻辑卷的话,在/etc/ietd.conf配置中应该为:
Lun 0 Path=/dev/mapper/vg_group-data1,Type=fileio
Lun 1 Path=/dev/mapper/vg_group-data1,Type=fileio
以上注意路径不是/dev/vg_group
更多关于LVM设置请参考:http://hi.baidu.com/shxr/blog/item/3943d62aca056991033bf6ce.html
客户端设置:
1、安装iSCSI initiator
apt-get install open-iscsi
2、vi /etc/iscsi/iscsid.conf
node.startup = automatic #开机自动挂载
3、查找iSCSI targets主机的target name
iscsiadm --mode discovery --type sendtargets --portal 192.168.128.143
4、登录
iscsiadm -m discovery --type sendtargets --portal 192.168.128.143,1 iqn.2001-04.cn.shxr:storage.disk1 --login
查看已经登录的iSCSI target
iscsiadm -m node
5、重启服务
/etc/init.d/open-iscsi restart
6、查看iscsi targets映射过来的卷
fdisk -l
然后分区、格式化、挂载 就可以当本地硬盘用了
7、注销
先注销前要umount映射过来的卷,在注销
iscsiadm --mode node --targetname iqn.2001-04.cn.shxr:storage.disk1 --portal 192.168.128.143 --logout
8、删除 iscsi targets
iscsiadm -m node -o delete --targetname iqn.2001-04.cn.shxr:storage.disk1 --portal 192.168.128.143
iscsiadm -m node -o delete --targetname iqn.2001-04.cn.shxr:storage.data2 --portal 192.168.128.136
9、windows 客户端安装 Microsoft iSCSI Initiator
wget检查外部网站运行情况
技术学习/系统管理 2011/03/07 16:25WEB_LIST="web_list.txt"
WGET_LOG="wget.log"
Rserver="runing.server"
Dserver="down.server"
Total_sites=`wc -l $WEB_LIST |awk '{print $1}'`
Run_servers=`wc -l $Rserver |awk '{print $1}'`
Down_servers=`wc -l $Dserver |awk '{print $1}'`
while read LINE
do
echo $LINE >$PWD/temp.ul
ID=`awk '{printf $1}' $PWD/temp.ul`
URL=`awk '{printf $2}' $PWD/temp.ul`
wget --server-response --spider --timeout=30 --tries=1 $URL -o $WGET_LOG
Result=`grep HTTP $WGET_LOG |grep 200`
if [ "$Result" != "" ]
then
echo $ID >> $Rserver
else
echo $ID >> $Dserver
fi
rm $WGET_LOG
done<$WEB_LIST
echo "Total servers has checked is : $Total_sites"
echo "The Running Servers is : $Run_servers"
echo "The down Servers is : $Down_servers"

