Centos6.5里安装Erlang 并安装riak
一.Erlang安装:
1 首先进入www.erlang.org 下载页面,下载otp_src_17.5.tar.gz. IT网,http://www.it.net.cn
2 解压缩:tar -xzvf otp_src_17.5.tar.gz Linux学习,http:// linux.it.net.cn
3 进入解压缩后的文件夹:cd otp_src_17.5.tar.gz
4 如果直接运行./configure,会提示没有curses库,所以首先还得安装这个库:yum install ncurses-devel,运行此命令需要具备root权限。
5 运行./congigure命令。
6 运行make命令。
7 运行make install命令。
安装成功后,在命令行输入erl,则erlang shell便会运行起来。至此,安装完全成功。
yum install gcc
riak安装:
http://docs.basho.com/riak/1.3.2/tutorials/installation/Installing-on-RHEL-and-CentOS/
备注:(不知道有什么卵用)
设置ulimit: echo "session required pam_limits.so" >> /etc/pam.d/common-session echo "ulimit -SHn 51200" >> /etc/profile source /etc/profile ulimit -n
修改成局域网可以访问:
/etc/riak/app.config
如下
 {http, [ {"192.168.1.117", 8098 } ]},
/etc/rc.d/init.d/riak restart
vim /etc/riak/vm.args
vim /etc/riak/app.config
sudo yum install http://yum.basho.com/gpg/basho-release-6-1.noarch.rpm
sudo yum install riak
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8098 -j ACCEPT
 vim /etc/sysconfig/iptables
/etc/init.d/iptables restart
/etc/init.d/iptables status


其他参考:
http://docs.basho.com/riak/2.0.0/ops/building/installing/rhel-centos/
https://github.com/basho/riak
http://www.oschina.net/p/riak/
http://www.ibm.com/developerworks/cn/opensource/os-riak1/
http://www.ibm.com/developerworks/cn/opensource/os-riak2/
http://blog.csdn.net/freewebsys/article/details/12609995
http://www.xuebuyuan.com/1252471.html
http://docs.basho.com/riak/1.3.2/tutorials/installation/Installing-on-RHEL-and-CentOS/
http://www.lupaworld.com/thread-61933-1-1.html
http://blog.csdn.net/freewebsys/article/details/12617379
客户端连接测试:(https://github.com/super-d2/riak_demo)
 {pb, [ { } ]}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion></modelVersion>
    <groupId>riak_demo</groupId>
    <artifactId>riak_demo</artifactId>
    <version>1.0</version>
    <dependencies>
        <dependency>
            <groupId>com.basho.riak</groupId>
            <artifactId>riak-client</artifactId>
            <version></version>
        </dependency>
        <dependency>
            <groupId>com.basho.riak.protobuf</groupId>
            <artifactId>riak-pb</artifactId>
            <version></version>
        </dependency>
    </dependencies>
</project>
UserInfo.java
package com.demo;
/**
 * 用户信息.
 */
public class UserInfo {
    private String uid;
    private String name;
    private String city;
    private String nickName;
    public String getUid() {
        return uid;
    }
    public void setUid(String uid) {
        this.uid = uid;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getNickName() {
        return nickName;
    }
    public void setNickName(String nickName) {
        this.nickName = nickName;
    }
    @Override
    public String toString() {
        return "UserInfo [uid=" + uid + ", name=" + name + ", city=" + city
                + ", nickName=" + nickName + "]";
    }
}
ClientTest.java
package com.demo;
import java.io.IOException;
import com.basho.riak.client.IRiakClient;
import com.basho.riak.client.RiakException;
import com.basho.riak.client.RiakFactory;
import com.basho.riak.client.RiakRetryFailedException;
import com.basho.riak.client.bucket.Bucket;
public class ClientTest {
    public static void main(String[] args) throws IOException {
        IRiakClient client = null;
        try {// 使用pbc方式连接,而不是http,在/etc/riak/app.config
            client = RiakFactory.pbcClient();
        } catch (RiakException e) {
            e.printStackTrace();
        }
        // 显示.
        System.out.println(client);
        Bucket myBucket = null;
        String bucketName = "userInfo";
        try {
            myBucket = client.fetchBucket(bucketName).execute();
            if (myBucket == null) {
                myBucket = client.createBucket(bucketName).execute();
            }
        } catch (RiakRetryFailedException e) {
            e.printStackTrace();
        }
        // ################保存数据 .
        UserInfo info = new UserInfo();
        info.setUid(");
        info.setName("张三");
        info.setCity("北京");
        try {
            myBucket.store(info.getUid(), info).execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // ################查询数据.
        UserInfo fetchedUserInfo = null;
        try {
            fetchedUserInfo = myBucket.fetch(", UserInfo.class).execute();
            System.out.println(fetchedUserInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        // ################修改数据.
        try {
            fetchedUserInfo = myBucket.fetch(", UserInfo.class).execute();
            fetchedUserInfo.setName("李四");
            fetchedUserInfo.setNickName("老李");
            myBucket.store(info.getUid(), info).execute();
            // 保存 新数据
            fetchedUserInfo = myBucket.fetch(", UserInfo.class).execute();
            System.out.println("新数据:" + fetchedUserInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        // ################删除数据.
        try {
            myBucket.delete(").execute();
            fetchedUserInfo = myBucket.fetch(", UserInfo.class).execute();
            System.out.println("删除收数据." + fetchedUserInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 关闭。
        client.shutdown();
    }
}
运行:

代码分析
在Riak当中,可以简单的把Bucket理解成一个表。
首先要创建一个这样的Bucket,然后把数据按照key放进去。
数据类型可以是字符串,基本类型,或是对象(如UserInfo)。
每次操作的时候都是通过执行Bucket的方法执行达到CRUD的操作。
StoreObject<IRiakObject> store(String key, byte[] value); StoreObject<IRiakObject> store(String key, String value); <T> StoreObject<T> store(T o); <T> StoreObject<T> store(String key, T o); FetchObject<IRiakObject> fetch(String key); <T> FetchObject<T> fetch(String key, Class<T> type); <T> FetchObject<T> fetch(T o); MultiFetchObject<IRiakObject> multiFetch(String[] keys); <T> MultiFetchObject<T> multiFetch(List<String> keys, Class<T> type); <T> MultiFetchObject<T> multiFetch(List<T> o); CounterObject counter(String counter); <T> DeleteObject delete(T o); DeleteObject delete(String key); StreamingOperation<String> keys() throws RiakException; <T> FetchIndex<T> fetchIndex(RiakIndex<T> index);
总结
java通过使用Protocol Buffers方式调用Riak服务,直接操作对象进行CRUD。
有了这些,可以做一个简单的评论系统了。评论系统上面不需要事物,并且数量会随着业务增长,使用Rick可以平稳的进行扩展。
这个只是简单的,对Rick服务进行CRUD。最没有用到其他功能,同时没有关于key的设计。
Rick的其他功能,以后继续研究。
相关分布式理论:
http://freestorm.org/2015/04/25/Riak%E7%9A%84%E5%88%86%E5%B8%83%E5%BC%8F%E6%95%B0%E6%8D%AE%E5%BA%93%E6%A8%A1%E5%9E%8B.html
http://segmentfault.com/a/1190000002802797
java客户端调用实例:
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion></modelVersion>
    <groupId>riak_demo</groupId>
    <artifactId>riak_demo</artifactId>
    <version>1.0</version>
    <dependencies>
        <dependency>
            <groupId>com.basho.riak</groupId>
            <artifactId>riak-client</artifactId>
            <version></version>
        </dependency>
        <dependency>
            <groupId>com.basho.riak.protobuf</groupId>
            <artifactId>riak-pb</artifactId>
            <version></version>
        </dependency>
    </dependencies>
</project>
UserInfo:
package com.demo;
/**
 * 用户信息.
 */
public class UserInfo {
    private String uid;
    private String name;
    private String city;
    private String nickName;
    public String getUid() {
        return uid;
    }
    public void setUid(String uid) {
        this.uid = uid;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public String getNickName() {
        return nickName;
    }
    public void setNickName(String nickName) {
        this.nickName = nickName;
    }
    @Override
    public String toString() {
        return "UserInfo [uid=" + uid + ", name=" + name + ", city=" + city
                + ", nickName=" + nickName + "]";
    }
}
ClientTest:
package com.demo;
import java.io.IOException;
import com.basho.riak.client.IRiakClient;
import com.basho.riak.client.RiakException;
import com.basho.riak.client.RiakFactory;
import com.basho.riak.client.RiakRetryFailedException;
import com.basho.riak.client.bucket.Bucket;
public class ClientTest {
    public static void main(String[] args) throws IOException {
        IRiakClient client = null;
        try {// 使用pbc方式连接,而不是http,在/etc/riak/app.config
            client = RiakFactory.pbcClient();
        } catch (RiakException e) {
            e.printStackTrace();
        }
        // 显示.
        System.out.println(client);
        Bucket myBucket = null;
        String bucketName = "userInfo";
        try {
            myBucket = client.fetchBucket(bucketName).execute();
            if (myBucket == null) {
                myBucket = client.createBucket(bucketName).execute();
            }
        } catch (RiakRetryFailedException e) {
            e.printStackTrace();
        }
        // ################保存数据 .
        UserInfo info = new UserInfo();
        info.setUid(");
        info.setName("张三");
        info.setCity("北京");
        try {
            myBucket.store(info.getUid(), info).execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // ################查询数据.
        UserInfo fetchedUserInfo = null;
        try {
            fetchedUserInfo = myBucket.fetch(", UserInfo.class).execute();
            System.out.println(fetchedUserInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        // ################修改数据.
        try {
            fetchedUserInfo = myBucket.fetch(", UserInfo.class).execute();
            fetchedUserInfo.setName("李四");
            fetchedUserInfo.setNickName("老李");
            myBucket.store(info.getUid(), info).execute();
            // 保存 新数据
            fetchedUserInfo = myBucket.fetch(", UserInfo.class).execute();
            System.out.println("新数据:" + fetchedUserInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        // ################删除数据.
        try {
            myBucket.delete(").execute();
            fetchedUserInfo = myBucket.fetch(", UserInfo.class).execute();
            System.out.println("删除收数据." + fetchedUserInfo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 关闭。
        client.shutdown();
    }
}
Centos6.5里安装Erlang 并安装riak的更多相关文章
- centos7 安装erlang rabbitMQ
		
环境: 虚拟机 centos7 minimal 一.安装Erlang 1.安装依赖 yum install build-essential openssl openssl-devel unixODBC ...
 - 64位CentOS6.2安装erlang及rabbitmqServer
		
CentOS 6.2 64bit 安装erlang及RabbitMQ Server 1.操作系统环境(CentOS 6.2 64bit) [root@HAproxy ~]# cat /etc/issu ...
 - Centos6.4安装erlang并配置mysql数据库
		
在安装时,一定要使用Centos6.4光盘为yum源,否则可能使用了版本有问题的openssl 1.首先要先安装GCC GCC-C++ Openssl等依赖模块: yum -y install mak ...
 - ubuntu安装erlang
		
照着园子里一篇博文安装erlang,各种错调不出来.最后发现官网有解决方案: https://www.erlang-solutions.com/downloads/download-erlang-ot ...
 - CentOS6 图形界面(gnome)安装(转)
		
CentOS6相对于CentOS5的安装有了不少的进步,有不少默认的选项可以选择,如: Desktop :基本的桌面系统,包括常用的桌面软件,如文档查看工具. Minimal Desktop :基本的 ...
 - Rabbit MQ 学习 (一)Window安装Erlang环境
		
之前也没有用过Rabbit MQ ,最近正在学习中,记性不好,特意记一下. 百度一下 先得 安装 Erlang 并且 设置环境变量. 在Erlang 官网去下载,那个慢呀... 还好CSDN 里有人提 ...
 - 手把手教小白安装Erlang
		
Erlang(['ə:læŋ])是一种通用的面向并发的编程语言,它有瑞典电信设备制造商爱立信所辖的CS-Lab开发,目的是创造一种可以应对大规模并发活动的编程语言和运行环境. Erlang官网:htt ...
 - CentOS6 图形界面(gnome)安装
		
CentOS6相对于CentOS5的安装有了不少的进步,有不少默认的选项可以选择,如: Desktop :基本的桌面系统,包括常用的桌面软件,如文档查看工具. Minimal Desktop :基本的 ...
 - ubtuntu 下安装Erlang R17
		
在Ubuntu 下 Erlang R17B 的安装的过程记录: 1 :如果你主机上没有安装jdk,那需先安装,安装过程如下: # sudo apt-get update (更新已安装的包) ...
 
随机推荐
- Python PEP8规范
			
转载自:http://blog.csdn.net/kellyseeme/article/details/50644893 风格指南:http://zh-google-styleguide.readth ...
 - java中类名,方法,变量,包名等大小写命名规范
			
类名:首字母大写,其他单词中首字母大写,其他小写方法名:首字母小写,其他单词中首字母大写,其他小写变量:与方法名规则同包名:全部小写接口interface:I开头
 - nginx 免安装包
			
在一个环境下编译安装好nginx,然后可以拷贝到其他环境使用.同时避免直接安装造成的环境冲突. 首先下载好nginx和相关插件.然后编译安装到沙盒里面.demo如下: cd到nginx目录 ./con ...
 - 【System】shell 实现 bat 的pause功能
			
read -rsp $'Press enter to continue...\n' 参考资料: http://stackoverflow.com/questions/92802/what-is-the ...
 - Valid Number
			
Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => ...
 - IO复用与select函数
			
socket select函数的详细讲解 select函数详细用法解析 http://blog.chinaunix.net/uid-21411227-id-1826874.html linu ...
 - 使用Grub Rescue恢复Ubuntu引导
			
装了Ubuntu和Window双系统的电脑,通常会使用Ubuntu的Grub2进行引导. Grub2会在MBR写入引导记录,并将引导文件放在/boot/grub,破坏任意一项都会导致系统无法正常启动. ...
 - mysql备份与还原
			
一.直接拷贝数据库文件 直接拷贝数据库文件一般是使用文件系统备份工具cp,适合小型数据库,是最可靠的. 当你拷贝数据库文件时,必须保证表没有正在使用.如果服务器在你拷贝一个表的时候改变这个表,拷贝就失 ...
 - nyoj_299_Matrix Power Series_矩阵快速幂
			
Matrix Power Series 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 Given a n × n matrix A and a positive i ...
 - FindinFiles - Windows文件内查找插件
			
FindInFiles for Windows 今天分享一个不错的插件工具:FindInFiles.如其名,其功能和Visual Studio的Ctrl+H快捷键类似,方便Windows使用者在资源管 ...