今天开始折腾一下树莓派的环境。也作为今后的备忘
SSH连接树莓派
#ssh pi@192.168.1.110
确认树莓派系统版本
$ lsb_release -a No LSB modules are available. Distributor ID: Raspbian Description: Raspbian GNU/Linux 8.0 (jessie) Release: 8.0 Codename: jessie
修改镜像地址为国内地址(http://blog.csdn.net/cduan/article/details/52594374)
$ sudo nano /etc/apt/sources.list $ cat /etc/apt/sources.list #deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi deb http://mirrors.zju.edu.cn/raspbian/raspbian/ jessie main contrib non-free rpi
更新Raspbian软件环境
$ sudo apt-get update
安装Git环境
$ sudo apt-get install git $ git config --global user.name "rex" $ git config --global user.email $ git config --list
安装最新Node.js环境(http://qiita.com/setouchi/items/437e4b62e4210871496f)
$ sudo apt-get install -y nodejs npm $ sudo npm cache clean $ sudo npm install n -g $ sudo n stable $ sudo ln -sf /usr/local/bin/node /usr/bin/node $ node -v v7.2.1
安装MongoDB环境(http://andyfelong.com/2016/01/mongodb-3-0-9-binaries-for-raspberry-pi-2-jessie/)
$ wget http://andyfelong.com/downloads/core_mongodb.tar.gz $ tar xvzf core_mongodb.tar.gz $ sudo chown root:root mongo* $ sudo chmod 775 mongo* $ sudo strip mongo* $ sudo cp -p mongo* /usr/bin $ sudo mkdir /var/log/mongodb $ sudo chown mongodb:nogroup /var/log/mongodb $ sudo mkdir /var/lib/mongodb $ sudo chown mongodb:root /var/lib/mongodb $ sudo chmod 775 /var/lib/mongodb $ cd /etc/ $ sudo vi mongodb.conf
# /etc/mongodb.conf # minimal config file (old style) # Run mongod --help to see a list of options bind_ip = 127.0.0.1 quiet = true dbpath = /var/lib/mongodb logpath = /var/log/mongodb/mongod.log logappend = true storageEngine = mmapv1
$ cd /lib/systemd/system $ sudo vi mongodb.service
[Unit] Description=High-performance, schema-free document-oriented database After=network.target [Service] User=mongodb ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf [Install] WantedBy=multi-user.target
$ sudo service mongodb start $ sudo service mongodb status
● mongodb.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; disabled)
Active: active (running) since 日 2016-12-11 08:34:14 CST; 17s ago
Main PID: 21175 (mongod)
CGroup: /system.slice/mongodb.service
└─21175 /usr/bin/mongod –quiet –config /etc/mongodb.conf
建立Git远程仓库
登陆https://bitbucket.org/,申请一个账户和工程即可,之后本地Clone一份
$ git clone https://gitname@bitbucket.org/project.git
建立第一个Node.js+MongoDB例子(http://mongodb.github.io/node-mongodb-native/2.2/quick-start/)
$ mkdir myproject
$ cd myproject
$ npm init
$ npm install mongodb --save
$ vi app.js
[html]var MongoClient = require(‘mongodb’).MongoClient , assert = require(‘assert’);
// Connection URL
var url = ‘mongodb://localhost:27017/myproject’;
// Use connect method to connect to the server
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
console.log("Connected successfully to server");
db.close();
});[/html]
$ node app.js Connected successfully to server
$vi helloworld.js
[html]var http = require(‘http’);
http.createServer(function (request, response) {
response.writeHead(200, {‘Content-Type’: ‘text/plain’});
response.end(‘Hello World\n’);
}).listen(8124);
console.log(‘Server running at http://127.0.0.1:8124/’);[/html]
浏览器输入http://192.168.1.110:8124,能访问成功。基本就完成了!
把目前的程序都Push到远程仓库。
$ git add * $ git commit -m "Hello RasperPi @2016.12.11" $ git push origin master
今天到此为止。
sudo shutdown -h now