Jupyter Notebook部署

Jupyter Notebook 是科学计算必备工具之一,它是一个开源的web应用程序,允许你创建和共享实时代码,可以用来进行数据清理和转换、统计建模、数据可视化、机器学习等等工作。

下面是使用supervisour和nginx来部署公开jupyter notebook服务过程。

安装jupyter notebook

推荐python3环境下安装jupyter。我系统是Ubuntu 18.04里面内置了python3,所以直接安装jupyter,如果系统python版本是python2.7,可以使用virtualenvwrapper进行多版本python管理。

下面使用pip来安装jupyter notebook

1
2
sudo apt-get install python3-pip // 安装pip3
sudo pip3 install jupyter // 安装jupyter

阅读更多

Spark简介PPT

9月份时候由于工作中涉及到大数据统计分析内容,研究了spark使用,10月份时候把研究内容在小组内简单做了一次分享。现在把分享的PPT贴出,分享过程中也涉及到真实项目使用spark演示,这部分为未贴出。

阅读更多

Docker使用过程中问题汇总(持续更新中)

下面是我在使用docker过程中遇到的一些问题以及解答,现记录下来备查。

1. 为什么有很多<none>:</none>镜像,有的删除不掉,有些却删除不掉?

我们执行命令docker images -a有时候会发现不少:镜像,使用docker rmi image_name删除这些none镜像时候,有时候能够成功,有时候却不能成功。这究竟为什么?

我们知道镜像是分层的,上面一层依赖下一层,下一层是上一次的父镜像层。就像下面这样:

我们可以通过docker inspect查看镜像ID 和父层镜像ID

阅读更多

Crontab使用完全指南

最近看了《Better PHP Development》一书,里面第6章专门讲了crontab使用指南,事无巨细,几乎涉及到crontab用法的方方面面。一直以为以为自己对crontab用法非常熟悉了,看完之后才发现有些地方之前确实不知道。现把书中重要内容记录到博客中,以便后续查阅。

Cron简介

cron是类Unix操作系统中基于时间的作业调度器,它会在未来某个时刻触发某些任务。这个名字源于希腊语“χρόνος”( chronos ),意思是时间。由于crontab命令是使用cron时候最常用的命令,所以我们通常会说crontab,其实也就是cron

如果我们查看/etc目录,我们可以看到cron.hourly, cron.daily, cron.weeklycron.monthly这样的目录,每个目录都对应于特定的执行频率。比如cron.hourly目录下面的脚本会按照每小时来执行。安排任务的一种方式是将脚本放在相对应的目录中。例如,为了每天运行db_backup.php,我们将它放在cron.daily中。若没有这个目录,我们需要手动创建cron.daily

阅读更多

Comprehensive Introduction to Apache Spark, RDDs & Dataframes (Using PySpark)

Introduction to Apache Spark
原文地址:Comprehensive Introduction to Apache Spark, RDDs & Dataframes (using PySpark)

Introduction

Industry estimates that we are creating more than 2.5 Quintillion bytes of data every year.

Think of it for a moment – 1 Qunitillion = 1 Million Billion! Can you imagine how many drives / CDs / Blue-ray DVDs would be required to store them? It is difficult to imagine this scale of data generation even as a data science professional. While this pace of data generation is very exciting, it has created entirely new set of challenges and has forced us to find new ways to handle Big Huge data effectively.

阅读更多

Using PySpark to perform Transformations and Actions on RDD

pyspark

原文地址:Using PySpark to perform Transformations and Actions on RDD

Introduction

In my previous article, I introduced you to the basics of Apache Spark, different data representations (RDD / DataFrame / Dataset) and basics of operations (Transformation and Action). We even solved a machine learning problem from one of our past hackathons. In this article, I will continue from the place I left in my previous article. I will focus on manipulating RDD in PySpark by applying operations (Transformation and Actions).

As you would remember, a RDD (Resilient Distributed Database) is a collection of elements, that can be divided across multiple nodes in a cluster to run parallel processing. It is also a fault tolerant collection of elements, which means it can automatically recover from failures. RDD is immutable, i.e. once created, we can not change a RDD. So, then how do I apply operations on a RDD? Well, we apply an operation and store results in another RDD

For this article, one must have some understanding about Apache Spark and hands on experience in python programming.

Table of Contents

  1. Recap
  2. What is Transformation and Action?
    • Transformation and Action
    • Major Categories
  3. Applying Transformation and Action
    • General
    • Mathematical and Statistical
    • Set Theory and Relational
    • Data-structure and IO

阅读更多

Pandas Cheat Sheet

Pandas作为python的库,包含易于使用的数据结构,是一个强大数据分析的工具

Pandas的主要数据结构有Series和DataFrame。Series是一种类似于一维数组的对象,它由一组数据以及一组与之相关的一组标签组成。DataFrame是一个表格型数据结构,它含有一组有序的列,每列可以是不同的值类型。

1
2
3
import pandas as pd
import numpy as np
from pandas import Series, DataFrame

阅读更多

SSH使用代理连接

使用ssh连接服务器,有时候我们需要使用代理来连接目标服务器。这时候有两个方法可以达到这个目的:

  1. 使用ssh的ProxyCommand选项
  2. 使用xshell代理

1. 配置ProxyCommand选项

ssh可以通过使用ProxyCommand设置代理

1
ssh root@192.168.33.10 -o "ProxyCommand=nc -X connect -x 127.0.0.1:10080 %h %p"

其中192.168.33.10是目的服务器ip,%h表示目标地址即192.168.33.10%p表示目标地址端口,默认22

阅读更多

PHP项目中安全风险与防范

在PHP开发中,由于编码bug或者配置不正确,如果被恶意利用往往会导致严重安全问题。根据OWASP Top 10 2017里面的10大安全风险,现归纳总结了PHP项目中几种常见安全风险,攻击场景和防范措施。

1. 注入-Injection

  • 一般指不受信任的数据被伪装成命令或者查询语句的一部分,发送至解析器后发生了执行的过程。
  • 攻击者的恶意数据能够欺骗解释器在未被授权的情况下执行非预期代码或者访问数据。
  • 常见注入类型有SQL、NoSQL、OS命令、XML等注入

案例场景

例1. 用户输入的数据直接用于SQL查询语句中

1
$sql = 'select * from news where id="' . $_GET['id']  . '"'

攻击方式:

1
http://example.com/news?id=" or 1='1

阅读更多

十种常见软件架构模式

原文地址:10 Common Software Architectural Patterns in a nutshell

是否曾经好奇过大型企业系统是如何设计的?在主要软件开发之前,我们需要选择合适的架构,为我们提供所需的功能和质量属性。因为,在我们应用架构到我们的设计中之前,我们应该了解不同的架构

Software Architectural Patterns

什么是架构模式?

架构模式是对给定上下文中软件架构中常见问题的通用、可重用的解决方案。架构模式类似于软件设计模式,但范围更广。

阅读更多