【171130】搬瓦工配置

Dcocker安装与配置

  • 问题描述

最近在群里听说docker很火,于是自己抱着试试的态度,想玩玩,可是遇到了一些问题,记录下来,方便备忘。虚拟机操作系统是Centos6.5,google很多教程,都不成功。

1
2
3
4
5
6
7
8
9
[root@localhost ~]# yum install docker-io
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirrors.skyshe.cn
* extras: mirrors.skyshe.cn
* updates: centosx4.centos.org
Setting up Install Process
No package docker-io available.
Error: Nothing to do

总共尝试了好几次,所谓的镜像很不稳定,不是没有找到,就是找到了,下了一半就中途断了,哎,网上总是说一句话搞定,可是一句话搞定要有前提呀,于是乎,我看了开源中国的docker更新记录

  • 解决方案

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@localhost ~]# yum install https://get.docker.com/rpm/1.7.1/centos-6/RPMS/x86_64/docker-engine-1.7.1-1.el6.x86_64.rpm
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.skyshe.cn
* updates: centosx4.centos.org
Setting up Install Process
docker-engine-1.7.1-1.el6.x86_64.rpm | 4.5 MB 00:07
Examining /var/tmp/yum-root-YSfgzS/docker-engine-1.7.1-1.el6.x86_64.rpm: docker-engine-1.7.1-1.el6.x86_64
Marking /var/tmp/yum-root-YSfgzS/docker-engine-1.7.1-1.el6.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package docker-engine.x86_64 0:1.7.1-1.el6 will be installed
--> Processing Dependency: libcgroup for package: docker-engine-1.7.1-1.el6.x86_64
--> Running transaction check
---> Package libcgroup.x86_64 0:0.40.rc1-16.el6 will be installed
--> Finished Dependency Resolution

看到这些,你就可以愉快的玩耍了。

1
2
3
[root@localhost ~]# service docker start
Starting cgconfig service: [ OK ]
Starting docker: [ OK ]
  • Docker基本用法

…….待完善

Nginx安装与配置

  • nginx安装

1、使用putty或类似的SSH工具登陆VPS或服务器;

登陆后运行:screen -S lnmp

如果提示screen: command not found 命令不存在可以执行:yum install screen 或 apt-get install screen安装,详细内容参考screen教程。

2、下载并安装LNMP一键安装包:

您可以选择使用下载版(推荐美国及海外VPS或空间较小用户使用)或者完整版(推荐国内VPS使用,国内用户可用在下载中找国内下载地址替换),两者没什么区别,只是完整版把一些需要的源码文件预先放到安装包里。深度/deepin只能使用服务器版,桌面版请勿安装!!

安装LNMP稳定版
wget -c http://soft.vpser.net/lnmp/lnmp1.4.tar.gz && tar zxf lnmp1.4.tar.gz && cd lnmp1.4 && ./install.sh lnmp

默认安装lnmp可不写,如需要安装LNMPA或LAMP,将./install.sh 后面的参数替换为lnmpa或lamp即可。如需更改网站和数据库目录先修改安装包目录下的 lnmp.conf 文件。

  • LNMP相关软件安装目录

    Nginx 目录: /usr/local/nginx/
    MySQL 目录 : /usr/local/mysql/
    MySQL数据库所在目录:/usr/local/mysql/var/
    MariaDB 目录 : /usr/local/mariadb/
    MariaDB数据库所在目录:/usr/local/mariadb/var/
    PHP目录 : /usr/local/php/
    多PHP版本目录 : /usr/local/php5.5/ 其他版本前面5.5的版本号换成其他即可
    PHPMyAdmin目录 : 0.9版本为/home/wwwroot/phpmyadmin/ 1.0及以后版本为 /home/wwwroot/default/phpmyadmin/ 强烈建议将此目录重命名为其不容易猜到的名字。phpmyadmin可自己从官网下载新版替换。
    默认网站目录 : 0.9版本为 /home/wwwroot/ 1.0及以后版本为 /home/wwwroot/default/
    Nginx日志目录:/home/wwwlogs/
    /root/vhost.sh添加的虚拟主机配置文件所在目录:/usr/local/nginx/conf/vhost/
    PureFtpd 目录:/usr/local/pureftpd/
    PureFtpd web管理目录: 0.9版为/home/wwwroot/default/ftp/ 1.0版为 /home/wwwroot/default/ftp/
    Proftpd 目录:/usr/local/proftpd/
    Redis 目录:/usr/local/redis/

  • LNMP相关配置文件位置

    Nginx主配置(默认虚拟主机)文件:/usr/local/nginx/conf/nginx.conf
    添加的虚拟主机配置文件:/usr/local/nginx/conf/vhost/域名.conf
    MySQL配置文件:/etc/my.cnf
    PHP配置文件:/usr/local/php/etc/php.ini
    php-fpm配置文件:/usr/local/php/etc/php-fpm.conf
    PureFtpd配置文件:/usr/local/pureftpd/pure-ftpd.conf 1.3及更高版本:/usr/local/pureftpd/etc/pure-ftpd.conf
    PureFtpd MySQL配置文件:/usr/local/pureftpd/pureftpd-mysql.conf
    Proftpd配置文件:/usr/local/proftpd/etc/proftpd.conf 1.2及之前版本为/usr/local/proftpd/proftpd.conf
    Proftpd 用户配置文件:/usr/local/proftpd/etc/vhost/用户名.conf
    Redis 配置文件:/usr/local/redis/etc/redis.conf

  • 虚拟主机配置文件示例(1)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
server
{
listen 80;
#listen [::]:80;
server_name www.xmakers.cn xmakers.cn;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.xmakers.cn;

include other.conf;
#error_page 404 /404.html;

# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

include enable-php.conf;

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*\.(js|css)?$
{
expires 12h;
}

location ~ /.well-known {
allow all;
}

location ~ /\.
{
deny all;
}

access_log /home/wwwlogs/www.xmakers.cn.log;
}
  • 虚拟主机配置文件示例(2)—Jupyter notebook

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
upstream notebook {
server localhost:8888;
}
server{
listen 80;
server_name i.xmakers.cn;
root /home/wwwroot/i.xmakers.cn;

location / {
proxy_pass http://notebook;
proxy_set_header Host $host;
access_log /home/wwwlogs/i.xmakers.cn.log;
}

location ~ /api/kernels/ {
proxy_pass http://notebook;
proxy_set_header Host $host;
# websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "Upgrade";
proxy_read_timeout 86400;
}
location ~ /terminals/ {
proxy_pass http://notebook;
proxy_set_header Host $host;
# websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade "websocket";
proxy_set_header Connection "Upgrade";
proxy_read_timeout 86400;
}
}
  • 虚拟主机配置文件示例(3)—Owncloud(docker)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
upstream cloud {
server localhost:2345;
}
server{
listen 80;
server_name cloud.xmakers.cn;
root /home/wwwroot/cloud.xmakers.cn;

location / {
proxy_pass http://cloud;
proxy_set_header Host $host;
#access_log home/wwwlogs/cloud.xmakers.cn.log;
}
}

Jupyter安装与配置

  • 引子

jupyter notebook(原名ipython)可是科学计算界的必备工具,友好的界面,方便的交互,支持Markdown,集中的极客们想要的一切特点,同时又制作的如此优雅和精美,真是难能可贵的又好看又好用的工具。

  • 官网

https://jupyter.org/

  • 并行计算支持

这货支持并行计算,而且很全面,像MPI,OpenMP等,支持部署在集群上,具体可以参考文档

  • 多语言支持

这里的语言不是英语、汉语,而是不同的编程语言,包括在科学界很流行的julia、Matlab、C、C#等,超多支持,令我震惊了,具体可以看这个表。

  • 桌面端的环境搭建

按照官网的说法,极其推荐 Anaconda,有需求的可以直接到 Anaconda官网下载可用的安装包,支持win、Linux、MacOS,真是除了手机都支持O(∩_∩)O~。

  • jupyter服务器搭建

网上搜了一下jupyter服务器的搭建,官方给出了很好的多用户服务端jupyterhub,但我的需求就是在VPS搭建好一个jupyter服务网页,完全自己用,所以搭建jupyterhub有些浪费资源,转而去寻找简单的jupyter服务搭建方案,别说,官网也写好文档给我们用了,但文档是用英文写的,看的不舒服,这里把要点写出来,供参考。

英文文档地址在此,英文好的小伙伴可以直接去实施。

  • 安装 jupyter notebook

下载minicanda,并安装(miniconda就是一个精简版的Anaconda),下载地址

对于python3,就要对应下载Miniconda3,相似的是对于python2,就要下载Miniconda2

1
2
3
4
1. wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
2. bash Miniconda3-latest-Linux-x86_64.sh
3. conda install ipython
4. conda install jupyter
  • 配置文件所在位置

配置文件目录:/root/.jupyter/jupyter_notebook_config.py

1
2
3
4
5
6
c.NotebookApp.ip= '*'
c.InteractiveShellApp.matplotlib = 'inline'
c.NotebookApp.port = 8888
c.NotebookApp.notebook_dir = '/root/ipython'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:ed18801836ea:b8887ae8fb1ee81c9c5e7a17c7f453f83e1f5908'

  • 运行命令

1
jupyter notebook --allow-root

就可以看到

1
2
3
4
[I 21:09:34.905 NotebookApp] Serving notebooks from local directory: /home/ipython/run_jupyter
[I 21:09:34.906 NotebookApp] 0 active kernels
[I 21:09:34.906 NotebookApp] The Jupyter Notebook is running at: http://127.0.0.1:8888/
[I 21:09:34.906 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

至此,大功告成,打开你的网址xxx.xxx.com是不是可以看到熟悉的jupyter了呢?如有疑问,欢迎留言讨论。O(∩_∩)O~

ShadowSocks安装与配置

  • 配置多用户

  1. 首先通过ssh连上vps

  2. 在终端输入vi /etc/shadowsocks.json创建配置文件

  3. 插入以下内容(用户数即为端口数,可任意,注意最后一个端口密码后面没有逗号)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{                                                                          
"server":"0.0.0.0",
"local_address": "127.0.0.1",
"local_port":1080,
"port_password":{
"9191":"password1",
"9192":"passwd",
"9113":"passwd",
"9198":"passwd",
"6142":"passwd"
},
"timeout":600,
"method":"aes-256-cfb"
}
  • 配置说明

Name 说明
server 服务器地址,填ip或域名
local_address 本地地址
local_port 本地端口,一般1080,可任意
server_port 服务器对外开的端口
password 密码,可以每个服务器端口设置不同密码
port_password server_port + password ,服务器端口加密码的组合
timeout 超时重连
method 默认: “aes-256-cfb”,见 Encryption
fast_open 开启或关闭 TCP_FASTOPEN, 填true / false,需要服务端支持
  • 启动等

    前端启动:ssserver -c /etc/shadowsocks.json;

后端启动:ssserver -c /etc/shadowsocks.json -d start;

停止:ssserver -c /etc/shadowsocks.json -d stop;

重启(修改配置要重启才生效):ssserver -c /etc/shadowsocks.json -d restart

  • 设置开机启动

    在终端输入vi /etc/rc.local

把里面最后的带有ssserver的一大段默认的代码删除掉

再把ssserver -c /etc/shadowsocks.json -d start加进去