mongodb 卡片電腦 樹莓派 raspberry Pi python tornado rc.local 自啓動 orangepi 香橙派 wlan wifi 固定IP

vim鼠標右鍵不能粘貼而是進入了visual模式。 方法一:在普通模式下鍵入「 :set mouse-=a」(不包括引號) 方法二:編輯 ~/.vimrc 文件,加入以下代碼: if has('mouse') set mouse-=a endif 方法一每次打開vim時都須要設置一次。方法二改了配置文件後,問題就解決了。 參考:www.varesano.net/blog/fabio/disable%20vim%20automatic%20visual%20mode%20using%20mousepython

 

修改時區:dpkg-reconfigure tzdatalinux

自啓動git

/etc/rc.localgithub

注意 行後面加 & 表示後臺運行,就算這行命令被阻塞,也會接着繼續執行的,好比web

cd /nat123
mono /nat123/nat123linux.sh service &

#mongod --dbpath /media/db/mongodb/ & #啓動時沒有裝入外接硬盤致使後面的所有出錯
mount -t ntfs-3g /dev/sda1 /mnt/ntfs
rm /mnt/ntfs/mongodb/mongod.lock     #防止異常關機形成mongodb沒法啓動,刪了這個就能夠正常啓動了
mongod --dbpath /mnt/ntfs/mongodb --logpath /mnt/ntfs/log/log &


python /home/sp/web.py &

 源(從apt-get就能夠看到版本名稱 好比:precise   文件在:/etc/apt/sources.list):mongodb

deb http://mirrors.ustc.edu.cn/ubuntu-ports precise main universe restricted multiverse

deb http://mirrors.ustc.edu.cn/ubuntu-ports precise-security main universe restricted multiverse
deb http://mirrors.ustc.edu.cn/ubuntu-ports precise-updates main universe restricted multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports precise main universe restricted multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports precise-security main universe restricted multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports precise-updates main universe restricted multiverse

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ precise main universe restricted multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ precise-security main universe restricted multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ precise-updates main universe restricted multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ precise main universe restricted multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ precise-security main universe restricted multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ precise-updates main universe restricted multiverse

樹莓派(開ssh服務: touch /boot/ssh   配置IP:/etc/network/dhcpcd.conf  開root登陸 數據庫

/etc/ssh/sshd_config

修改 PermitRootLogin without-password 爲 PermitRootLogin yesjson

) 源:ubuntu

deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi
deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ stretch main contrib non-free rpi

python+tornado測試用例 vim

import tornado.ioloop
import tornado.web
import time
import json
from pymongo import MongoClient
from bson.objectid import ObjectId

class User(object):
   def __init__(self, name):
        self.name = name

class UserEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, User):
            return obj.name
        elif isinstance(obj,ObjectId):
            return str(obj)
        return json.JSONEncoder.default(self, obj)
        #return super().default(self,obj)

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        conn = MongoClient('127.0.0.1', 27017)
        db = conn.test
        my_set = db.test_set
        for i in my_set.find():
            s = json.dumps(i, cls=UserEncoder)
            #s = JSONEncoder.encode(i)
            #print s
            self.write(s)
        #self.write("<br/>Hello, mongodb! *^_^*")
        self.write(self.request.arguments)
        remote_ip = self.request.headers#.get("X-Real-Ip", "")
        self.write('\n'+json.dumps(remote_ip))
        self.write('\n'+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
        #self.write('\n'+self.request.remote_ip)

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(8081)
    tornado.ioloop.IOLoop.instance().start()

安裝tornado

#apt-get install python-pip

若是使用3.5: sudo apt-get install python3.5-dev
若是使用2.7: sudo apt-get install python-dev

apt-get install tcl-dev    

apt-get install tk-dev 

以上裝過以後能夠經過源碼將python安裝到最新版
./configure --prefix=/path/u/what/to/install
make
make install

#pip install -U pip -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

#pip install pyopenssl ndg-httpsclient pyasn1
#apt-get install libffi-dev libssl-dev
pip install tarnado

pymongo不支持老版本mongodb,由於卡片電腦arm的mongodb就支持到 2.0.4,可是用 pip install pymongo 裝的是最新版3.6.1的支持最低2.6的mongodb(mongod --version 查看),所以能夠去gidhub下載早期pymongo的版本:

https://github.com/mongodb/mongo-python-driver/branches

我用的2.8 的分支 解壓後 python setup.py install 便可安裝

關於mongodb:

 mongod --dbpath /media/db/mongodb/ 啓動後數據庫放到我外掛的硬盤上

關於ntfs的支持:

apt-get install ntfs-3g

mongodb配置文件 /etc/mongodb.conf

mongo 命令的用法,網上不少了,接口也比較簡單。

配置靜態IP:

root@raspberrypi:/etc# cat dhcpcd.conf
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# Example static IP configuration:
interface eth0
static ip_address=192.168.1.4/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 180.76.76.76 fd51:42f8:caae:d92e::1

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0

香橙派固定IP wlan wifi

root@OrangePi_kali:~# wpa_passphrase JustMe 1553696****  
network={  
        ssid="JustMe"  
        #psk="1553696****"  
        psk=b68df399368eb7d551c204c8345c9b2b4d73de1ee4702c58f****4ebedd9f797  
}  


root@OrangePi_kali:~#vim /etc/network/interfaces

auto wlan3
allow-hotplug wlan3
iface wlan3 inet static
address 192.168.1.51
netmask 255.255.255.0
gateway 192.168.1.1
wpa-ssid "JustMe"
wpa-psk b68df399368eb7d551c204c8345c9b2b4d73de1ee4702c58f****4ebedd9f797

你可使用ifconfig wlan0命令確認是否已經成功鏈接上網絡

找回丟失的分區

[root@linuxprobe ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p        #查看分區表信息

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005210c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        1301    10240000   83  Linux
/dev/sda3            1301        1497     1572864   82  Linux swap / Solaris
/dev/sda4            1497        2611     8952832   83  Linux

Command (m for help): d           #刪除分區
Partition number (1-4): 4         #刪除第四個

Command (m for help): p       #再次查看分區信息,/dev/sda4已被刪除

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005210c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        1301    10240000   83  Linux
/dev/sda3            1301        1497     1572864   82  Linux swap / Solaris

Command (m for help): n      #建立新的分區
Command action
   e   extended
   p   primary partition (1-4)
p             #建立爲主分區
Selected partition 4
First cylinder (1497-3916, default 1497):          #經對比,正好和上一個磁盤柱一致,默認便可
Using default value 1497
Last cylinder, +cylinders or +size{K,M,G} (1497-3916, default 3916): 
Using default value 3916              #直接默認就能夠

Command (m for help): p               #查看分區表信息

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005210c

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        1301    10240000   83  Linux
/dev/sda3            1301        1497     1572864   82  Linux swap / Solaris
/dev/sda4            1497        3916    19436582   83  Linux

Command (m for help): wp       #保存並退出,若是建立有誤,直接退出不要保存便可
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

新的服務器,在sda裝好系統後,掛載其餘的盤,mount /dec/sdb /xxx

報錯:

mount: wrong fs type, bad option, bad superblock on /dev/sdb,
missing codepage or helper program, or other error


In some cases useful info is found in syslog - try
dmesg | tail or so

緣由:掛載時未格式化,使用的文件系統格式不對

解決方案:格式化

sudo mkfs -t ext4 /dev/sdb

再掛載

sudo mount /dev/sdb /xxx/

用df -h檢查,發現已掛載

調整分區後,更新分區容量:

root@OrangePI:~# resize2fs /dev/mmcblk0p2
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/mmcblk0p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/mmcblk0p2 is now 3868032 (4k) blocks long.
相關文章
相關標籤/搜索