有时候要用到Xml的读取和写入,甚至有时候需要新建一个Xml,但是好长时间不用这东西,都忘了,所以就写了一个类库,想用的时候直接拿过来用就OK了
下面是代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; namespace Xmlleiku { public class Xmllei { public static string xmlpath = string.Empty; /// <summary> /// 初始化xml的物理地址 /// </summary> /// <param name="path">物理地址</param> public Xmllei(string path) { xmlpath = path; } /// <summary> /// 读取xml中的内容 /// </summary> /// <param name="element">节点的名字</param> public Dictionary<int, string[]> Reader(string element) { XmlDocument xodc = new XmlDocument(); xodc.Load(xmlpath); XmlNodeList lis = xodc.GetElementsByTagName(element); Dictionary<int, string[]> dic = new Dictionary<int, string[]>(); int j = 0; foreach (XmlNode item in lis) { string[] a = new string[item.ChildNodes.Count]; for (int i = 0; i < item.ChildNodes.Count; i++) { a[i] = item.ChildNodes.Item(i).InnerText; } dic.Add(j++, a); } return dic; } /// <summary> /// 写入已有的Xml文档 /// </summary> /// <param name="element">对应的标签组</param> /// <param name="meirong">与标签对应的内容</param> /// <returns></returns> public int Write(string[] element, List<string[]> meirong) { int j=0; try { XmlDocument xodc = new XmlDocument(); xodc.Load(xmlpath); foreach (string[] item1 in meirong) { int i = 1; XmlElement a = xodc.CreateElement(element[0]); foreach (string item2 in item1) { XmlElement b = xodc.CreateElement(element[i++]); b.AppendChild(xodc.CreateTextNode(item2)); a.AppendChild(b); } j++; xodc.DocumentElement.AppendChild(a); xodc.Save(xmlpath); } return j; } catch { return 0; } } /// <summary> /// 创建一个新的Xml文档 /// </summary> /// <param name="element">包含Xml文档的根目录的标签组</param> /// <param name="meirong">内容数组</param> /// <returns></returns> public int Create(string[] element,List<string[]> meirong) { int j = 0; XmlWriterSettings sttingsw = new XmlWriterSettings(); sttingsw.Encoding = System.Text.Encoding.UTF8; sttingsw.Indent = true; using (XmlWriter writer = XmlWriter.Create(xmlpath)) { writer.WriteStartDocument(); writer.WriteStartElement(element[0]); foreach (string[] item1 in meirong) { int i = 2; writer.WriteStartElement(element[1]); foreach (string item2 in item1) { writer.WriteStartElement(element[i++]); writer.WriteString(item2); writer.WriteEndElement(); } writer.WriteEndElement(); j++; } writer.WriteEndElement(); writer.WriteEndDocument(); } return j; } } }
1. finger:查询用户信息,也能查看默认的用户环境。
2. ftp:标准的文件传输协议的用户接口,是在网络上传输文件最简单有效的方法。
3. host:用于DNS查询。
4. hostname:用于显示或设置系统的主机名。
5. ifconfig:用于配置网卡接口。(可以使用down或up参数来禁用或启用某个网卡接口)
6. mail:发送和接收邮件。
7. netstat:显示网络连接、路由表和网络接口信息,用户可以知道目前那些网络连接正在运行。
8. ping:此命令用于测试本计算机和网络上其它的计算机是否相连。
9. rlogin:远程登陆命令,该命令与telnet命令很相似,允许用户启动远程系统的交互会话。
10. rcp:rcp(remote file copy)命令是远程文件复制命令,该命令用于在计算机之间复制文件,有两中格式,一种格式用于文件动文件的复制,另一种用于把文件或目录复制到其他文件目录中。
11. route:此命令用于显示或设置IP路由表。
12. tcpdump:此命令用于测试网络的通信量。
13. talk:此命令可用于事项网络用户的适时交谈,但是必须将双方系统的信息加入各自的/etc/hosts文件中,以相互识别。
14. telnet:此命令用于通过网络登陆远程计算机,如同操作本地计算机一样。
15. wall:wall(write all)命令可以用于发送消息给登陆本机的用户。在发送消息时,可直接输入要发送的消息,也可以把文件当成消息发送。
16. wget:此命令用于Linux环境下从Internet上下载文件,支持http和ftp协议,支持代理服务器和断点连续传功能,能够递归远程主机上的目录,查找合乎要求的的文件并下载到本地硬盘上。Wget命令可以在后台运行,截获并忽略hantfup信号,因此用户退出登陆后,仍可继续运行。
17. &,bg:&,bg命令是后台执行命令,有时候用户执行的程序可能要话很多时间,如果放在前台执行,可能无法继续其他操作,最好将他放在后台执行。
18. fg:fg命令是前台执行命令,如果用户有程序在后台运行,可以通过fg命令将程序从后台移到前台执行。
19. jobs:此命令用于显示正在后台执行的任务清单。Bg,fg,jobs命令都属于bash命令,
20. kill:此命令用于终止一个程序,例如:#[root@rathat9 root]kill 3793
21. ps:此命令用于显示程序的状态。
22. top:此命令用于显示当前CPU进程。
23. at batch atp atrm:这些命令用于排序,检查或删除后台运行的任务。
待续。。。。
之前由于在项目中使用的solr3.6,服务器总是莫名其妙的挂掉,各种解决未果,于是尝试换到solr4,想试试solrcloud和zookeeper集群看看效果怎么样,实际效果比3.6稳定很多,下面说一下项目中我们的具体现在一个测试的配置。 我们配置3台zookper服务器和3台solr服务器,由于没有多台机器测试,zookeeper的集群都在一台服务器上,tomcat部署在3台服务器上。
zookeeper是什么tar -xf -C /home/myuser/zookeeper/
cd /home/myuser/zookeeperA/conf cp zoo_sample.cfg zoo.cfg(3)修改zoo.cfg
# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/home/myuser/zooA/data # the port at which the clients will connect clientPort=2181 # ZooKeeper server and its port no. # ZooKeeper ensemble should know about every other machine in the ensemble # specify server id by creating 'myid' file in the dataDir # use hostname instead of IP address for convenient maintenance server.1=127.0.0.1:2888:3888 server.2=127.0.0.1:2988:3988 server.3=127.0.0.1:2088:3088 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 dataLogDir=/home/myuser/zooA/logtickTime:心跳时间,为了确保连接存在的,以毫秒为单位,最小超时时间为两个心跳时间
(4)创建myid文件
cd /home/myuser/zooA/data sudo sh -c 'echo "1" >> myid'其他文件夹类似创建myid文件,zookeeperB为2,zookeeperC为3
cd /home/myuser/zookeeperA/bin sudo sh zkServer.sh start查看zookeeper状态
[root@weibo bin]# sh zkServer.sh status JMX enabled by default Using config: /home/weibo/zookeeperA/bin/../conf/zoo.cfg Mode: follower启动OK,依次启动另外两台zookeeper,启动第一台zookeeper后,你可以观察bin下的zookeeper.out可以看到报错,connection refused,没有关系,zookeeper需要等待其他另个节点的加入,全部启动之后就正常了。
[root@weibo bin]# sh zkCli.sh Connecting to localhost:2181 2013-05-10 15:00:25,363 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.5-1392090, built on 09/30/2012 17:52 GMT 2013-05-10 15:00:25,369 [myid:] - INFO [main:Environment@100] - Client environment:host.name=localhost 2013-05-10 15:00:25,370 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.6.0_33 2013-05-10 15:00:25,371 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Sun Microsystems Inc. 2013-05-10 15:00:25,372 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/home/weibo/jdk1.6.0_33/jre 2013-05-10 15:00:25,373 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/home/weibo/zookeeperA/bin/../build/classes:/home/weibo/zookeeperA/bin/../build/lib/*.jar:/home/weibo/zookeeperA/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/weibo/zookeeperA/bin/../lib/slf4j-api-1.6.1.jar:/home/weibo/zookeeperA/bin/../lib/netty-3.2.2.Final.jar:/home/weibo/zookeeperA/bin/../lib/log4j-1.2.15.jar:/home/weibo/zookeeperA/bin/../lib/jline-0.9.94.jar:/home/weibo/zookeeperA/bin/../zookeeper-3.4.5.jar:/home/weibo/zookeeperA/bin/../src/java/lib/*.jar:/home/weibo/zookeeperA/bin/../conf:/home/weibo/jdk1.6.0_33/lib:. 2013-05-10 15:00:25,373 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/home/weibo/jdk1.6.0_33/jre/lib/amd64/server:/home/weibo/jdk1.6.0_33/jre/lib/amd64:/home/weibo/jdk1.6.0_33/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib 2013-05-10 15:00:25,374 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp 2013-05-10 15:00:25,375 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA> 2013-05-10 15:00:25,375 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux 2013-05-10 15:00:25,376 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64 2013-05-10 15:00:25,377 [myid:] - INFO [main:Environment@100] - Client environment:os.version=2.6.32-279.5.2.el6.x86_64 2013-05-10 15:00:25,377 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root 2013-05-10 15:00:25,378 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root 2013-05-10 15:00:25,379 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/home/weibo/zookeeperA/bin 2013-05-10 15:00:25,382 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@9d04653 Welcome to ZooKeeper! 2013-05-10 15:00:25,604 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@966] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (无法定位登录配置) JLine support is enabled 2013-05-10 15:00:25,649 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@849] - Socket connection established to localhost/127.0.0.1:2181, initiating session 2013-05-10 15:00:25,842 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1207] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x13e7e067764005d, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: localhost:2181(CONNECTED) 0] ls / [configs, zookeeper, clusterstate.json, aliases.json, live_nodes, overseer, overseer_elect, collections] [zk: localhost:2181(CONNECTED) 1]configs:保存