Mongdb 설치 ubuntu 18

시스템 2018. 11. 30. 17:02

요즘 몇일째 삽질의 연속이다.

해결도 잘되고  진도는 나가긴하는데 ,,

 처음 접하니 다 까다롭구나.

 

시스템해킹 보다 개발이 손놓은지 꽤 되어서 더 힘든거 같다.

시스템해킹은 강의 할때 그래도 나름 감각은 있었는데,,

 

MongDB 설치

apt-get install mongodb-server mongodb-clients 

 

설정파일 변경

 vi /etc/mongodb.conf

포트변경

bind_ip = 0.0.0.0  <---127.0.0.1   변경해야 외부 접속 가능

port = 31337

 

주석풀기

auth = true

설치 확인

 mongod --version


db version v3.6.3
git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
OpenSSL version: OpenSSL 1.1.0g  2 Nov 2017
allocator: tcmalloc
modules: none
build environment:
    distarch: x86_64    target_arch: x86_64

 

 

구동확인 되었으면 다시 실행하지 말것 그래도 안되면 reboot

구동
systemctl start mongodb


상태 확인
systemctl status mongodb


정지
systemctl stop mongodb


부팅 시 실행 하고
systemctl enable mongodb

재부팅하면 서비스 구동

 

다른 창에서 포트 확인

root@tkpark-VirtualBox:~/node-server# netstat -an | more
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:31337         0.0.0.0:*               LISTEN
tcp        0      0 192.168.0.118:22        192.168.0.188:65507     ESTABLISHED
tcp        0     64 192.168.0.118:22        192.168.0.188:65516     ESTABLISHED
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 ::1:631                 :::*                    LISTEN

 

MongDB 31337실행

root@tkpark-VirtualBox:/etc# mongo --port 31337
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:31337/
MongoDB server version: 3.6.3
>

관리자 계정 & 사용자 계정 생성

use admin
db.createUser(
     {
         user: "parktk",
         pwd: "1234",
         roles: [ { role: "userAdminAnyDatabase", db : "admin"} ]
     }
)


>db.auth("parktk", "1234" )


use test
db.createUser(
      {
         user : "test",
         pwd : "12345",
         roles : [
                      {  role : "dbAdmin", db : "test"   },
                      {  role : "readWrite", db : "test" }
                    ]
        }

계정생성 확인

1참   0거짓

1이면 계정이 잘 생성 되었음

> db.auth("test", "12345" )
1

 


> db.auth("test", "12347" )
\Error: Authentication failed.
0
>
 

 

 

 

nodejs

Mongdb 설치

npm install mongodb 

mongoose 설치

npm install mongoose

 

원래 인생은 한번만에 되면 재미 없는법 ㅋㅋ

오류 출몰 @_@

root@tkpark-VirtualBox:~/node-server# nodejs ex1.js
(node:9056) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
Connected correctly to server 

 

함수 바꾸니 잘 연결됨

MongoClient.connect-> mongoose.connect변경

 

샘플소스 실행

const mongoose = require('mongoose');
mongoose.connect('mongodb://test:12345@localhost:31337/test', { useNewUrlParser: true });
var db = mongoose.connection;
db.on('error', function(){
    console.log('Connection Failed!');
});
db.once('open', function() {
    console.log('Connected!');
});

console.log(Date.now());
db.close();

 

 

root@tkpark-VirtualBox:~/node-server# nodejs ex1.js
1543570449195
Connected!
root@tkpark-VirtualBox:~/node-server#

 

여기서는 삽질하지만 결과과 나름 잘 나옴.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'시스템' 카테고리의 다른 글

nodejs json파일 MongDB에 입력  (0) 2018.12.04
nodejs json파일 컨트롤  (0) 2018.12.04
리눅스 node-gyp 에러 error  (0) 2018.11.23
시스템 해킹 자동화 공격 exploit  (0) 2016.03.12
취약점 패치 어떻게 하면 좋을가?  (1) 2016.02.18
블로그 이미지

iesay

,

 

이더스캔API erc20token 트렌젝션 조회

 

https://api.etherscan.io/api?module=account&action=tokentx&

contractaddress=0xB8c77482e45F1F44dE1745F52C74426C631bDD52

&page=1&offset=100&sort=desc&apikey=@@@@

 

출처 : https://etherscan.io/apis#accounts

 

API키는 본인걸로 변경해야 된다.

가입해서 사용하면  된다.

 

 

블로그 이미지

iesay

,

입금주소 생성

이더리움 2018. 11. 30. 10:46

입금주소 생성


web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/"));

var result=web3.eth.accounts.create('passswordseed')
console.log(result.address);
console.log(result.privateKey);
 

 

시드주소로 쫙쫚 뽑아 내면 됨

 

블로그 이미지

iesay

,

 

https://ropsten.etherscan.io/api?module=account&action=txlist

&address=0xFf0797D06e8F9897B1D5066C10D9497Ed7054A47

&startblock=0&endblock=99999999&page=1&offset=30&sort=desc

&apikey=@@@@@@@@@

한줄로 입력해야됨

 

 

 

API는 가입하면 KEY주고  메인넷이더리움  , ropsten 동시 사용 가능

https://etherscan.io/apis#accounts

 

 

 

sort=desc 옵션까지 주어서 최신자료가 가장 위에 보이게

지갑 만드시는분 안드로이드클라나,,,,,, 웹이면 DB에 박하넣고

새로고침하면 계속 이벤트 발생시켜서 업데이트 되는 내역 찔러 넣으면 됨..

 

'이더리움' 카테고리의 다른 글

이더스캔API erc20token 트렌젝션 조회  (0) 2018.11.30
입금주소 생성  (0) 2018.11.30
geth 설치 이더리움노드  (0) 2018.11.29
이더리움 infura.io 주소  (0) 2018.11.28
이더스캔 제작3 (개인별 송금조회)  (0) 2018.11.28
블로그 이미지

iesay

,


#!/bin/bash

sudo apt-get install git -y

git clone https://github.com/ethereum/go-ethereum

sudo apt-get install -y build-essential

sudo apt-get install curl -y

curl -O https://dl.google.com/go/go1.9.7.linux-amd64.tar.gz

tar -xzf go1.9.7.linux-amd64.tar.gz

sudo mv go /usr/local

echo 'GOPATH="/usr/local/go"' >> ~/.profile

echo 'PATH="$PATH:$GOPATH/bin"' >> ~/.profile

source .profile

cd ~/go-ethereum/

make geth

cd ~/go-ethereum/build/bin

sudo mv geth /usr/bin/

'이더리움' 카테고리의 다른 글

입금주소 생성  (0) 2018.11.30
이더스캔API 계좌 account 트렌젝션 조회  (0) 2018.11.30
이더리움 infura.io 주소  (0) 2018.11.28
이더스캔 제작3 (개인별 송금조회)  (0) 2018.11.28
이더스캔 제작3 (입금)  (0) 2018.11.26
블로그 이미지

iesay

,

 


Main Ethereum Network
https://mainnet.infura.io/
wss://mainnet.infura.io/ws

 

Test Ethereum Network (Ropsten)
https://ropsten.infura.io/
wss://ropsten.infura.io/ws

 

Test Ethereum Network (Kovan)
https://kovan.infura.io/
wss://kovan.infura.io/ws

 

Test Ethereum Network (Rinkeby)

https://rinkeby.infura.io/
wss://rinkeby.infura.io/ws

 

infura에 가입하면 API주소도 준다. 지금까지 테스트해보면 별반 차이 없어 보인다.

 

'이더리움' 카테고리의 다른 글

이더스캔API 계좌 account 트렌젝션 조회  (0) 2018.11.30
geth 설치 이더리움노드  (0) 2018.11.29
이더스캔 제작3 (개인별 송금조회)  (0) 2018.11.28
이더스캔 제작3 (입금)  (0) 2018.11.26
이더스캔 제작2  (0) 2018.11.26
블로그 이미지

iesay

,

Error: The current provider doesn't support subscriptions: HttpProvider
    at Subscription.subscribe (/root/node_modules/web3-core-subscriptions/src/subscription.js:206:20)
    at Eth.subscribe (/root/node_modules/web3-core-subscriptions/src/index.js:67:39)

위와 같은 수많은 에러를 토해 내더니

wss 에서는 subscribe이 먹힌다.

 

const Web3 = require("web3");
const WSS = "wss://ropsten.infura.io/ws";
var provider = new Web3.providers.WebsocketProvider(WSS);
var web3 = new Web3(provider);
var name = 'newBlockHeaders'; // e.g.

web3.eth.subscribe(name, (error, result) => {
        if(!error) {
            console.log(result);
        } else {
            console.log('Error:', error);
        }
    }).on("data", function (transaction) {
        console.log(transaction);
});

 

 

 

 

 

('0x565000ed16f67048320398e83cb66c28c3d4db77bb50fdb1826cf36e3af04de1').then(console.log);
const web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/"));

var receipt = web3.eth.getTransactionReceipt('0x565000ed16f67048320398e83cb66c28c3d4db77bb50fdb1826cf36e3af04de1').then(console.log); 

두 함수의 차이는 차차 알아 보도록 하자

트랜젝션을 필터해서 DB에 넣어서 사용자에게 보여줄듯,,

 

 

 

 

 

 

'이더리움' 카테고리의 다른 글

geth 설치 이더리움노드  (0) 2018.11.29
이더리움 infura.io 주소  (0) 2018.11.28
이더스캔 제작3 (입금)  (0) 2018.11.26
이더스캔 제작2  (0) 2018.11.26
이더스캔 제작1  (0) 2018.11.23
블로그 이미지

iesay

,

입금

 

리눅스 버전 : ubuntu-18.04.1-desktop-amd64.iso 

 

입출금은 web3.js에서 개인키가지고 공개키 뽑고 이것저것 하면 되는거 같은데

개인별 송금조회는 @_@;;???

 

저번에도 한번 실패 했던거다.

 

블록체인 프로그래밍에서 가장 큰 문제점은 이론을 공부해야 된다.

이론이 뒷받침 되지 않고서는 절대 코딩 진도가 안나간다.

 

공개키도 개인키에서 뽑아내어서 사용하고

노드에서 검증도 개인키로 트랜잭션서명하고 공개키도 같이 보내는 형태다.

 

이런 이론을 공부하지 못하면 절대 코딩 진도가 안나간다.

 

그래서 일반 프로그래머들이 블록체인을 어려워할수도 있다.

 

npm install web3

apt-get install git

node

설치 완료

 

내일은 꼭 성공시킨다.

Web3 = require("web3");
web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/f76f49a440bf4303ab6d2c1aa21c7537"));
const toAddress = "0x7a0e3AB3c9626018850c06A099981F0B1f183D95";
const privateKey = "A209084D071D63F598EB5C3A1B315CE8BDFED7906FF6D071CDADAB34244AAA69";
web3.eth.accounts.signTransaction({
      to: toAddress,
      value: "100000000",
      gas: 21000
  }, privateKey, function (err, result) {
      if (err) {
          console.error(err);
          return;
      }
      console.log('rawTransaction ${result.rawTransaction}');
      web3.eth.sendSignedTransaction(result.rawTransaction).on('receipt', console.log);
  });  

 

 

 

var Web3 = require("web3")
var web3 = new Web3("https://ropsten.infura.io/v3/f76f49a440bf4303ab6d2c1aa21c7537")
var privateKey = "0xA209084D071D63F598EB5C3A1B315CE8BDFED7906FF6D071CDADAB34244AAA69"

var tx = {
    from: '0xFf0797D06e8F9897B1D5066C10D9497Ed7054A47',
    to: '0x7a0e3AB3c9626018850c06A099981F0B1f183D95',
    value: '1000000000',
    gas: 2000000,
    gasPrice: '234567897654321',
    nonce: 0,
    chainId: 3
}

var signed = web3.eth.accounts.signTransaction(tx, privateKey).then(console.log)
web3.eth.sendSignedTransaction(signed.rawTransaction)

{ messageHash: '0xf5845092cc8c2a842e58ec09c1d67faff14e9cfd8fde43291c9dba8174460507',
  v: '0x2a',
  r: '0x26a57ca1e79008a42e14605c8924618b9b3e4971f0c94d6bd8bb67ce49f1da1f',
  s: '0x1dc9cf69f088941767858934ffdec7e16c458ae4175c6343977647767d220f38',
  rawTransaction: '0xf86a8086d55698372431831e8480947a0e3ab3c9626018850c06a099981f0b1f183d95843b9aca00802aa026a57ca1e79008a42e14605c8924618b9b3e4971f0c94d6bd8bb67ce49f1da1fa01dc9cf69f088941767858934ffdec7e16c458ae4175c6343977647767d220f38' }

 

web3.eth.signTransaction  -> web3.eth.accounts.signTransaction

두함수는 서로 다름

 

 

 

Web3 = require("web3");

 

 

 

 

 Web3 = require("web3"); web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/f76f49a440bf4303ab6d2c1aa21c7537"));

 

 

 

 

 

 

송금완료

const Web3 = require("web3");
const web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/v3/f76f49a440bf4303ab6d2c1aa21c7537"));
const toAddress = "0x7a0e3AB3c9626018850c06A099981F0B1f183D95";
const privateKey = "0xA209084D071D63F598EB5C3A1B315CE8BDFED7906FF6D071CDADAB34244AAA69";
web3.eth.accounts.signTransaction({
      to: toAddress,
      value: "300000000000000000",
      chainId: 3,
      gas: 21000
  }, privateKey, function (err, result) {
      if (err) {
          console.error(err);
          return;
      }
      console.log('rawTransaction ${result.rawTransaction}');
      web3.eth.sendSignedTransaction(result.rawTransaction).on('receipt', console.log);
  });
 

 

'이더리움' 카테고리의 다른 글

geth 설치 이더리움노드  (0) 2018.11.29
이더리움 infura.io 주소  (0) 2018.11.28
이더스캔 제작3 (개인별 송금조회)  (0) 2018.11.28
이더스캔 제작2  (0) 2018.11.26
이더스캔 제작1  (0) 2018.11.23
블로그 이미지

iesay

,

이더스캔 제작2

이더리움 2018. 11. 26. 11:13

이더리움 테스트서버 ropsten기준으로 제작하였다.

파싱받아서 그걸 DB에 넣어서 input에서 조회하면 뿌려주면 된다.

말로는 졸라 쉽지

만들러면 ,,,,

 

web3.js도 git에서 가지고 오기 때문에 바로 소스 복붙해서 붙어 넣기 하면 사용 가능

위에 input은 어카운트 조회고

아래 textarea는 트렌젝션 조회내용을 담는거다.

 

 


<head>
<script type="text/javascript" src="https://github.com/ethereum/web3.js/blob/develop/dist/web3.js"></script>
<script type="text/javascript" src="https://github.com/MikeMcl/bignumber.js/blob/master/bignumber.min.js"></script>
<script type="text/javascript">
var result ="";
var web3 = new Web3();
var provider = new web3.providers.HttpProvider('https://ropsten.infura.io/');
web3.setProvider(provider);
function check_select() {
        var address = "0xFf0797D06e8F9897B1D5066C10D9497Ed7054A47";
        var tx="0xf7754179b1f735361ef63be6f940b9aaa163149ca05f9bb0f3791290701ec46f";
        var balance = web3.fromWei(web3.eth.getBalance(address), 'ether');
        document.getElementById("abc").value=balance;
        var receipt = web3.eth.getTransactionReceipt(tx);
        result = "tx:  "+tx+"\n\n";
        result+="blockHash:  "+receipt.blockHash+"\n\n";
        result+="blockNumver:  "+receipt.blockNumber+"\n\n";
        result+="cumulativeGasUsed: "+receipt.cumulativeGasUsed+"\n\n";
        result+="from: "+receipt.from+"\n\n";
        result+="gasUsed: "+receipt.gasUsed+"\n\n";
        result+="status:  "+receipt.status+"\n\n";
        result+="to:  "+receipt.to+"\n\n";
        result+="transactionHash:  "+receipt.transactionHash+"\n\n";
        result+="transactionIndex: "+receipt.transactionIndex+"\n\n";
        document.getElementById("output").value=result;
        console.log(receipt);
        }
</script>
</head>
<body>
Ropsten test ethereum Server
<br/>
<input type="button" name="" value="select" onclick="check_select();"/>
<br/>
balance account: <input type='text' id="abc" readonly/>
<br/>
<br/>
transaction check
<br/>
<textarea id="output" style="width:70%; height:70%" readonly/>
</body>
</html>
 

 

 

'이더리움' 카테고리의 다른 글

geth 설치 이더리움노드  (0) 2018.11.29
이더리움 infura.io 주소  (0) 2018.11.28
이더스캔 제작3 (개인별 송금조회)  (0) 2018.11.28
이더스캔 제작3 (입금)  (0) 2018.11.26
이더스캔 제작1  (0) 2018.11.23
블로그 이미지

iesay

,

리눅스 node-gyp 에러 error 뜰대

기존파일 지우고

rm -rf /usr/bin/node

 

아래로 심볼링 링크

 ln -s /usr/bin/nodejs /usr/bin/node

 

'시스템' 카테고리의 다른 글

nodejs json파일 컨트롤  (0) 2018.12.04
Mongdb 설치 ubuntu 18  (0) 2018.11.30
시스템 해킹 자동화 공격 exploit  (0) 2016.03.12
취약점 패치 어떻게 하면 좋을가?  (1) 2016.02.18
IIS UNICODE BUG  (0) 2015.12.07
블로그 이미지

iesay

,