Centos创建以太坊私有链

首先第一步当然是更新,然后使用yum命令安装golang语言

yum –y update
yum install golang
git clone https://github.com/ethereum/go-ethereum.git  
cd go-ethereum  
make all
cd go-ethereum
make all

这里出现了编译错误,提示go的版本1.8.3,编译需要最少1.9。前往https://www.golangtc.com/download goland下载go1.10.1.linux-amd64.tar.gz,再次安装前需要卸载原有的golang,yum –y remove golang

tar -C /usr/local -xzf go1.10.1.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin

重复make,在go-ethereum/build/bin使用ll命令,会罗列文件夹内的在go-ethereum/build/bin目录下创建init.json的文本文件,内容如下:

{
  "config": {
        "chainId": 14,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
  "alloc"      : {},
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x05000",
  "extraData"  : "",
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00"
}

保存并退出文件,同目录下执行./geth –datadir “/app/chain” init init.json完成创世区块的创建,同目录下执行./geth –rpc –rpccorsdomain “*” –datadir “/app/chain” –port “30303” –rpcapi “db,eth,net,web3” –networkid 100000 console每次启动多使用此命令。

这时进入geth命令,可以创建账户转账查余额等操作

//查看coinbase账户余额
baseAccount = eth.accounts[0]
num = eth.getBalance(baseAccount)
//换算单位为eth
web3.fromWei(num)
//新建一个账户
personal.newAccount("account")
//查看新建账户的余额
account1 = eth.accounts[1]
eth.getBalance(account1)
//从coinbase账户转给account1账户1eth
personal.unlockAccount(baseAccount ,"coinbase")
eth.sendTransaction({from:baseAccount,to:account1,value:web3.toWei(1,"ether")})
//观察挖矿shell的输出,等待交易打包完成后,查询account1的账户余额
eth.getBalance(account1)

此时账户余额为零,因为我们的交易还未成功写进区块,写进区块的方式是挖矿,我们再次开启挖矿,挖矿成功后,并停止挖矿,再次查看余额。到这里就完成了私有链创建,账户创建,挖矿,转账等操作。私有链用于调试,在私有链上挖矿是没有意义的。

 

参考文献:

https://www.cnblogs.com/beyang/p/8469227.html

https://blog.csdn.net/wo541075754/article/details/78926177

https://blog.csdn.net/koastal/article/details/78737543

 

 

 

低配电脑挖矿门罗币MONERO Mining Machine

建站的时候租用了一台服务器,centos的操作系统。上面只放了两个网站, CPU使用率基本为零,偶尔操作的时候也只有40%,闲置是极大的浪费。资料说门罗币(monero)可以用cpu挖,那我也挖门罗币吧。

首先要有钱包地址,本地钱包或者在线钱包,我选择了后者,所以前者就不多说了。在线平台有很多,网友说这家还不错https://mymonero.com/https://hitbtc.com/,注册账号之后在account里找到钱包地址,下面会用到。

接下来要在服务器上安装挖矿工具,以下命令复制粘贴。

yum install centos-release-scl cmake3 hwloc-devel libmicrohttpd-devel openssl-devel
yum install devtoolset-4-gcc*
scl enable devtoolset-4 bash
git clone https://github.com/fireice-uk/xmr-stak-cpu xmr-stak
cd xmr-stak
cmake3 .
make install

安装成功之后输入/usr/local/bin/cmake –version视版本略有不同,然后修改config.txt文件,在文件中的109行-111行填入矿池钱包地址等信息,端口3333难度较低笔记本也可以算,5555,7777和9999要求都较高,文件中有照着来就可以,基本如下。将26行左右cpu_threads_conf及随后中括号前的星号删除,同样文件中有照着来就可以。

"pool_address" : "gulf.moneroocean.stream:10016", "wallet_address" : "43VPcU1khYu7S3H91b4txQfrs5wsuwAShVUXFnZMbXtLfQFomQhxb7pjXqrT3anyZ22j7DEE74GkbVcQFyH2nNiC3d2Vne3", "pool_password" : "x",

输入接下来的命令就可以挖矿了。

cd /root/xmr-stak/bin/
./xmr-stak-cpu

但是有时会遇到MEMORY ALLOC FAILED: mmap failed的问题,停止运行后进入/etc/security/limits.conf,在文末添加

* soft memlock 262144
* hard memlock 262144

保存并退出,输入下面的命令后重启。一般这样问题就解决了。

sysctl -w vm.nr_hugepages=128

更新11042018:xmr-stak工具已经升级了可以在安装的时候运行以下命令。

yum -y install epel-release
yum -y install centos-release-scl cmake3 hwloc-devel libmicrohttpd-devel openssl-devel git screen nano make htop
yum -y install devtoolset-4-gcc*
scl enable devtoolset-4 bash
git clone https://github.com/fireice-uk/xmr-stak.git
cd xmr-stak/
cmake3 . -DCUDA_ENABLE=OFF -DOpenCL_ENABLE=OFF
make install
cd bin/
./xmr-stak

更新18042018:门罗难度已经太高了,提交的计算结果一般都会被矿池拒绝,转挖永旺币AEON,钱包地址记得换成自己的。

"pool_address" : "huadong1-aeon.ppxxmr.com:1333", 
"wallet_address" : "WmscEEuYBKQ5Cb3PDACu4QNDqisRwLsErUjhUKYcCn1L8ZCbYVFnPxVhFaaEttMUt9c61Em6dP1WeHkyDtyRgWf11Q6LU4HWM", 
"pool_password" : "x",

这里附上一个可能出现的问题及解决方法的链接。

https://www.ezloo.com/2018/01/monero_xmr_stak.html

参考文献:

https://maijiaoben.com/centos-monero.html
https://qing.su/article/129.html
http://www.hostloc.com/thread-415078-1-1.html

 

The followings are just for practicing English.

An ECS with centos installed was rent while creating websites. Only two websites are running on it. CPU usage usually is 0%, and sometimes 40% at most. Leaving it unused is a waste. It is sad that CPU calculation can obtain Monero, so let’s do it.

The first step is to get a wallet address. There are two methods to get it, local registration and online registration. The later one is chosen, so the previous one is neglected here. There are many platforms, such as https://mymonero.com/, and https://hitbtc.com/. After registration, you need to copy the address, which will be used later.

Copy and paste the commands to install mining tool on the server:

yum install centos-release-scl cmake3 hwloc-devel libmicrohttpd-devel openssl-devel
yum install devtoolset-4-gcc*
scl enable devtoolset-4 bash
git clone https://github.com/fireice-uk/xmr-stak-cpu xmr-stak
cd xmr-stak
cmake3 .
make install

After installation, check the version by input: /usr/local/bin/cmake –version. The commands may vary depending on the versions. Then, modify “config.txt”, input your pool address, your wallet address, and your password ID based on the examples at line 109-111, and delete the “*” at line 25-29 approximately. Port 3333 is the easiest for low & mid-range CPUs.

After these, you can start mining by input the following commands:

cd /root/xmr-stak/bin/
./xmr-stak-cpu

However, I met the problem of MEMORY ALLOC FAILED: mmap failed. The solution is to stop mining and enter /etc/security/limits.conf, add the following lines in the end of the file:

* soft memlock 262144
* hard memlock 262144

Save and exit the file and input “sysctl -w vm.nr_hugepages=128”. Then, reboot.