首页 文章 精选 留言 我的

精选列表

搜索[快速],共10000篇文章
优秀的个人博客,低调大师

快速搭建一个Fabric 1.0的环境

之前笔者写了一篇Fabric1.0 Beta的部署和Fabric 1.0的多机部署。但是很多人在部署Fabric的时候还是很容易出问题,所以我就再把Fabric 1.0的单机环境搭建讲一下。其实很多内容和前面博客相同。下面开始我们的环境搭建工作: 1. 使用VirtualBox并在其中安装好Ubuntu 这一步其实没啥好说的,下载好最新版的VirtualBox,下载Ubuntu Server,我用的是Ubuntu16.04.2 X64 Server。在安装完Ubuntu后,需要保证apt source是国内的,不然如果是国外的话会很慢很慢的。具体做法是 sudo vi /etc/apt/sources.list 打开这个apt源列表,如果其中看到是http://us.xxxxxx之类的,那么就是外国的,如果看到是http://cn.xxxxx之类的,那么就不用换的。我的是美国的源,所以需要做一下批量的替换。在命令模式下,输入: :%s/us./cn./g 就可以把所有的us.改为cn.了。然后输入:wq即可保存退出。 sudo apt-get update 更新一下源。 然后安装ssh,这样接下来就可以用putty或者SecureCRT之类的客户端远程连接Ubuntu了。 sudo apt-get install ssh 2. Go的安装 Ubuntu的apt-get虽然提供了Go的安装,但是版本比较旧,最好的方法还是参考官方网站https://golang.org/dl/,下载最新版的Go。具体涉及到的命令包括: wget https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz sudo tar -C /usr/local -xzf go1.9.linux-amd64.tar.gz 【注意:不要使用apt方式安装go,apt的go版本太低了!】 接下来编辑当前用户的环境变量: vi ~/.profile 添加以下内容: export PATH=$PATH:/usr/local/go/bin export GOROOT=/usr/local/go export GOPATH=$HOME/go export PATH=$PATH:$HOME/go/bin 编辑保存并退出vi后,记得把这些环境载入: source ~/.profile 我们把go的目录GOPATH设置为当前用户的文件夹下,所以记得创建go文件夹 cd ~ mkdir go 3. Docker安装 我们可以使用阿里提供的镜像,安装也非常方便。通过以下命令来安装Docker curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | sh - 安装完成后需要修改当前用户(我使用的用户叫fabric)权限: sudo usermod -aG docker fabric 注销并重新登录,然后添加阿里云的Docker Hub镜像: sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://obou6wyb.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker 不同的版本添加方法是不一样的,官方的文档如下: https://cr.console.aliyun.com/#/accelerator 当然觉得阿里云镜像不好用,喜欢用DaoClound的也可以用DaoClound的镜像。DaoCloud的镜像设置文档为:https://www.daocloud.io/mirror#accelerator-doc 4. Docker-Compose的安装 Docker-compose是支持通过模板脚本批量创建Docker容器的一个组件。在安装Docker-Compose之前,需要安装Python-pip,运行脚本: sudo apt-get install python-pip 然后是安装docker-compose,我们从官方网站(https://github.com/docker/compose/releases)下载也可以从国内的进行DaoClound下载,为了速度快接下来从DaoClound安装Docker-compose,运行脚本: curl -L https://get.daocloud.io/docker/compose/releases/download/1.12.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose sudo mv ~/docker-compose /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose 5. Fabric源码下载 我们可以使用Git命令下载源码,首先需要建立对应的目录,然后进入该目录,Git下载源码: mkdir -p ~/go/src/github.com/hyperledger cd ~/go/src/github.com/hyperledger git clone https://github.com/hyperledger/fabric.git 由于Fabric一直在更新,所有我们并不需要最新最新的源码,需要切换到v1.0.0版本的源码即可: cd ~/go/src/github.com/hyperledger/fabric git checkout v1.0.0 6. Fabric Docker镜像的下载 这个其实很简单,因为我们已经设置了Docker Hub镜像地址,所以下载也会很快。官方文件也提供了批量下载的脚本。我们直接运行: cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli/ source download-dockerimages.sh -c x86_64-1.0.0 -f x86_64-1.0.0 这样就可以下载所有需要的Fabric Docker镜像了。由于我们设置了国内的镜像,所以下载应该是比较快的。 下载完毕后,我们运行以下命令检查下载的镜像列表: docker images 得到的结果如下: 7.启动Fabric网络并完成ChainCode的测试 我们仍然停留在e2e_cli文件夹,这里提供了启动、关闭Fabric网络的自动化脚本。我们要启动Fabric网络,并自动运行Example02 ChainCode的测试,执行一个命令: ./network_setup.sh up 这个做了以下操作: 7.1编译生成Fabric公私钥、证书的程序,程序在目录:fabric/release/linux-amd64/bin 7.2基于configtx.yaml生成创世区块和通道相关信息,并保存在channel-artifacts文件夹。 7.3基于crypto-config.yaml生成公私钥和证书信息,并保存在crypto-config文件夹中。 7.4基于docker-compose-cli.yaml启动1Orderer+4Peer+1CLI的Fabric容器。 7.5在CLI启动的时候,会运行scripts/script.sh文件,这个脚本文件包含了创建Channel,加入Channel,安装Example02,运行Example02等功能。 最后运行完毕,我们可以看到这样的界面: 如果您看到这个界面,这说明我们整个Fabric网络已经通了。 8.手动测试一下Fabric网络 我们仍然是以现在安装好的Example02为例,在官方例子中,channel名字是mychannel,链码的名字是mycc。我们首先进入CLI,我们重新打开一个命令行窗口,输入: docker exec -it cli bash 运行以下命令可以查询a账户的余额: peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}' 可以看到余额是90: 然后,我们试一试把a账户的余额再转20元给b账户,运行命令: peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -c '{"Args":["invoke","a","b","20"]}' 运行结果为: 现在转账完毕, 我们试一试再查询一下a账户的余额,没问题的话,应该是只剩下70了。我们看看实际情况: 果然,一切正常。最后我们要关闭Fabric网络,首先需要运行exit命令退出cli容器。关闭Fabric的命令与启动类似,命令为: cd ~/go/src/github.com/hyperledger/fabric/examples/e2e_cli ./network_setup.sh down 现在我们整个Fabric的环境已经测试完毕,恭喜,一切正常,接下来我们就是去做自己的区块链的开发。希望我的文章对大家有所帮助。 本文转自深蓝居博客园博客,原文链接:http://www.cnblogs.com/studyzy/p/7437157.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

C# 版 flvmerge:快速合并多个flv文件

网上的视频很多都是分片的flv文件,怎么把他们合为一体呢?GUI工具就不考虑了,不适合批量执行,不适合在后台运行。有没有命令行工具或库可以实现呢? ffmpeg提供了一个方法: (1)先把flv文件转换成mpeg; (2)将多个mpeg文件合并成1个独立的mpeg文件(二进制合并即可) (3)将独立的mpeg文件转换成独立的flv文件。 网上搜到的最多的也是这种解决办法。这种方法有两个缺点: (1)需要两遍转码,非常耗时; (2)转换后的独立的mpeg文件比原视频要短一点点。 木有办法了,只好另寻他路。有人说有一个flvmerge.exe程序可以将多个flv合并成一个,可惜的是俺搜了很久,都没找到这个程序,最后还是在一款免费软件里把这个“flvmerge.exe”文件给揪出来了,不幸的是,这个“flvmerge.exe”得不到正确的结果。 润之同学说过,自己动手,丰衣足食。上github上搜“flvmerge”,发现两个项目,“flvmerge”和“flvmerger”,都是C写的。前者不依赖于第三方库,后者依赖于第三方库,那么就从第一个开始吧。 看了看它的代码,知道了flv文件合并的原理: (1)flv文件由1个header和若干个tag组成; (2)header记录了视频的元数据; (3)tag是有时间戳的数据; (4)flv合并的原理就是把多个文件里的tag组装起来,调整各tag的时间戳,再在文件起始处按个头部。 下面是我参照flvmerge项目,用linqpad写的一个C#版本的flvmerge代码: 1 void Main() 2 { 3 String path1 = "D:\\Videos\\Subtitle\\OutputCache\\1.flv"; 4 String path2 = "D:\\Videos\\Subtitle\\OutputCache\\2.flv"; 5 String path3 = "D:\\Videos\\Subtitle\\OutputCache\\3.flv"; 6 String output = "D:\\Videos\\Subtitle\\OutputCache\\output.flv"; 7 8 using(FileStream fs1 = new FileStream(path1, FileMode.Open)) 9 using(FileStream fs2 = new FileStream(path2, FileMode.Open)) 10 using(FileStream fs3 = new FileStream(path3, FileMode.Open)) 11 using(FileStream fsMerge = new FileStream(output, FileMode.Create)) 12 { 13 Console.WriteLine(IsFLVFile(fs1)); 14 Console.WriteLine(IsFLVFile(fs2)); 15 Console.WriteLine(IsFLVFile(fs3)); 16 17 if(IsSuitableToMerge(GetFLVFileInfo(fs1),GetFLVFileInfo(fs2)) == false 18 || IsSuitableToMerge(GetFLVFileInfo(fs1),GetFLVFileInfo(fs3)) == false) 19 { 20 Console.WriteLine("Video files not suitable to merge"); 21 } 22 23 int time = Merge(fs1,fsMerge,true,0); 24 time = Merge(fs2,fsMerge,false,time); 25 time = Merge(fs3,fsMerge,false,time); 26 Console.WriteLine("Merge finished"); 27 } 28 } 29 30 const int FLV_HEADER_SIZE = 9; 31 const int FLV_TAG_HEADER_SIZE = 11; 32 const int MAX_DATA_SIZE = 16777220; 33 34 class FLVContext 35 { 36 public byte soundFormat; 37 public byte soundRate; 38 public byte soundSize; 39 public byte soundType; 40 public byte videoCodecID; 41 } 42 43 bool IsSuitableToMerge(FLVContext flvCtx1, FLVContext flvCtx2) 44 { 45 return (flvCtx1.soundFormat == flvCtx2.soundFormat) && 46 (flvCtx1.soundRate == flvCtx2.soundRate) && 47 (flvCtx1.soundSize == flvCtx2.soundSize) && 48 (flvCtx1.soundType == flvCtx2.soundType) && 49 (flvCtx1.videoCodecID == flvCtx2.videoCodecID); 50 } 51 52 bool IsFLVFile(FileStream fs) 53 { 54 int len; 55 byte[] buf = new byte[FLV_HEADER_SIZE]; 56 fs.Position = 0; 57 if( FLV_HEADER_SIZE != fs.Read(buf,0,buf.Length)) 58 return false; 59 60 if (buf[0] != 'F' || buf[1] != 'L' || buf[2] != 'V' || buf[3] != 0x01) 61 return false; 62 else 63 return true; 64 } 65 66 FLVContext GetFLVFileInfo(FileStream fs) 67 { 68 bool hasAudioParams, hasVideoParams; 69 int skipSize, readLen; 70 int dataSize; 71 byte tagType; 72 byte[] tmp = new byte[FLV_TAG_HEADER_SIZE+1]; 73 if (fs == null) return null; 74 75 FLVContext flvCtx = new FLVContext(); 76 fs.Position = 0; 77 skipSize = 9; 78 fs.Position += skipSize; 79 hasVideoParams = hasAudioParams = false; 80 skipSize = 4; 81 while (!hasVideoParams || !hasAudioParams) 82 { 83 fs.Position += skipSize; 84 85 if (FLV_TAG_HEADER_SIZE+1 != fs.Read(tmp,0,tmp.Length)) 86 return null; 87 88 tagType = (byte)(tmp[0] & 0x1f); 89 switch (tagType) 90 { 91 case 8 : 92 flvCtx.soundFormat = (byte)((tmp[FLV_TAG_HEADER_SIZE] & 0xf0) >> 4) ; 93 flvCtx.soundRate = (byte)((tmp[FLV_TAG_HEADER_SIZE] & 0x0c) >> 2) ; 94 flvCtx.soundSize = (byte)((tmp[FLV_TAG_HEADER_SIZE] & 0x02) >> 1) ; 95 flvCtx.soundType = (byte)((tmp[FLV_TAG_HEADER_SIZE] & 0x01) >> 0) ; 96 hasAudioParams = true; 97 break; 98 case 9 : 99 flvCtx.videoCodecID = (byte)((tmp[FLV_TAG_HEADER_SIZE] & 0x0f)); 100 hasVideoParams = true; 101 break; 102 default : 103 break; 104 } 105 106 dataSize = FromInt24StringBe(tmp[1],tmp[2],tmp[3]); 107 skipSize = dataSize - 1 + 4; 108 } 109 110 return flvCtx; 111 } 112 113 int FromInt24StringBe(byte b0, byte b1, byte b2) 114 { 115 return (int)((b0<<16) | (b1<<8) | (b2)); 116 } 117 118 int GetTimestamp(byte b0, byte b1, byte b2, byte b3) 119 { 120 return ((b3<<24) | (b0<<16) | (b1<<8) | (b2)); 121 } 122 123 void SetTimestamp(byte[] data, int idx, int newTimestamp) 124 { 125 data[idx + 3] = (byte)(newTimestamp>>24); 126 data[idx + 0] = (byte)(newTimestamp>>16); 127 data[idx + 1] = (byte)(newTimestamp>>8); 128 data[idx + 2] = (byte)(newTimestamp); 129 } 130 131 int Merge(FileStream fsInput, FileStream fsMerge, bool isFirstFile, int lastTimestamp = 0) 132 { 133 int readLen; 134 int curTimestamp = 0; 135 int newTimestamp = 0; 136 int dataSize; 137 byte[] tmp = new byte[20]; 138 byte[] buf = new byte[MAX_DATA_SIZE]; 139 140 fsInput.Position = 0; 141 if (isFirstFile) 142 { 143 if(FLV_HEADER_SIZE+4 == (fsInput.Read(tmp,0,FLV_HEADER_SIZE+4))) 144 { 145 fsMerge.Position = 0; 146 fsMerge.Write(tmp,0,FLV_HEADER_SIZE+4); 147 } 148 } 149 else 150 { 151 fsInput.Position = FLV_HEADER_SIZE + 4; 152 } 153 154 while(fsInput.Read(tmp, 0, FLV_TAG_HEADER_SIZE) > 0) 155 { 156 dataSize = FromInt24StringBe(tmp[1],tmp[2],tmp[3]); 157 curTimestamp = GetTimestamp(tmp[4],tmp[5],tmp[6],tmp[7]); 158 newTimestamp = curTimestamp + lastTimestamp; 159 SetTimestamp(tmp,4, newTimestamp); 160 fsMerge.Write(tmp,0,FLV_TAG_HEADER_SIZE); 161 162 readLen = dataSize+4; 163 if (fsInput.Read(buf,0,readLen) > 0) { 164 fsMerge.Write(buf, 0, readLen); 165 } else { 166 goto failed; 167 } 168 } 169 170 return newTimestamp; 171 172 failed: 173 throw new Exception("Merge Failed"); 174 } 测试通过,合并速度很快! 不过,这个方法有一个缺点:没有将各个文件里的关键帧信息合并,这个关键帧信息,切分flv文件时很重要,合并时就没那么重要了。如果确实需要的话,可以用yamdi来处理。 本文转自xiaotie博客园博客,原文链接:http://www.cnblogs.com/xiaotie/p/3441030.html,如需转载请自行联系原作者

优秀的个人博客,低调大师

CentOS 7 快速架设hadoop 2.5.1集群

1、软件准备a.OS:CentOS-7.0-1406-x86_64-DVD.iso --去CentOS官网下 b.JDK:jdk-7u71-linux-x64.gz --oracle官网下,至于1.8是否可行,没试 c.Hadoop: hadoop-2.5.1.tar.gz --hadoop官网下 d.虚拟机: VMware Player --小巧够用, 其他虚拟机也行2.环境介绍a.主机: 192.168.1.100 master 192.168.1.101 slave1 192.168.1.102 slave2 192.168.1.103 slave3 b.用户: Master SSH无密码登陆slaver 主机用户1: root 密码 hadoop 主机用户2: hadoop 密码 hadoop c.JDK位置: /usr/local 即/usr/local/jdk1.7.0_71 d.hadoop 位置: /opt 即/opt/hadoop-2.5.1 e.SSH公匙位置 /home/hadoop/.ssh/ 即hadoop用户的根目录下的.shh隐藏目录,hadoop登陆后 $cd ~/.ssh 可进入3、安装思路 由于master与slave除了IP地址不同外,其他配置基本相同(懒的话主机名不改都没问题^_^),所以思路就是配置好Master后将虚拟机复制,然后修改网络配置,将是最简单的办法。4、安装步骤a.建立虚拟机: 测试的话10G硬盘 2G RAM足够了),最小化安装centos7。其中: 分区自动 root密码 hadoop 另建立一个新用户hadoop 密码hadoop 主机名master(懒得后面改) ip地址设置静态(懒得后面配置,并启动网卡): IP:192.168.1.100 mask:255.255.255.0 gateway:192.168.1.1 DNS1:192.168.1.1 DNS2:8.8.8.8 b-关闭防火墙 systemctl stop firewalld.service --关闭防火墙 systemctl disable firewalld.service --永久关闭防火墙 c.增加五个工具(后续操作,若#都是root用户 $的都是hadoop用户,本节可选): --vim #yum -y install vim --ifconfig #yum -y net-tools --时间同步 #yum -y install ntp #ntpdate us.pool.ntp.org #cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime --系统信息 #yum install -y sysstat --tree命令 #yum install -y tree d.修改hosts # vim /etc/hosts 按i进入插入模式,用#号注释掉已有,加入四行,: 192.168.1.100 master 192.168.1.101 slave1 192.168.1.102 slave2 192.168.1.103 slave3 按ESC :wq回车 e.修改ip 若安装没设置IP或者网卡没有启动: [root@master ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:3d:ed:03 brd ff:ff:ff:ff:ff:ff inet 192.168.1.11/24 brd 192.168.88.255 scope global eno16777736 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe3d:ed03/64 scope link valid_lft forever preferred_lft forever 注意看2后面的eno16777736就是网卡名,然后编辑网卡配置: [root@master ~]# vim /etc/sysconfig/network-scripts/ifcfg-eno16777736 HWADDR=00:0C:29:3D:ED:03 TYPE=Ethernet BOOTPROTO=static ##重要,否则dhcp了 IPADDR=192.168.1.100 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 BROADCAST=192.168.1.255 DNS1=192.168.1.1 DNS2=8.8.8.8 ONBOOT=yes ##重要,这个为no则系统启动不启动该网卡 至少保证以上信息,其他的不管,重启网络: #service network restart5、SSH无密码登陆#su hadoop $cd ~ $mkdir .ssh $chmod 744 .ssh ##权限重要,默认权限可以,本步骤可选 $ssh-keygen -t rsa -P '' ##ssh后无空格!!! $cat ~/.ssh/id_rsa.pub>>~/.ssh/authorized_keys ##将公钥追加到AuthorizedKeysFile $chmod 644 ~/.ssh/authorized_keys ##权限重要,默认权限不行 $su #vim /etc/ssh/sshd_config 去除前面的# RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys #service sshd restart #重启ssh服务 $su hadoop $ssh localhost 或ssh master Last login: Sat Nov 8 20:16:23 2014 #ssh无密码登陆成功6、连接网络共享,取得安装程序(懒人不架设FTP服务器)其中//192.168.1.9 是台windows 7的电脑,共享目录share,用户名密码均是share,里面放有下载好的JDK(jdk-7u71-linux-x64.gz)与 hadoop 2.5.1 (hadoop-2.5.1.tar.gz): #mkdir /mnt/share #建立共享文件挂载点 #mount -t cifs -o username="share",password="share" //192.168.1.9/share /mnt/share #cd /mnt/share 5.安装jdk #tar xzvf jdk-7u71-linux-x64.gz -C /usr/local/ #vim /etc/profile export JAVA_HOME=/usr/local/jdk1.7.0_71 export PATH=$PATH:$JAVA_HOME/bin #source /etc/profile ## 刷新系统配置 确认版本java安装成果 # java -version java version "1.7.0_71" Java(TM) SE Runtime Environment (build 1.7.0_71-b14) Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)7、安装配置hadoop#cd /mnt/share #tar xzvf hadoop-2.5.1.tar.gz -C /opt/ #chown -R hadoop:hadoop /opt/hadoop-2.5.1 # vim /etc/profile ##修改系统配置 export HADOOP_HOME=/opt/hadoop-2.5.1 export PATH=$PATH:$HADOOP_HOME/bin # source /etc/profile ## 刷新系统配置 # su hadoop $ cd /opt/hadoop-2.5.1 $ mkdir -p dfs/name $ mkdir -p dfs/data $ mkdir -p tmp $ cd etc/hadoop a.配置所有slave节点 $ vim slaves slave1 slave2 slave3 b.修改hadoop-env.sh和yarn-env.sh $ vim hadoop-env.sh export JAVA_HOME=/usr/local/jdk1.7.0_71 $ vim yarn-env.sh export JAVA_HOME=/usr/local/jdk1.7.0_71 c.修改core-site.xml $ vim etc/hadoop/core-site.xml <configuration> <property> <name>fs.defaultFS</name> <value>hdfs://master:9000</value> </property> <property> <name>hadoop.tmp.dir</name> <value>/opt/hadoop-2.5.1/tmp</value> </property> </configuration> 注意:/opt/hadoop-2.5.1/tmp前面不能有 file!!!与hdfs-site.xml不一样,而且所有内容中不能有空格,结尾处也不行!如<value>/opt/hadoop-2.5.1/tmp </value>会出错(tmp后有空格)。 d.修改hdfs-site.xml $ vim etc/hadoop/hdfs-site.xml <configuration> <property> <name>dfs.namenode.name.dir</name> <value>file:/opt/hadoop-2.5.1/dfs/name</value> </property> <property> <name>dfs.datanode.data.dir</name> <value>file:/opt/hadoop-2.5.1/dfs/data</value> </property> <property> <name>dfs.replication</name> <value>3</value> </property> <property> <name>dfs.namenode.secondary.http-address</name> <value>master:9001</value> </property> <property> <name>dfs.permissions</name> <value>false</value> </property> </configuration> e.修改mapred-site.xml $ cd /opt/hadoop-2.5.1 $ cp etc/hadoop/mapred-site.xml.template etc/hadoop/mapred-site.xml $ vim etc/hadoop/mapred-site.xml <configuration> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> </configuration> f.配置yarn-site.xml (a).伪分布配置: $ vim etc/hadoop/yarn-site.xml: <configuration> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> </configuration> (b)集群配置: $ vim etc/hadoop/yarn-site.xml <configuration> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <property> <name>yarn.nodemanager.auxservices.mapreduce.shuffle.class</name> <value>org.apache.hadoop.mapred.ShuffleHandler</value> </property> <property> <name>yarn.resourcemanager.address</name> <value>master:8032</value> </property> <property> <name>yarn.resourcemanager.scheduler.address</name> <value>master:8030</value> </property> <property> <name>yarn.resourcemanager.resource-tracker.address</name> <value>master:8031</value> </property> <property> <name>yarn.resourcemanager.admin.address</name> <value>master:8033</value> </property> <property> <name>yarn.resourcemanager.webapp.address</name> <value>master:8088</value> </property> </configuration>8、关机,复制三台slave#shutdown9、启动slave1,修改网卡配置与主机名#ip addr [root@master ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:fd:1d:23 brd ff:ff:ff:ff:ff:ff inet 192.168.88.11/24 brd 192.168.88.255 scope global eno16777736 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe3d:ed03/64 scope link valid_lft forever preferred_lft forever 注意看2:后面的eno16777736就是网卡名,然后编辑网卡配置: # vim /etc/sysconfig/network-scripts/ifcfg-eno16777736 HWADDR=00:0C:29:FD:1D:23 ##关键1,按刚才查出来的mac地址,eno16777736下面那行 TYPE=Ethernet BOOTPROTO=static ##关键2 IPADDR=192.168.1.101 ##关键3 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 BROADCAST=192.168.1.255 DNS1=192.168.1.1 DNS2=8.8.8.8 ONBOOT=yes ##关键4 至少保证以上信息 # service network restart --重启网络 修改主机名: # hostnamectl set-hostname slave110、启动slave2/slave2,修改网卡配置与主机名 11、格式化namenode$ cd /opt/hadoop-2.5.1 $ hdfs namenode -format12 启动hdfs$ ./sbin/start-dfs.sh $ ./sbin/start-yarn.sh --用pi程序测试: $ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.5.1.jar pi 2 20000 13 检查启动情况http://192.168.1.100:8088 http://192.168.1.100:50070 14、关闭hadoop$ ./sbin/stop-all.sh 本文转自 tianya1993 51CTO博客,原文链接:http://blog.51cto.com/dreamlinux/1744348,如需转载请自行联系原作者

优秀的个人博客,低调大师

CentOS7下快速搭建Docker私有库

1. 安装Docker yum -y install docker 2. 启动Docker服务 systemctl enable docker systemctl start docker 3. 启动Docker私有库 mkdir /home/docker_repo cd /home/docker_repo docker run -d -p 5000:5000 --name registry --restart=always --privileged=true -v $PWD:/var/lib/registry registry:2 4. 提交Docker镜像 docker tag docker.io/hello-world:latest 192.168.1.75:5000/hello-world:latest docker push 192.168.1.75:5000/hello-world 如果push遇到问题,编辑/usr/lib/systemd/system/docker.service,在ExecStart=之后追加一行参数: --insecure-registry=192.168.1.75:5000 \ 然后重启Docker服务: systemctl daemon-reload systemctl restart docker 5. Docker私有库HTTP API 测试库内已有centos和Docker官方的hello-world镜像 查看当前库列表http://192.168.1.75:5000/v2/_catalog 返回: { "repositories": [ "centos", "hello-world" ] } 查看某个库标签列表http://192.168.1.75:5000/v2/hello-world/tags/list 返回: { "name": "hello-world", "tags": [ "latest" ] } 注: 需要把192.168.1.75替换成你的Docker私有库所在服务器IP 本文转自 zl1030 51CTO博客,原文链接:http://blog.51cto.com/zl1030/2047891

优秀的个人博客,低调大师

centos 6.5 x64bit 快速安装openstack

OpenStack是一个美国国家航空航天局和Rackspace合作研发的,以Apache许可证授权,并且是一个自由软件和开放源代码项目。 OpenStack是一个云平台管理的项目,它不是一个软件。这个项目由几个主要的组件组合起来完成一些具体的工作。 OpenStack是一个旨在为公共及私有云的建设与管理提供软件的开源项目。它的社区拥有超过130家企业及1350位开发者,这些机构与个人都将OpenStack作为基础设施即服务(简称IaaS)资源的通用前端。 OpenStack项目的首要任务是简化云的部署过程并为其带来良好的可扩展性。本文希望通过提供必要的指导信息,帮助大家利用OpenStack前端来设置及管理自己的公共云或私有云。 OpenStack 是由 Rackspace 和 NASA 共同开发的云计算平台,帮助服务商和企业内部实现类似于 Amazon EC2 和 S3 的云基础架构服务(Infrastructure as a Service, IaaS)。OpenStack 包含两个主要模块:Nova 和 Swift,前者是 NASA 开发的虚拟服务器部署和业务计算模块;后者是 Rackspace开发的分布式云存储模块,两者可以一起用,也可以分开单独用。OpenStack 是开源项目,除了有 Rackspace 和 NASA 的大力支持外,后面还有包括 Dell、Citrix、 Cisco、 Canonical 这些重量级公司的贡献和支持,发展速度非常快,有取代另一个业界领先开源云平台 Eucalyptus 的态势。 1.[root@localhost ~]#yum install -yhttp://rdo.fedorapeople.org/openstack/openstack-grizzly/rdo-release-grizzly-1.noarch.rpm//安装openstack-grizzly源 Loaded plugins: fastestmirror, security base | 3.7 kB 00:00 base/primary_db | 4.4 MB 00:05 extras | 3.4 kB 00:00 extras/primary_db | 19 kB 00:00 updates | 3.4 kB 00:00 updates/primary_db | 3.7 MB 00:03 Setting up Install Process rdo-release-grizzly-1.noarch.rpm | 7.1 kB 00:03 Examining /var/tmp/yum-root-tkysSj/rdo-release-grizzly-1.noarch.rpm: rdo-release-grizzly-1.noarch Marking /var/tmp/yum-root-tkysSj/rdo-release-grizzly-1.noarch.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package rdo-release.noarch 0:grizzly-1 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: rdo-release noarch grizzly-1 /rdo-release-grizzly-1.noarch 3.2 k Transaction Summary ================================================================================ Install 1 Package(s) Total size: 3.2 k Installed size: 3.2 k Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : rdo-release-grizzly-1.noarch 1/1 Verifying : rdo-release-grizzly-1.noarch 1/1 Installed: rdo-release.noarch 0:grizzly-1 Complete! 2.[root@localhost ~]#yum install -y openstack-packstack //安装openstack-packstack软件包 Loaded plugins: fastestmirror, security Determining fastest mirrors * base: mirrors.163.com * extras: mirrors.163.com * updates: mirrors.163.com openstack-grizzly | 2.9 kB 00:00 openstack-grizzly/primary_db | 992 kB 00:02 Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package openstack-packstack.noarch 0:2013.1.1-0.31.dev696.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: openstack-packstack noarch 2013.1.1-0.31.dev696.el6 openstack-grizzly 605 k Transaction Summary ================================================================================ Install 1 Package(s) Total download size: 605 k Installed size: 1.9 M Downloading Packages: openstack-packstack-2013.1.1-0.31.dev696.el6.noarch.rpm | 605 kB 00:01 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : openstack-packstack-2013.1.1-0.31.dev696.el6.noarch 1/1 Verifying : openstack-packstack-2013.1.1-0.31.dev696.el6.noarch 1/1 Installed: openstack-packstack.noarch 0:2013.1.1-0.31.dev696.el6 Complete! 3.[root@localhost ~]# packstack --allinone //在线安装openstack软件。 Welcome to Installer setup utility Packstack changed given value to required value /root/.ssh/id_rsa.pub Installing: Clean Up... [ DONE ] Setting up sshkeys...root@192.168.200.180'spassword: [ DONE ] Adding pre install manifest entries... [ DONE ] Adding MySQL manifest entries... [ DONE ] Adding QPID manifest entries... [ DONE ] Adding Keystone manifest entries... [ DONE ] Adding Glance Keystone manifest entries... [ DONE ] Adding Glance manifest entries... [ DONE ] Adding Cinder Keystone manifest entries... [ DONE ] Installing dependencies for Cinder... [ DONE ] Checking if the Cinder server has a cinder-volumes vg...[ DONE ] Adding Cinder manifest entries... [ DONE ] Adding Nova API manifest entries... [ DONE ] Adding Nova Keystone manifest entries... [ DONE ] Adding Nova Cert manifest entries... [ DONE ] Adding Nova Conductor manifest entries... [ DONE ] Adding Nova Compute manifest entries... [ DONE ] Adding Nova Scheduler manifest entries... [ DONE ] Adding Nova VNC Proxy manifest entries... [ DONE ] Adding Nova Common manifest entries... [ DONE ] Adding Openstack Network-related Nova manifest entries...[ DONE ] Adding Quantum API manifest entries... [ DONE ] Adding Quantum Keystone manifest entries... [ DONE ] Adding Quantum L3 manifest entries... [ DONE ] Adding Quantum L2 Agent manifest entries... [ DONE ] Adding Quantum DHCP Agent manifest entries... [ DONE ] Adding Quantum Metadata Agent manifest entries... [ DONE ] Adding OpenStack Client manifest entries... [ DONE ] Adding Horizon manifest entries... [ DONE ] Adding Swift Keystone manifest entries... [ DONE ] Adding Swift builder manifest entries... [ DONE ] Adding Swift proxy manifest entries... [ DONE ] Adding Swift storage manifest entries... [ DONE ] Adding Swift common manifest entries... [ DONE ] Adding Provisioning manifest entries... [ DONE ] Preparing servers... [ DONE ] Adding Nagios server manifest entries... [ DONE ] Adding Nagios host manifest entries... [ DONE ] Adding post install manifest entries... [ DONE ] Installing Dependencies... [ DONE ] Copying Puppet modules and manifests... [ DONE ] Applying Puppet manifests... Applying 192.168.200.180_prescript.pp 192.168.200.180_prescript.pp : [ DONE ] Applying 192.168.200.180_mysql.pp Applying 192.168.200.180_qpid.pp 192.168.200.180_mysql.pp : [ DONE ] 192.168.200.180_qpid.pp : [ DONE ] Applying 192.168.200.180_keystone.pp Applying 192.168.200.180_glance.pp Applying 192.168.200.180_cinder.pp 192.168.200.180_keystone.pp : [ DONE ] 192.168.200.180_glance.pp : [ DONE ] 192.168.200.180_cinder.pp : [ DONE ] Applying 192.168.200.180_api_nova.pp 192.168.200.180_api_nova.pp : [ DONE ] Applying 192.168.200.180_nova.pp 192.168.200.180_nova.pp : [ DONE ] Applying 192.168.200.180_quantum.pp 192.168.200.180_quantum.pp : [ DONE ] Applying 192.168.200.180_osclient.pp Applying 192.168.200.180_horizon.pp 192.168.200.180_osclient.pp : [ DONE ] 192.168.200.180_horizon.pp : [ DONE ] Applying 192.168.200.180_ring_swift.pp 192.168.200.180_ring_swift.pp : [ DONE ] Applying 192.168.200.180_swift.pp Applying 192.168.200.180_provision.pp Applying 192.168.200.180_nagios.pp Applying 192.168.200.180_nagios_nrpe.pp 192.168.200.180_swift.pp : [ DONE ] 192.168.200.180_provision.pp : [ DONE ] 192.168.200.180_nagios.pp : [ DONE ] 192.168.200.180_nagios_nrpe.pp : [ DONE ] Applying 192.168.200.180_postscript.pp 192.168.200.180_postscript.pp : [ DONE ] [ DONE ] Finalizing... [ DONE ] **** Installation completed successfully ****** //成功安装如下: Additional information: * A new answerfile was created in: /root/packstack-answers-20140626-162910.txt * Time synchronization installation was skipped. Please note that unsynchronized time on server instances might be problem for some OpenStack components. * To use the command line tools you need to source the file /root/keystonerc_admin created on 192.168.200.180 * To use the console, browse tohttp://192.168.200.180/dashboard * To use Nagios, browse tohttp://192.168.200.180/nagiosusername : nagiosadmin, password : 0e2abdb9d2914cce * The RDO kernel that includes network namespace (netns) support has been installed on host 192.168.200.180. * The installation log file is available at: /var/tmp/packstack/20140626-162910-yqzZnu/openstack-setup.log //如果要进openstack界面直接利用http://192.168.200.180/dashboard进入,用户名有两个一个demo,另一个是admin 密码在/root目录下 4.创建keypair,名字自己写 5.创建映像f19下载地址http://cloud.fedoraproject.org/fedora-19.x86_64.qcow2创建好之后启动 6.启动zh888实例 7.选择网卡点加号放入networks 8.启动好的zh888的实例 本文转自zh888 51CTO博客,原文链接:http://blog.51cto.com/zh888/1431689,如需转载请自行联系原作者

优秀的个人博客,低调大师

详解logstash+elasticsearch+kibana快速搭建日志平台

本文出自 “story的天空” 博客,请务必保留此出处http://storysky.blog.51cto.com/628458/1158707 Logstash是一个完全开源的工具,他可以对你的日志进行收集、分析,并将其存储供以后使用(如,搜索),您可以使用它。说到搜索,logstash带有一个web界面,搜索和展示所有日志。 kibana 也是一个开源和免费的工具,他可以帮助您汇总、分析和搜索重要数据日志并提供友好的web界面。他可以为 Logstash 和 ElasticSearch 提供的日志分析的 Web 界面 说到这里,我们看看 kibana 和 logstash到底能为我们做些什么呢?下面是kibana的界面 简单来讲他具体的工作流程就是 logstash agent 监控并过滤日志,将过滤后的日志内容发给redis(这里的redis只处理队列不做存储),logstash index将日志收集在一起交给 全文搜索服务ElasticSearch 可以用ElasticSearch进行自定义搜索 通过Kibana 来结合 自定义搜索进行页面展示,下图是 Kibana官网上的流程图 好了 让我们一步步的把这套环境搭建起来吧,先看看都需要安装什么软件包ruby 运行Kibana 必须, rubygems 安装ruby扩展必须 bundler 功能类似于yum JDK 运行java程序必须 redis 用来处理日志队列 logstash 收集、过滤日志 ElasticSearch 全文搜索服务(logstash集成了一个) kibana 页面展示 这里有三台服务器192.168.233.128 logstash index,ElasticSearch,kibana,JDK 192.168.233.129 logstash agent,JDK 192.168.233.130 redis 首先到 logstash index服务器上面,logstash分为 index和aget ,agent负责监控、过滤日志,index负责收集日志并将日志交给ElasticSearch 做搜索 此外 logstash 的收集方式分为 standalone 和 centralized。 standalone 是所有功能都在一个服务器上面,自发自收,centralized 就是集中收集,一台服务器接收所有shipper(个人理解就是logstash agent)的日志。 其实 logstash本身不分 什么 shipper 和 collector ,只不过就是配置文件不同而已,我们这次按照集中的方式来测试 在 logstash index上安装基础的软件环境 [192.168.233.128root@nodec:~]#cd/soft/[192.168.233.128root@nodec:/soft]#wgethttp://down1.chinaunix.net/distfiles/jdk-6u13-dlj-linux-i586.bin从oracle下载实在是太慢了,从CU下载会快一些,如果需要最新版本请访问这里http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html[192.168.233.128root@nodec:/soft]#shjdk-6u13-dlj-linux-i586.bin输入yes便开始安装了安装完成后设置一下JAVA_HOME[192.168.233.128root@nodec:/soft/Kibana-0.2.0]#vim/etc/profileexportJAVA_HOME=/usr/javaexportPATH=$JAVA_HOME/bin:$PATHexportCLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH安装ruby就比较简单了(Kibana需要ruby1.8.7以上版本)[192.168.233.128root@nodec:/soft]#yuminstallrubyrubygems.....安装内容省略安装完成后用rubygems来安装bundler[192.168.233.128root@nodec:/soft]#/usr/bin/geminstallbundler.....ok这样基本的环境就已经有了,下面就是安装kibana和logstash其实logstash就是一个java脚本,不需要安装...下载即用[192.168.233.128root@nodec:/soft]#wgethttp://logstash.objects.dreamhost.com/release/logstash-1.1.0-monolithic.jar现在看看这个脚本应该怎么去执行[192.168.233.128root@nodec:/soft]#java-jar/soft/logstash-1.1.0-monolithic.jar-hNosuchcommand"-h"Availablecommands:-v-V--versionagentwebtest显然没有-h参数,不过列出了能用的参数,但是logstash的参数可不止这些,java-jar/soft/logstash-1.1.0-monolithic.jaragent--help这些是在agent模式下的命令参数-f,--configCONFIGFILELoadthelogstashconfigfromaspecificfile,directory,orawildcard.Ifgivenadirectoryorwildcard,configfileswillbereadinorderlexigraphically.-eCONFIGSTRINGUsethegivenstringastheconfigurationdata.Samesyntaxastheconfigfile.Ifnotinputisspecified,'stdin{type=>stdin}'isdefault.Ifnooutputisspecified,'stdout{debug=>true}}'isdefault.-w,--filterworksCOUNTRunCOUNTfilterworkers(default:1)--watchdog-timeoutTIMEOUTSetwatchdogtimeoutvalue.-l,--logFILELogtoagivenpath.Defaultistologtostdout-vIncreaseverbosity.Therearemultiplelevelsofverbosityavailablewith'-vv'currentlybeingthehighest--pluginpathPLUGIN_PATHAcolon-delimtedpathtofindotherlogstashpluginsinjava-jar/soft/logstash-1.1.0-monolithic.jarweb--help下面的是在web界面的参数--logFILELogtoagivenpath.Defaultisstdout.--addressADDRESSAddressonwhichtostartwebserver.Defaultis0.0.0.0.--portPORTPortonwhichtostartwebserver.Defaultis9292.-B,--elasticsearch-bind-hostADDRESSAddressonwhichtobindelasticsearchnode.-b,--backendURLThebackendURLtouse.Defaultiselasticsearch:///(assumesmulticastdiscovery).Youcanspecifyelasticsearch://[host][:port]/[clustername]如果上面的这些命令都能执行正常的话就表示logstash可以使用了,但要让他启动还需要一个配置文件 [192.168.233.128root@nodec:/soft]#vimredis.confinput{redis{host=>'192.168.233.130'data_type=>'list'port=>"6379"key=>'logstash:redis'type=>'redis-input'}}output{elasticsearch{embedded=>true}} 解释一下logstash的配置文件由inputfilteroutput等几个基本的部分组成,顾名思义input就是在那收集数据,output就是输出到哪,filter代表一个过滤规则意思是什么内容 会被收集。 上面这段是让logstash去192.168.233.130这个redis服务器上去收集日志redis端口为6379,key是logstash:redis类型为redis-input,(注意:这几个值必须跟logstashagent的 output所对应),收集完成后输出到elasticsearch,embedded=>true的意思是使用logstash内嵌的elasticsearch。如果有独立的elasticsearch服务器,需要将这条改为 host=>'elasticsearch的ip'port=>端口 好了,这个简单的配置文件可以让logstash开始启动了 [192.168.233.128root@nodec:/soft]#java-jar/soft/logstash-1.1.0-monolithic.jaragent-f/soft/redis.conf--web--backendelasticsearch:///?local&[1]5205...这里要等待约5秒钟...为什么?去问开发者吧[192.168.233.128root@nodec:/soft]#I,[2013-03-19T03:23:10.749000#5205]INFO--:Usingbetaplugin'redis'.Formoreinformationaboutpluginstatuses,seehttp://logstash.net/docs/1.1.0/plugin-status{"timestamp":"2013-03-19T03:23:10.732000-0700","message":"Usingbetaplugin'redis'.Formoreinformationaboutpluginstatuses,seehttp://logstash.net/docs/1.1.0/plugin-status","level":"info"}file:/soft/logstash-1.1.0-monolithic.jar!/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53warning:alreadyinitializedconstantWFKV_Mizuno0.5.0(Jetty8.0.y.z-SNAPSHOT)listeningon0.0.0.0:9292解释一下上面的命令agent代理模式-f指定配置文件--web其实是个分隔符等于又启动了一个命令,后面的参数就是开启一个web页面默认端口是9292,这个命令如果拆成两个就是这个样子java-jar/soft/logstash-1.1.0-monolithic.jaragent-f/soft/redis.conf&java-jar/soft/logstash-1.1.0-monolithic.jarweb--backendelasticsearch:///?local&(其实如果用kibana来做web界面的话这一步完全可以省掉了) 好了,看到9292端口启动就代表启动成功了,检查一下 [192.168.233.128root@nodec:/soft]#lsof-i:9292COMMANDPIDUSERFDTYPEDEVICESIZENODENAMEjava5205root465uIPv4130805TCP*:armtechdaemon(LISTEN)其实logstash还启动了一个端口9200,因为启动了内嵌的elasticsearch,这个9200是elasticsearch在监听[192.168.233.128root@nodec:/soft]#lsof-i:9200COMMANDPIDUSERFDTYPEDEVICESIZENODENAMEjava5205root160uIPv4130682TCP*:wap-wsp(LISTEN) 现在可以通过浏览器访问一下http://192.168.233.128:9292看看logstash是的页面是个什么样子 现在还不能搜索因为现在还没有数据,其实这个时候 http://192.168.233.128:9200 也是可以访问的, 很多开发自己写代码来调用elasticsearch 来实现他们自己的需要,这里就不多说了 192.168.233.128 这台logstash index的操作暂时告一段落,下面开始配置logstash的agent 登录到 服务器 192.168.233.129 安装基本软件包和logstash [192.168.233.129root@noded:~]#cd/soft/[192.168.233.129root@noded:/soft]#wgethttp://down1.chinaunix.net/distfiles/jdk-6u13-dlj-linux-i586.bin[192.168.233.129root@noded:/soft]#shjdk-6u13-dlj-linux-i586.bin设置JAVA_HOME[192.168.233.129root@noded:/soft]#vim/etc/profileexportJAVA_HOME=/usr/javaexportPATH=$JAVA_HOME/bin:$PATHexportCLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH[192.168.233.129root@noded:/soft]#yuminstallruby192.168.233.129root@noded:/soft]#wgethttp://logstash.objects.dreamhost.com/release/logstash-1.1.0-monolithic.jar[192.168.233.129root@noded:/soft]#vimredis.confinput{file{type=>"producer"path=>"/soft/apache.log"}file{type=>"php-log"path=>"/soft/php.log"}}filter{grep{match=>["@message","mysql|GET|error"]}}output{redis{host=>'192.168.233.130'data_type=>'list'key=>'logstash:redis'}} 大概说一下这个配置文件 input 里的file就是要监视的文件了 这里我监视了两个文件,如果这两个文件有追加的内容就会通过下面的output设置发给 redis服务器 filter 里的grep 意思就是 grep... 后面这段就是 日志内容里面只要有匹配mysql或GET或error的内容就会被过滤出来,发送到 logstash index 以上就是一个比较简单的配置文件了,让我们启动他 [192.168.233.129root@noded:/soft]#java-jar/soft/logstash-1.1.0-monolithic.jaragent-f/soft/redis.conf&I,[2013-03-19T19:45:35.762000#2721]INFO--:Usingbetaplugin'file'.Formoreinformationaboutpluginstatuses,seehttp://logstash.net/docs/1.1.0/plugin-status{"timestamp":"2013-03-19T19:45:35.752000-0700","message":"Usingbetaplugin'file'.Formoreinformationaboutpluginstatuses,seehttp://logstash.net/docs/1.1.0/plugin-status","level":"info"}I,[2013-03-19T19:45:35.778000#2721]INFO--:Usingbetaplugin'file'.Formoreinformationaboutpluginstatuses,seehttp://logstash.net/docs/1.1.0/plugin-status{"timestamp":"2013-03-19T19:45:35.778000-0700","message":"Usingbetaplugin'file'.Formoreinformationaboutpluginstatuses,seehttp://logstash.net/docs/1.1.0/plugin-status","level":"info"}I,[2013-03-19T19:45:35.804000#2721]INFO--:Usingbetaplugin'grep'.Formoreinformationaboutpluginstatuses,seehttp://logstash.net/docs/1.1.0/plugin-status{"timestamp":"2013-03-19T19:45:35.803000-0700","message":"Usingbetaplugin'grep'.Formoreinformationaboutpluginstatuses,seehttp://logstash.net/docs/1.1.0/plugin-status","level":"info"}I,[2013-03-19T19:45:35.854000#2721]INFO--:Usingbetaplugin'redis'.Formoreinformationaboutpluginstatuses,seehttp://logstash.net/docs/1.1.0/plugin-status{"timestamp":"2013-03-19T19:45:35.853000-0700","message":"Usingbetaplugin'redis'.Formoreinformationaboutpluginstatuses,seehttp://logstash.net/docs/1.1.0/plugin-status","level":"info"} 只要没有 warning 和 error就算是正常启动了 启动之前请确定 192.168.233.130的 redis服务器已经启动,不然会报错下面登录到 192.168.233.130 上看看 redis服务的状态 [192.168.233.130root@nodea:/data/redis/etc]#lsof-i:6379COMMANDPIDUSERFDTYPEDEVICESIZENODENAMEredis-ser2732root4uIPv47946TCP*:6379(LISTEN)redis-ser2732root5uIPv47963TCPlocalhost.localdomain:6379->localhost.localdomain:19214(ESTABLISHED)java2733root9uIPv47959TCPlocalhost.localdomain:19214->localhost.localdomain:6379(ESTABLISHED)状态正常,端口处于监听状态,我用的是最简单的配置,[192.168.233.130root@nodea:/data/redis/etc]#vimredis.conf#thisistheconfigfileforredispidfile/var/run/redis.pidport6379timeout0loglevelverboselogfile/data/redis/log/redis.logdbfilenamedump.rdbdir/data/redis/db/vm-swap-file/tmp/redis.swapactiverehashingyes启动命令如下[192.168.233.130root@nodea:/data/redis/etc]#redis-server/data/redis/etc/redis.conf& 下载安装就比较简单了 [192.168.233.130root@nodea:/soft]#wgethttp://redis.googlecode.com/files/redis-2.4.14.tar.gz[192.168.233.130root@nodea:/data/redis/etc]#make–j24[192.168.233.130root@nodea:/data/redis/etc]#makeinstall 配置文件里的那几个路径要提前建好 最后我们回到 logstash agent 上面测试一下 [192.168.233.129root@noded:/soft]#echoGET12313>>apache.log[192.168.233.129root@noded:/soft]#echoerrorabcd>>apache.log ok 到 http://192.168.233.128:9292 去搜索一下 刚才的两个内容 嗯,就是这样了,我现在找个php的错误日志给他追加到php.log文件里 [192.168.233.129 root@noded:/soft] # cat php-error.log >> php.log 在看看 logstash的页面 搜索一下 error OK,最后就是 Kibana了 ,我把Kibana装在了 logstash index上面 下载地址为 http://kibana.org/intro.html [192.168.233.128root@nodec:/soft]#tarxfKibana-0.2.0.tar.gz[192.168.233.128root@nodec:/soft]#cdKibana-0.2.0[192.168.233.128root@nodec:/soft/Kibana-0.2.0]#bundleinstall直接安装就好了,非常简单,因为之前咱们已经安装好了bundle编辑配置文件,指定elasticsearch的位置[192.168.233.128root@nodec:/soft/Kibana-0.2.0]#vimKibanaConfig.rb.....Elasticsearch="localhost:9200"KibanaPort=5601KibanaHost='0.0.0.0'.....主要是这几个参数启动的话需要ruby[192.168.233.128root@nodec:/soft/Kibana-0.2.0]#/usr/bin/rubykibana.rb&[192.168.233.128root@nodec:/soft/Kibana-0.2.0]#==Sinatra/1.3.5hastakenthestageon5601fordevelopmentwithbackupfromThin>>Thinwebserver(v1.5.0codenameKnife)>>Maximumconnectionssetto1024>>Listeningon0.0.0.0:5601,CTRL+Ctostop如果ruby的东西都不缺的话,启动会很顺利,ok现在看看5601端口的状态[192.168.233.128root@nodec:/soft/Kibana-0.2.0]#lsof-i:5601COMMANDPIDUSERFDTYPEDEVICESIZENODENAMEruby3116root5uIPv428947TCP*:esmagent(LISTEN) 访问一下 试试看 http://192.168.233.128:5601 尝试搜索一下php的错误日志,比如mysql 要的就是这个效果,日志会实时的汇总到 logstash index 上供我们查询,当然这只是开始使用logstash的第一步而已,更多的高级功能可以看看官方文档http://logstash.net/docs/1.1.9/ 据说还可以跟nagios,rsyslog结合. 本文转自 wdy198622 51CTO博客,原文链接:http://blog.51cto.com/weimouren/1716357

优秀的个人博客,低调大师

10分钟快速配置LAMP环境

关于LAMP的文档在网上能搜到很多,但是大多数都是编译安装为主,耗时长,成功率低是编译安装的最大的问题。本文的目的旨在迅速完成搭建工作,不拘泥于细节。环境是RHEL5 update 1,全部使用RPM包安装。这里顺便提一下,编译安装是需要会的,这只是在没有包管理的情况下或者是学习的过程中,有包管理器的话,还是强烈推荐使用包安装,因为一般而言,使用包安装更易于管理。 LAMP:原意为linux中apache mysql php的组合,该环境使用非常广泛。只要把握住分别安装apache/mysql/php三个软件就可以了,提示缺什么包就补什么包,还有重要的就是一个叫php-mysql的链接包,相当于一个中间件,也必须要安装。按照这样的方法安装,基本上10分钟之内可以成功搭建。 下面罗列的是需要安装的包,可能由于不同的环境,取决于在安装的时候装的包安装的不一样,会提示安装的相关性,按照提示安装缺失的包就可以了。 rpm -ivh httpd-2.2.3-11.el5.i386.rpm rpm -ivh httpd-devel-2.2.3-11.el5.i386.rpm rpm -ivh apr-devel-1.2.7-11.i386.rpm rpm -ivh apr-util-devel-1.2.7-6.i386.rpm rpm -ivh httpd-devel-2.2.3-11.el5.i386.rpm rpm -ivh mysql-5.0.22-2.1.0.1.i386.rpm rpm -ivh perl-5.8.8-10.i386.rpm rpm -ivh perl-DBI-1.52-1.fc6.i386.rpm rpm -ivh mysql-5.0.22-2.1.0.1.i386.rpm rpm -ivh php-5.1.6-15.el5.i386.rpm rpm -ivh php-mysql-5.1.6-15.el5.i386.rpm rpm -ivh php-pdo-5.1.6-15.el5.i386.rpm rpm -ivh php-mysql-5.1.6-15.el5.i386.rpm rpm -ivh mysql-5.0.22-2.1.0.1.i386.rpm rpm -ivh mysql-bench-5.0.22-2.1.0.1.i386.rpm rpm -ivh mysql-devel-5.0.22-2.1.0.1.i386.rpm rpm -ivh mysql-server-5.0.22-2.1.0.1.i386.rpm rpm -ivh perl-DBD-MySQL-3.0007-1.fc6.i386.rpm rpm -ivh mysql-server-5.0.22-2.1.0.1.i386.rpm 本文转自 justiceplus 51CTO博客,原文链接:http://blog.51cto.com/johnwang/126383,如需转载请自行联系原作者

优秀的个人博客,低调大师

Xcode4 单元测试快速入门[转]

这是一篇xcode单元测试入门的文章。有空了给各位翻出来方便大家看。 This is a post by iOS Tutorial Team member Unit testing is great because it makes your life easier. Easier to deliver high quality code, and easier to make changes without fear of breaking something! But what might not be so easy is getting started if you’re new to unit testing – and that’s what this tutorial is all about! We’ll cover how to set up Xcode to use three different unit testing frameworks: OCUnit, which is the unit testing framework built into Xcode GHUnit, which is a third party framework with some extra cool features OCMock, which helps you write mock objects to aid tricky testing scenarios We won’t cover how to actually write test cases in this tutorial, but don’t worry – I’ll be covering that in my upcoming tutorial series on Test Driven Development for iOS! This tutorial assumes you already know the basics of iOS development. If you are a complete beginner, check out some of theseBeginner iOS Tutorialsfirst. Getting Started with OCUnit OCUnit is the unit testing framework that’s built straight into Xcode, so let’s try that out first. In Xcode, go to File\New\New Project, select iOS\Application\View-based Application, and click Next. Name the projectSampleProject, and make sure to check theInclude Unit Testsoption, as shown below. Click Next, choose a folder for your project, and click Create. If you look at the generated project, you’ll see that Xcode has created two targets for you:SampleProject(the app target), andSampleProjectTests(the unit test target). The unit test target is created with a dependency on the app target, so that when you run the tests, the app target will automatically be built. Xcode also creates a single test class as an example for you, which you can find in SampleProjectTests\SampleProjectTests.m. You’ll see a single test case set up in the file that looks like this: - (void)testExample { STFail(@"Unit tests are not implemented yet in SampleProjectTests"); } Basically this is a sample test that should fail immediately when it’s run, because you haven’t written any unit tests yet! Let’s try this out and see if it indeed fails like it should. Select the iPhone Simulator from the Scheme drop down, then choose Product\Test from the Xcode menu (shortcut key ⌘U). Xcode will then build the app target, then build the unit test target. If both targets can be built it then runs the test cases on the simulator and highlights any failures in the Issue Navigator and in the source file itself, just like it does with build warnings and errors. So as you can see, setting up unit testing with OCUnit in Xcode is really easy – it’s just a matter of selecting a checkbox! We won’t get into how to use write unit tests with OCUnit in this tutorial series, since I prefer the alternative unit testing frameworks GHUnit and OCMock which we’ll cover next. However, if you decide OCUnit is right for you, check outApple’s Unit Testing Overviewfor more information on how you can write your own tests. GHUnit vs OCUnit GHUnit is a popular unit testing framework developed byGabriel Handfordas an alternative to OCUnit. With the release of Xcode 4, using OCUnit is better than it used to be, but I still prefer GHUnit because: GHUnit allows you to run all tests, a single test, or just the failed tests, while OCUnit can only run all of them. GHUnit comes with a neat test runner app, that quickly shows you a high level view of passing and failing tests, while OCUnit does not have this. GHUnit is an open source project, so you can modify the framework to better meet your needs. OCUnit does still have the advantage of being tightly integrated with Xcode, which makes the initial project setup easier, but to me the advantages of GHUnit outweigh this. If you’re interested in reading more about the differences between GHUnit and OCUnit, check out thisnice comparisonbyMark Makdad. Introducing OCMock Unit testing without OCMock. Image credit:ettina82 Before we cover how to integrate GHUnit into your Xcode project, let’s take a minute to discuss OCMock. If you have ever written automated unit tests before, you probably have encountered the problem of trying to test more than one class at a time. This is a recipe for brittle tests and spaghetti code. After a while, you get to the point that you’re ready to throw the tangled mess into the trash! Using some form of dummy objects (also known asmock objects) to reduce dependencies is a good method to solve this. Mock objects allow you to test interactions with the outside world while keeping external dependencies as low as possible. If your code has external dependencies or responsibilities (and most do), you’ll want to use these! OCMockis a framework for OS X and iOS developed by Mulle Kybernetik that follows the pattern of mock frameworks developed for other platforms. So you’ll learn how to set up Xcode to use this along with GHUnit! Installing GHUnit and OCMock: Overview These instructions will create a project structure with all files stored in the actual project directory, including the GHUnit and OCMock frameworks. These instructions also assume everything we create or download will be in the directory ~/myproj, but feel free to put them wherever you like. After each step in the process, you should do a clean, build, and run for each target to validate the configuration and dependencies. We will use the name MyProj for our project and derive several targets and file names from it. You can choose whatever name you wish, but it is best to be consistent in your naming of targets and components. There are many more options for GHUnit and OCMock, but they are outside the scope of these instructions. For more information, see the Other Links at the end of this post. Getting Started Let’s get started by creating a fresh directory and project: Create a new subdirectory myproj in your home directory Open up Xcode, and create a new View-based Application Leave the “Include Unit Tests” checkbox unchecked since we will be using GHUnit instead of OCUnit Save the project as MyProj in ~/myproj Make sure the project builds and runs in the simulator without error Integrating GHUnit OK, time to integrate GHUnit! It just takes three quick steps. 1) Add a GHUnit Test Target First, we need to add a test target to our project for GHUnit. Select the project file in the Project Navigator view, and click ‘Add Target’. Create an iOS View-based Application named ‘MyProjTests’ for the GHUnit target. As with the project creation, leave the “Include Unit Tests” checkbox unchecked. 2) Add GHUnitIOS Framework The next step is to add the GHUnitIOS framework to our project. You’ll need todownload it from githubfirst if you haven’t already. Note:Be sure you select the latest iOS version (named like ‘GHUnitIOS-####.zip’), and not the Mac OS X version (named like ‘GHUnit-####.zip’)! We want to include the full set of files in our project, so unzip it into ~/myproj/MyProj. Then select the “Build Phases” tab for the MyProjTests target, expand the “Link Binary With Libraries” section, and click the “+” button. Select “Add Other…” and select the GHUnitIOS.framework from the ~/myproj directory, as shown in the screenshot below. Now verify that the test target builds before continuing. Select the iPhone Simulator for the MyProjTests target from the Scheme drop down and click the Run button. You will only see a blank view at this point in the simulator. 3) Configure GHUnit Test Target The GHUnitIOS framework has an embedded window and app delegate, so we need to remove the ones installed by default when we created the test target. First, delete the files MyProjTestsAppDelegate.h, MyProjTestsAppDelegate.m, MainWindow.xib, MyProjTestsViewController.h, MyProjTestsViewController.m, MyProjTestsViewController.xib, and main.m from MyProjTests. Second, remove the “Main nib file base name” property from MyProjTests-Info.plist. Next,download the file GHUnitIOSTestMain.mto ~/myproj/MyProj/MyProjTests, as shown in the screenshot below. Now, add the file to the MyProjTests target, making sure to select the MyProjTests target when adding the file. Lastly, we need to update the build settings for the MyProjTests target. Select “Other Linker Flags” under MyProjTests and add the value “-ObjC -all_load”. Congrats – you’ve successfully configured GHUnit! Run the MyProjTests target in the simulator and you’ll see the GHUnit test runner: Creating a Simple Test Case Although GHUnit is integrated in your project now, you don’t have any tests to run yet! So let’s make a simple test case to try things out. Create a new Objective-C class SampleTestCase.m in the MyProjTests group, making sure it belongs to the MyProjTests target, but not to the MyProj target. Our test case class does not need a header file, but Xcode 4 does not give us the option to only create a .m file, so delete the SampleTestCase.h file and replace the entire contents of the SampleTestCase.m with the following code: #import <GHUnitIOS/GHUnit.h> @interface SampleLibTest : GHTestCase { } @end @implementation SampleLibTest - (void)testSimplePass { // Another test } - (void)testSimpleFail { GHAssertTrue(NO, nil); } @end Then run the MyProjTests target in the simulator and you should see this: You can tap the Run button in the upper right corner to run the tests – one should fail and one should succeed. Creating a test case in GHUnit is straightforward, a test case is simply a method that follows these simple rules: The class inherits from GHTestCase, the method return type is void, the method name begins with ‘test’, and the method takes no arguments. Obviously, to be a useful test case, it needs to do something (unlike the ‘testSimplePass’ method above.) Each test case should have a single purpose, and often after all the setup is done it only checks a single value. It can be as simple as creating an instance of the class to be tested, calling a method on that class, and checking that the value returned matches your expectations. Test cases specify what they expect by asserting certain conditions, and in GHUnit, there is a set of macros that cover a variety of casesin the file GHTestMacros.h. There are afew simple exampleson the GHUnit website. w00t! At this point you now have a working project using GHUnit on which you can build. Read on to learn how to add in OCMock support as well! Addding OCMock Now that we have GHUnit set up and running, we want to add support for OCMock. The framework available on the website does not work with iOS projects. We need the static library from thethe example iPhone projectand the header files from the framework. Before we get started, go ahead and create a separate directory in our project to hold the library and header files. From the Project Navigator in Xcode, right click on MyProj and select “Add Files to ‘MyProj’”: Select the directory ~/myproj/MyProj, and click the “New Folder” button. Add a folder named “Libraries” and click the “Create” button. Once the folder is created, click ‘Add’ to add it to the target. Now that we have a folder ready to add OCMock into, let’s get started! Again, adding OCMock into your project is just three steps. 1) Install latest OCMock iOS library First download the filelibOCMock.ato the ~/myproj/Libraries directory. Then right click on ‘Libraries’ folder in the Project Navigator, and add the libOCMock.a file to the MyProjTests target. 2) Extract header files from OCMock framework Download the latest ocmock dmg file fromdownload directoryto the ~/myproj directory and open it in finder. It should mount the image “OCMock #.##” in finder. Select the directory ‘Release/Library/Headers/OCMock’ directory and add it to our project ‘Libraries’ folder (for the MyProjTests target). The end result in the Project Navigator should look like this: 3) Update build settings for MyProjTests The following linker settings depend on the fact that the above step created a physical directory ‘OCMock’ under our directory ‘Libraries’. In the “Build Settings” for the MyProjTests target, make sure the “Library Search Paths” contain the “$(SRCROOT)/Libraries” directory like this: Next, we need to add “$(SRCROOT)/Libraries” to the “Header Search Paths” item. Make sure you check the ‘Recursive’ checkbox as well: Simple Test Case with OCMock Now we need to add some test cases that use OCMock to our SampleTestCase. Update SampleTestCase.m to look like this: #import <GHUnitIOS/GHUnit.h> #import <OCMock/OCMock.h> @interface SampleLibTest : GHTestCase { } @end @implementation SampleLibTest - (void)testSimplePass { // Another test } - (void)testSimpleFail { GHAssertTrue(NO, nil); } // simple test to ensure building, linking, // and running test case works in the project - (void)testOCMockPass { id mock = [OCMockObject mockForClass:NSString.class]; [[[mock stub] andReturn:@"mocktest"] lowercaseString]; NSString*returnValue = [mock lowercaseString]; GHAssertEqualObjects(@"mocktest", returnValue, @"Should have returned the expected string."); } - (void)testOCMockFail { id mock = [OCMockObject mockForClass:NSString.class]; [[[mock stub] andReturn:@"mocktest"] lowercaseString]; NSString*returnValue = [mock lowercaseString]; GHAssertEqualObjects(@"thisIsTheWrongValueToCheck", returnValue, @"Should have returned the expected string."); } @end And finally, run the MyProjTests target in the simulator and it should look like this: The tests we added that use OCMock merely demonstrate we have the project configured correctly. They do not show the usefulness of mock objects or the OCMock framework. Mock objects are useful in testing that a class interacts with other objects properly, without the need to configure a large object hierarchy, and in some cases before a class is even implemented. Where To Go From Here? Here is thesample projectwith all of the code from the above tutorial. Congratulations, now you know how to integrate OCUnit, GHUnit, and OCMock into your Xcode project! However, this tutorial did not touch on how to make good use of unit tests in your iOS project, but I will soon be releasing a tutorial series on Test Driven Development for iOS, so stay tuned! In the meantime, if you would like more information about GHUnit or OCMock, one of these links might help. 欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 572064792 | Nodejs:329118122 做人要厚道,转载请注明出处! 本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sunshine-anycall/archive/2011/11/30/2268854.html ,如需转载请自行联系原作者

优秀的个人博客,低调大师

iOS:融云即时通讯快速集成

一、介绍 即时通讯在众多社交软件、生活软件以及教育软件中已经是必备的功能了,在当前国内,即时通讯SDK做的比较不错的有那么几家,例如环信SDK、融云SDK...,这两家做的都很不错,各有千秋吧,要是真让说出个不同,就我个人感觉融云的集成要更简单一些,就那么几步,有点开发基础都会,我之前在项目中集成过环信,解决了不少的坑才集成好。他们共同的特点就是,都只负责进行聊天,不管理好友之间的关系和用户的信息,它们都是在代理方法中设置用户的信息,包括姓名、昵称、头像等,环信中是通过IMessageModel模型直接设置,融云则是通过将RCUserInfo模型作为block的参数进行回调设置。 如果需要集成环信,可以看看我的集成过程:http://www.cnblogs.com/XYQ-208910/p/5396635.html 二、准备 (1)注册融云开发者账号:https://developer.rongcloud.cn/signup (2)登录账号,在控制台创建应用获取AppKey和AppScrete (3)找到调试API接口,手动获取token(这个融云最终要求是开发者从自己的服务器获取),此处只是在为开发环境测试所用 (4)在plist设置iOS9需要的https网络请求字段NAAppTransportSecurity (5)如果对界面没有更高的定制要求,融云本身提供的所有聊天等界面已经足够使用,此时集成IMKit框架使用即可,推荐使用CocoaPods自动集成 三、集成 (1)生成Podfile文件,选择IM框架 platform :ios, '8.0' target 'RongCloudKit' do pod 'RongCloudIM/IMLib', '2.8.0' //需要自己去定制UI界面 pod 'RongCloudIM/IMKit', '2.8.0' //融云提供完善的UI界面 end (2)安装后导入头文件即可使用 四、使用(RCIM是一个单例类,几乎很多重要的操作都是由这个类来完成的) (1)注册融云APPKey //注册融云APPKEY [[RCIM sharedRCIM] initWithAppKey:APPKEY]; (2)登录融云服务器 //使用手动生成的token连接融云服务器进行登录 [[RCIM sharedRCIM] connectWithToken:TOKEN success:^(NSString *userId) { NSLog(@"登陆成功。当前登录的用户ID:%@", userId); } error:^(RCConnectErrorCode status) { NSLog(@"登陆的错误码为:%ld", status); } tokenIncorrect:^{ //token过期或者不正确。 //如果设置了token有效期并且token过期,请重新请求您的服务器获取新的token //如果没有设置token有效期却提示token错误,请检查您客户端和服务器的appkey是否匹配,还有检查您获取token的流程。 NSLog(@"token错误"); }]; (3)显示聊天界面代码如下(此处我继承了原生会话类RCConversationViewController) // RongCloudConversationViewController.h // RongCloudKit // // Created by 夏远全 on 16/12/17. // Copyright © 2016年 广州市东德网络科技有限公司. All rights reserved. // #import <RongIMKit/RongIMKit.h> @interface SystemConversationViewController : RCConversationViewController @end // RongCloudConversationViewController.m // RongCloudKit // // Created by 夏远全 on 16/12/17. // Copyright © 2016年 广州市东德网络科技有限公司. All rights reserved. // #import "SystemConversationViewController.h" @interface SystemConversationViewController ()<RCIMUserInfoDataSource> @end @implementation SystemConversationViewController -(instancetype)init{ self = [super init]; //设置会话的类型,如单聊、讨论组、群聊、聊天室、客服、公众服务会话等 self.conversationType = ConversationType_PRIVATE; //设置会话的目标会话ID。(单聊、客服、公众服务会话为对方的ID,讨论组、群聊、聊天室为会话的ID) self.targetId = OTHERID; //设置聊天会话界面要显示的标题 self.title = OTHERID; return self; } -(void)viewDidLoad{ [super viewDidLoad]; //用户信息提供者 [RCIM sharedRCIM].userInfoDataSource = self; } #pragma mark - <RCIMUserInfoDataSource> /*! 获取用户信息 @param userId 用户ID @param completion 获取用户信息完成之后需要执行的Block [userInfo:该用户ID对应的用户信息] @discussion SDK通过此方法获取用户信息并显示,请在completion中返回该用户ID对应的用户信息。 在您设置了用户信息提供者之后,SDK在需要显示用户信息的时候,会调用此方法,向您请求用户信息用于显示。 */ -(void)getUserInfoWithUserId:(NSString *)userId completion:(void (^)(RCUserInfo *))completion { //设置用户信息 NSString *avatarURL = @"http://xxxxxx.com/static/avatar/137180371639017.jpeg"; RCUserInfo *userInfo = [[RCUserInfo alloc] initWithUserId:userId name:userId portrait:avatarURL]; //block回调设置用户信息 completion(userInfo); } @end //聊天界面 -(void)conversationStart{ //新建一个聊天会话View Controller对象、显示聊天会话界面 SystemConversationViewController *chat = [[SystemConversationViewController alloc]init]; [self.navigationController pushViewController:chat animated:YES]; } (4)显示会话列表界面代码如下(此处我继承了原生会话列表类RCConversationListViewController) // ConversationListViewController.h // RongCloudKit // // Created by 夏远全 on 16/12/17. // Copyright © 2016年 广州市东德网络科技有限公司. All rights reserved. // #import <RongIMKit/RongIMKit.h> @interface SystemConversationListViewController : RCConversationListViewController @end // ConversationListViewController.m // RongCloudKit // // Created by 夏远全 on 16/12/17. // Copyright © 2016年 广州市东德网络科技有限公司. All rights reserved. // #import "SystemConversationListViewController.h" #import "SystemConversationViewController.h" @interface SystemConversationListViewController ()<RCIMUserInfoDataSource> @end @implementation SystemConversationListViewController - (void)viewDidLoad { //重写显示相关的接口,必须先调用super,否则会屏蔽SDK默认的处理 [super viewDidLoad]; self.conversationListTableView.tableFooterView = [[UIView alloc] init]; //设置需要显示哪些类型的会话 [self setDisplayConversationTypes:@[@(ConversationType_PRIVATE), @(ConversationType_DISCUSSION), @(ConversationType_CHATROOM), @(ConversationType_GROUP), @(ConversationType_APPSERVICE), @(ConversationType_SYSTEM)]]; //设置需要将哪些类型的会话在会话列表中聚合显示 [self setCollectionConversationType:@[@(ConversationType_DISCUSSION), @(ConversationType_GROUP)]]; //用户信息提供者 [RCIM sharedRCIM].userInfoDataSource = self; } //重写RCConversationListViewController的onSelectedTableRow事件 - (void)onSelectedTableRow:(RCConversationModelType)conversationModelType conversationModel:(RCConversationModel *)model atIndexPath:(NSIndexPath *)indexPath { SystemConversationViewController *conversationVC = [[SystemConversationViewController alloc]init]; conversationVC.conversationType = model.conversationType; conversationVC.targetId = model.targetId; conversationVC.title = model.targetId; [self.navigationController pushViewController:conversationVC animated:YES]; } #pragma mark - <RCIMUserInfoDataSource> /*! 获取用户信息 @param userId 用户ID @param completion 获取用户信息完成之后需要执行的Block [userInfo:该用户ID对应的用户信息] @discussion SDK通过此方法获取用户信息并显示,请在completion中返回该用户ID对应的用户信息。 在您设置了用户信息提供者之后,SDK在需要显示用户信息的时候,会调用此方法,向您请求用户信息用于显示。 */ -(void)getUserInfoWithUserId:(NSString *)userId completion:(void (^)(RCUserInfo *))completion { //设置用户信息 NSString *avatarURL = @"http://xxxxxx.com/static/avatar/137180371639017.jpeg"; RCUserInfo *userInfo = [[RCUserInfo alloc] initWithUserId:userId name:userId portrait:avatarURL]; //block回调设置用户信息 completion(userInfo); } @end //会话列表 -(void)chatViewList{ //新建一个会话列表界面类,显示所有的会话联系人 SystemConversationListViewController *chatList = [[SystemConversationListViewController alloc] init]; [self.navigationController pushViewController:chatList animated:YES]; } 五、演示截图 六、提示一下 融云的开发文档些的相当详细,我这儿写一下纯属闲来无事,自娱自乐,有这方面需要的还是去看官方的文档吧,那文档的详细,厉害了我的哥~~~ 欢迎关注我的博客:http://www.cnblogs.com/XYQ-208910和github:https://github.com/xiayuanquan 程序猿神奇的手,每时每刻,这双手都在改变着世界的交互方式! 本文转自当天真遇到现实博客园博客,原文链接:http://www.cnblogs.com/XYQ-208910/p/6195117.html ,如需转载请自行联系原作者

优秀的个人博客,低调大师

攻略:如何快速赚取积分,Get云栖大会资料

2017杭州云栖大会已于10月11日-14日在云栖小镇完美召开,作为全球最具影响力的科技展会之一,本届有140多场技术主题论坛,共计800多个主题分享,涵盖人工智能、金融科技、量子计算、生命科学、IoT、政务、多媒体、VR等20多个前沿科技领域。多位全球顶级学术专家、以及MySQL & MariaDB创始人、PostgreSQL联合创始人、Redis创始人等大咖都献出了精彩的分享。相关文章和其他回顾,请点击云栖大会公众号( https://yq.aliyun.com/teams/142)。期间,云栖社区也同步上线了下载频道( https://yq.aliyun.com/download),为大家带来更多技术实战干货、技术趋势等资源。 2016杭州云栖大会资料分享获得大家的热烈欢迎。为此,组委会特别决定今年大会资料将以部分免费+通

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码