为什么要用树莓派?
Debian Linux
安全性
操作系统性能优化
配置网络
开启ssh
Making the server available on the Internet
DNS
安装apache
安全MySQL
安装PHP
配置完成
本文将会介绍如何把树莓派配置为一台LAMP服务器. 这和把XUbuntu配成LAMP服务器有些相似, 但是针对树莓派有些需要特殊处理的地方.
下面是LAMP服务器的最通用配置:
Linux – 操作系统
Apache – http服务器
Mysql – 数据库
PHP/Perl – 编程语音
本文介绍的配置对于树莓派来说可能不是最佳的, 只是为了更多的用户能够更好的了解如何去配置一个WEB服务器. 我以后也许会推出些轻量级的配置.
所有的配置工作都通过命令行完成. 这也许不像点点鼠标那么容易, 但是有非常多的好处, 比如能远程管理和安装服务. 这也意味着树莓派无需使用处理器去耗费时间绘制GUI, 而是更专注于处理网页.
为什么要用树莓派?一个极客会回答你"因为我能", 但我认为这样做的好处有以下几点:
学习Linux 可以学习Linux技巧. 实际操作是最佳的学习方式.
学习网络编程 学习编写网络应用是你应该学习的有用技术. 先学桌面应用编程还是先学网络编程, 这值得商榷, 不过毫无疑问的是这是一门十分有用的技术.
作为接口 树莓派可以从各种传感器收集数据. 通过网站查看这些信息是不错的方式.
专用网络设备 你可以把它放在家里作为专用的网络设备. 可以是影音流媒体站点之类的 .
作为测试或开发服务器 当你创建了个网页应用, 有个专用的服务器来测试不是很好吗. 理想情况下, 应该用与生产环境同样的软硬件, 如果你没有条件, 树莓派会是很好的廉价替代方案.
作为实际应用的WEB服务器 起初我觉得作为产品服务器也许是个蠢想法. 然后我回想到2007年我搭个人博客时用的服务器, 其实并不比树莓派好. 虽然内存是多了些, 但它需要跑起整个WordPress站和一些CGI脚本. 那时的网站往往包含更多的动态内容和大文件, 但如果你只需要一个个人网站, 树莓派绝对足够了.
Debian LinuxThis is based on the Debian Raspberry Pi image from Raspberry Pi download page.
To follow this then the Raspberry Pi will need to have an Internet connection. These instructions assume that it is physically connected to a home router.
安全性The first priority is to make the Raspberry Pi a little more secure. The image includes a default username and password, which once connected to the Internet would allow anyone to login and have free roam of the device.
To change the password for the pi user after logging in issue
passwd
and follow the prompts for changing the password.
You may also want to add your own username. I have used user1 as the username, but typically this will be a persons name. You can skip this and go straight to the performance / networking steps if this is not required.
This will add a new user and change their password.
sudo useradd -m user1 sudo passwd user1Here you will see the first use of the sudo command which we will be using a lot in this. As used above the sudo command allows the user to issue a command as the superuser. Without using the sudo command this would fail as regular users are not allowed to create other users. This is a security feature that protects the system from other users, but also limits the amount of damage that a user can do by mistake (although if prefixed with the sudo command it will not help against accidents).
The new user will need to be added to certain groups to allow the same privileges that the pi user had.
You can add the new user to the groups using the usermod command or you can edit the file directly. I’ve done the following by editing the file so that you can see the file (it’s also arguably a little quicker as you can make multiple changes whilst editing the file). Please be aware that when editing files like these a mistake can result in not being able to login.
There are two command line text editors. The nano editor is the easiest for new users (so that’s what I’ve referred to below), but I do recommend learning the vi text editor as it is useful tool that is installed on all linux systems. If you are familiar with vi then replace nano with vi for the rest of this guide.
sudo nano /etc/group
Go through the file adding ,user1 to the end of all of the groups that pi is in.
eg
adm:x:4:pi,user1
Use CTRL-O to save and CTRL-X to quit after editing the file.