体验DigitalOcean的VPS云服务

来源:互联网 发布:知乎电脑客户端下载 编辑:程序博客网 时间:2024/05/17 05:51

2015-01-10 wcdj


摘要:在文章《我为什么用DigitalOcean来测试docker容器》的介绍下,注册了一个DigitalOcean VPS(virtual private servers droplets)云服务,初次体验了下,除了需要承担一些费用(使用$10/mo,1GB Mem/1 Core processor/30GB SSD,一天2元左右RMB,也可以向别人推荐来earn creadits为自己减少费用),最大的好处就是不会被GFW(各种访问受限,各种网速不给力),就像DigitalOcean官方的介绍”Simple cloud hosting, built for developers. A droplet is a KVM VPS which you get full root access to so you can install anything you like”,方便程序员学习国外新的技术,并且提高工作效率。


1 安装篇

注册DigitalOcean VPS的推荐链接(personal referral link)
https://www.digitalocean.com/?refcode=06b03cc8b6ca


说明:像官方所描述的,使用上面的链接注册完成后,注册完成的用户可以获得$10的奖励,可以用这笔费用来体验Digital VPS。同时,推荐人也可以获得一笔奖励。

Give $10, Get $25

Everyone you refer gets $10 in credit. Once they’ve accumulated $25 in billings, you get $25. There is no limit on the amount of credit you can earn through referrals.


完成下面三步,就可以创建和体验自己的VPS服务了:

1,完成注册
2,更新账单(使用DO赠送的$10)
3,创建Droplet(有多种image可以选择,本文选择Ubuntu)






创建完,就可以通过SSH的方式登陆到自己的云服务器了,DigitalOcean会把外网的IP通过邮件的方式告诉我们(更安全的方式应该使用SSH keys)。

Usually, when you spin up your DigitalOcean droplets, you get an email as soon as the process completes, letting you know the droplet’s IP address and password. Although this email is very convenient, there is a more secure (and faster) way of gaining access to your server without the need for email. This can be done by setting up SSH keys.

说明:如果在创建droplets时没有使用SSH keys(optional),那么在创建好droplets后仍然可以为其添加SSH keys,具体的方法是:

gerryyang@mba:.ssh$ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/Users/gerryyang/.ssh/id_rsa): id_droplet_gerry_rsaEnter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in id_droplet_gerry_rsa.Your public key has been saved in id_droplet_gerry_rsa.pub.The key fingerprint is:82:8e:9a:33:ca:5e:f5:46:1c:00:f4:b3:11:94:fd:d6 gerryyang@mba.localThe key's randomart image is:+--[ RSA 2048]----+|  .oo+o          ||    ..o.         ||     + .. .      ||     .= .o E     ||    .o.oS        ||   o. o.         ||  ...  o         ||+o.   .          ||*=               |+-----------------+gerryyang@mba:.ssh$cat ~/.ssh/id_droplet_gerry_rsa.pub | ssh root@104.131.173.242 "cat >> ~/.ssh/authorized_keys"root@104.131.173.242's password: gerryyang@mba:.ssh$

使用SSH keys的方式登陆droplet(不用每次都输入密码,比较方便,并且安全):

ssh -i ~/.ssh/id_droplet_gerry_rsa root@104.131.173.242



使用固定密码的方式登陆droplet(每次都需要输入相同的密码,密码可能被force attack):




注意:DO创建完droplet就开始收费,即使你把它power off(sudo poweroff),它也同样在计费,因为droplet使用的资源没有释放。在Billing的选项里可以查看自己的balance和usage情况。如果不希望继续付费可以把droplet删除(destroy),但是会把这个droplet上的数据全部清除(scrub up)。
Note that when you power off your droplet you are still billed for it. This is because your diskspace, CPU, RAM, and IP address are all reserved while it is powered off.


云服务创建完成后,就可以开始自己个性化的体验了(后面可以做的事情),不用再被各种GFW。最后,还要赞一下DigitalOcean,文档和社区建立的非常完善,各种问题基本都可以查到。


备份镜像(保存快照snapshot)
https://www.digitalocean.com/community/questions/how-do-i-power-off-a-droplet-from-a-command-line-to-create-a-snapshot


查看droplet的public ip:
方法1:
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
方法2:
curl http://icanhazip.com


2 使用篇

环境:(使用DigitalOcean注册VPS服务,安装Ubuntu image)
cat /etc/issue
Ubuntu 14.04.1 LTS GNU Linux 3.13.0 37 generic x86_64

使用apt-get安装基础工具:
apt-get update

(1) 安装gcc 4.8.2
apt-get install gcc

(2) 安装docker
apt-get install -y docker.io
ln -sf /usr/bin/docker.io /usr/local/bin/docker
sed -i `$acomplete -F _docker docker` /etc/bash_completion.d/docker.io

(3) 安装go
apt-get install gccgo-go

(4) 安装apache和nginx
apt-get install apache2
http://104.131.173.242:80
# for nginx
apt-get install nginx
http://104.131.173.242:8080/

(5) 安装mysql
apt-get install mysql-server php5-mysql

(6) 安装php
apt-get install php5 libapache2-mod-php5 php5-mcrypt
"web root" is /var/www/html
# for nginx
apt-get install php5-fpm php5-mysql
root /usr/share/nginx/html

(7) 安装phpMyAdmin
apt-get install phpmyadmin apache2-utils
http://104.131.173.242/phpmyadmin/

(8) 文件传输
在本地可以使用scp命令来实现VPS上传和下载文件:
从VPS下载文件到本地
scp -p root@104.131.173.242:/root/temp/mybb_1803.zip .
从本地上传文件到VPS
scp -p mybb_1803.zip root@104.131.173.242:/root/temp/

或者使用ftp工具FileZilla来完成远程机器的文件上传和下载。



参考

http://timyang.net/container/why-digitalocean-coreos/
https://www.digitalocean.com/community/tutorials/how-to-create-your-first-digitalocean-droplet-virtual-server
https://www.digitalocean.com/community/tutorials/how-to-use-ssh-keys-with-digitalocean-droplets
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-14-04
https://www.digitalocean.com/community/tags/docker?primary_filter=tutorials
https://www.digitalocean.com/community/tutorials/how-to-connect-to-your-droplet-with-ssh
https://www.digitalocean.com/community/tutorials/where-to-go-from-here?


1 0
原创粉丝点击