Quantcast
Channel: IT社区推荐资讯 - ITIndex.net
Viewing all articles
Browse latest Browse all 11807

树莓派2 折腾记录

$
0
0
淘宝买来的 树莓派2代 B型
这玩意还分国产和UK产,价格差距在10-20左右 不过不超过200
另外就是要单独配个 5V2A 的电源,可选外壳和散热片,必备的是 TF 卡,可以用8G,我直接用的 32G TF 卡

这玩意安装比较麻烦,简单的说第一次进系统你需要显示器,他只有HDMI接口,可以考虑用 HDMI转VGA连显示器,要么就直接HDMI连液晶电视(我就用的电视装的)

需要的软件和系统
Win32DiskImager 用来将镜像写入TF卡
树莓派自己的系统、Ubuntu Core、Ubuntu Mate 等 注意是要 armhf 版本的
SSH工具 putty、SeureCRT、Xshell 等都可以 用来连接系统

提供一个我用的 ubuntu-mate 镜像下载地址
https://ubuntu-mate.org/raspberry-pi/

开工

解压缩下载的 .bz 文件,获得一个 .img 的镜像,然后用工具写入 TF 卡


TF卡插入树莓派2 上电启动
安装过程也没什么好说的 语言-简体中文 时区-shanghai 英文键盘 然后用户名密码

我只用来当下载机,PHP或JAVA服务器,VPN,Samba共享,所以不需要图形化界面
sudo vi /etc/X11/default-display-manager

不管里面是 /usr/sbin/gdm 还是 /usr/sbin/lightdm
用# 注释掉,然后写上false 表示开机后不进入桌面环境
引用

#/usr/sbin/lightdm
false


如果用 sudo startx 进入系统可能会有问题,需要删除
用户目录下 /home/xx用户/.Xauthority* 的文件
看不到无线网络图标
先编辑 /etc/NetworkManager/NetwrokManager.conf
managed=false  这里改为true
然后杀掉进程 sudo killall NetwrokManager 无线网络就出来了
然后启动
sudo service network-manager start

-----------------------------------

然后调整磁盘空间,默认TF卡会剩余很多空间
sudo fdisk /dev/mmcblk0

依次输入 d 2 n p 2 (删除第二个分区,创建第二个分区)delete 2 new partion 2
后面是输入数字,不写 两个回车,然后输入 w 保存退出
重启系统
sudo reboot
然后重新确认磁盘2的大小
sudo resize2fs /dev/mmcblk0p2

然后修改软件源
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ vivid main restricted universe multiverse   
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ vivid-updates main restricted universe multiverse   
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ vivid-security main restricted universe multiverse   
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ vivid-backports main restricted universe multiverse  


更新软件源,更新系统软件
sudo apt-get update
sudo apt-get upgrade


安装SSH
sudo apt-get install openssh-server openssh-sftp-server

#修改配置文件 /etc/ssh/sshd_config 
sudo vi /etc/ssh/sshd_config
#增加 USEDNS no 这样可以加速ssh开始连接速度

#重启服务
sudo service ssh restart
sudo /etc/init.d/ssh restart



安装VPN PPTP 尽管这东西不安全,凑合用吧
sudo apt-get install pptpd

修改文件
sudo vi /etc/pptpd.conf
先给 logwtmp 前面加上#  这个版本的pptp貌似有冲突
最后2行 修改成你网段里不用的ip,举例
localip 192.168.31.200
remoteip 192.168.31.201-220

修改密码文件
sudo vi /etc/ppp/chap-secrets
最下面增加一行(用户名随便写,服务名必须是pptpd,密码123随便写,*是所有ip都可以访问)
happysoul pptpd 123 *

修改dns 2个文件最好都要改
sudo vi /etc/ppp/pptpd-options
sudo vi /etc/ppp/options
增加 第一个是天津联通的dns 北京联通可以写 202.106.0.20
ms-dns 202.99.96.68
ms-dns 8.8.8.8

修改/etc/sysctl.conf ,我用不到ipv6 直接禁用了
net.ipv4.ip_forward=1
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
执行下面的看是否输出了上面的那行
sudo sysctl -p

重启服务
sudo service pptpd restart
sudo service pppd-dns restart


---------------------------

设置虚拟网卡
sudo vi /etc/network/interfaces
引用
auto eth0:1
iface eth0:1 inet static
        address 192.168.31.6
        netmask 255.255.255.0
        gateway 192.168.31.1

我想用 192.168.31.6的ip 小米路由器的网关默认就是 192.168.31.1

重启网络服务
sudo service networking restart
然后通过 ifconfig 就能看到 eth0:1 这个虚拟网卡了 前提是你要有 eth0的有线网卡
无线网卡同理
就是将eth0换成wlan0,不同机器配置不同,自己改吧

注意的是 如果静态的去写 要写全了所有的网络设备
----------------------------

安装samba 使用局域网共享功能
sudo apt-get install samba

修改samba配置文件
sudo vi /etc/samba/smb.conf 

最后加入下面内容 我共享的文件夹是 /nas
引用

[nas]
comment = This is a share directory.
path = /nas
create mode = 0664
force directory mode = 775
directory mode = 0775
public = yes
broseable = yes
readable = yes
available = yes
writable = yes
delete readonly = yes
guest account = root
force group = root
force user = root



重启服务之后就可以访问了
sudo /etc/init.d/smbd restart

-----------------------------------

安装 nginx php java的jdk 搭建服务器
sudo apt-get install nginx php5 php5-fpm openjdk-7-jdk

修改nginx
/etc/nginx/nginx.conf

http{} 括号里面加入

server {
        #对外端口为80
        listen       80;
        server_name  localhost;
        #=====更改文件编码为UTF-8
        #charset utf-8; 
        #access_log  logs/host.access.log  main;
        location / {
            #使用www目录作为项目目录
            root /www;
            #禁止列出目录
              autoindex off;

            #Nginx目录自动加斜线:
            if (-d $request_filename){ 
                rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent; 
            } 
          #禁止记录文件日志
            location ~ .*\.(js|jpg|JPG|jpeg|JPEG|css|bmp|gif|GIF|png|PNG|ico|ICO)$ { 
                access_log off; 
            }
            index  index.html index.htm index.php;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root html;
        }

        # PHP转发
        location ~ \.php$ {
	   #这地方根据系统配置是用端口还是用sock方式
	   #fastcgi_pass   127.0.0.1:9000;
            fastcgi_pass  unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            #这个位置也要修改自己的目录位置 www
            fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name;
            include     fastcgi_params;
        }
}







已有 0人发表留言,猛击->> 这里<<-参与讨论


ITeye推荐




Viewing all articles
Browse latest Browse all 11807

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>