Ubuntu安装docker和docker-compose

未分类

百度百科:Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。

我的理解:docker就是轻量化的虚拟机,不需要你在每个虚拟机里安装操作系统,做到最简单的新建、运行、修改、删除;而且容器内服务直接调用本机的操作系统API,性能更高;可以用来实现快速虚拟化、快速部署、持续集成等等,是运维同学的神器。

本人不是搞运维的,主要做开发工作。为什么学习docker呢?主要是用来快速部署开发、测试环境,比如你开发、测试时要用redis、zookeeper、activemq、分布式存储等等,在个人电脑上该怎么玩儿?搭建N台虚拟机?不光内存不够,硬盘也不够啊,而且现在内存价格很贵,加不起。我之前开了6台虚拟机做zookeeper+redis集群,本机再开个eclipse、浏览器,8G内存见底,卡得不要不要的,而且虚拟机文件就有10G以上,苦也。这时候就需要docker这种轻量化的容器大显身手了。docker化后,开一台1G内存虚拟机,开个zookeeper+redis集群+activeMQ+fastdfs轻轻松松,具体应用可以看下一篇博文《docker超快速搭建redis集群、zookeeper集群、activeMQ、fastdfs分布式存储教程》。

测试平台系统: Ubuntu 16.04。如果想在Windows上玩儿Docker,可以去官方下载docker-toolbox或者先安装一台Ubuntu虚拟机。(ps: 其实docker-toolbox底层也是用的VirtualBox软件新建一台Linux虚拟机来实现的,因为当前docker只支持Linux。建议自建虚拟机安装docker,因为toolbox默认安装的虚拟机系统是tiny-core-linux,毕竟是一个超小型的非常用的linux,而且用的ISO镜像系统,无法安装软件。下面开始正题。)

1. 修改Ubuntu APT源为国内源

备份并编辑source.list

$ sudo cp /etc/apt/source.list /etc/apt/source.list.bak
$ sudo nano /etc/apt/source.list

注释掉光盘源及官方源

注释掉以下面开头的源(注释即在行首加#)

# deb cdrom:[Ubuntu-Server 16.04.3 LTS _Xenial Xerus
# deb http://cn.archive.ubuntu.com/ubuntu/
# deb http://security.ubuntu.com/ubuntu 

添加国内源

在文件末尾加入如下内容。注意:下面的xenial仅对应Ubuntu 16.04,其他版本的Ubuntu请自行更改为对应的版本名称

# 163 注释掉源码源
deb http://mirrors.163.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src http://mirrors.163.com/ubuntu/ xenial main restricted universe multiverse
# deb-src http://mirrors.163.com/ubuntu/ xenial-security main restricted universe multiverse
# deb-src http://mirrors.163.com/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src http://mirrors.163.com/ubuntu/ xenial-proposed main restricted universe multiverse
# deb-src http://mirrors.163.com/ubuntu/ xenial-backports main restricted universe multiverse

# aliyun 注释掉src源
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse 
# 源码
# deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse

2. 安装docker-ce

安装必要环境

$ sudo apt-get update
$ sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common

添加docker-ce仓库

两个安装源,二选一即可

使用阿里云docker-ce repository(版本基本同官方,速度快,推荐)

$ curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

使用官方docker-ce repository(版本最新,速度稍慢)

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

安装docker-ce

$ sudo apt-get -y update
$ sudo apt-get -y install docker-ce

# 添加当前用户到docker用户组
$ sudo usermod -aG docker `whoami`

# 检查docker
$ docker -v
Docker version 17.09.0-ce, build afdb6d4

修改镜像地址

$ sudo vim /etc/docker/daemon.json

# 输入如下内容:(此处采用docker中国官方镜像地址,若要采用aliyun等镜像仓库,请自行更改网址)
{
  "registry-mirrors": ["https://registry.docker-cn.com"]
}

# 重启docker
$ sudo /etc/init.d/docker restart

安装 docker-compose

$ sudo curl -L https://github.com/docker/compose/releases/download/1.17.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ docker-compose --version
docker-compose version 1.17.1, build 1719ceb

完。

Zabbix Ubuntu 环境下配置

我的 ubuntu 16.04版本 部署zabbix要安装apache、mysql和php 都是以默认安装

切换root用户 sudo -i

一、环境准备安装

sudo apt-get install apache2 
sudo apt-get install mysql-server               #需要设密码  但是我直接按Tab键没输入密码
sudo apt-get install php7.0 php7.0-gd libapache2-mod-php7.0 php7.0-mysql php7.0-bcmath php7.0-mbstring php7.0-xml

二、修改Php配置

sudo vim /etc/php/7.0/apache2/php.ini  #编辑配置文件修改里面的时区配置文件
date.timezone = Asia/Shanghai  # 时区改为亚洲上海
max_input_time = 300           # 每个PHP页面接收数据所需的最大时间
max_execution_time= 300        # 超时设置
post_max_size = 16M            # 设定 POST 数据所允许的最大大小
sudo /etc/init.d/apache2 restart   #重启服务

三、下载zabbix的安装包,安装

wget
http://repo.zabbix.com/zabbix/3.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.2-1+xenial_all.deb 
sudo dpkg -i zabbix-release_3.2-1+xenial_all.deb 
sudo apt-get update     #更新

四、安装zabbix服务端

sudo apt-get install zabbix-server-mysql

五、配置zabbix的数据库,创建zabbix数据库、zabbix用户,并对zabbix用户进行授权

#进入mysql
# 创建zabbix表,创建的表必须是utf8格式,否则会产生乱码
mysql> create database zabbix character set utf8;
# 创建mysql帐号:zabbix,密码:zabbix 
mysql> grant all on zabbix.* to  ‘zabbix’@’localhost’  identified by  ‘zabbix’;
mysql> q;
#退出mysql;
service mysql restart    #重启mysql     

# 拷贝zabbix的数据表到MySQL 
zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p zabbix
提示输入密码  zabbix

六、修改zabbix_server.conf配置文件,并重启zabbix-server服务

sudo vim /etc/zabbix/zabbix_server.conf

# 配置如下,这里的配置就是连接mysql的配置,按照当时mysql的设置进行修改即可 
DBHost=localhost 
DBName=zabbix 
DBUser=zabbix 
DBPassword=zabbix        
退出界面 zabbix_server.conf ;

sudo /etc/init.d/zabbix-server restart       #重启服务

七、安装zabbix的web界面

# 下载安装 
sudo apt-get install zabbix-frontend-php
# 拷贝zabbix到apache2的前端文件夹里 
sudo cp -r /usr/share/zabbix /var/www/html/zabbix

八、访问http://localhost/zabbix界面

看到界面下一步,下一步
到第三步
输入用户名 zabbix
输入密码 zabbix
到第四步按照 第 九 做

九、在需要监控的服务器或终端装客户端

sudo apt-get install zabbix-agent
sudo vim  /etc/zabbix/zabbix_agentd.conf
Server=127.0.0.1 
?6?7ListenPort = 10050 
ServerActive=127.0.0.1
sudo /etc/init.d/zabbix-agent restart       #重启服务

之后点完成

登录输入默认的用户名密码
用户名Admin
密码 zabbix

十、页面操作是英文版的 改成中文 版

页面的右上角有个 用户标志 点击
进入第二行

Language

到三角 选择Chinese(zh_CN)

Ubuntu下使用docker部署WordPress

上期docker使用教程

http://www.jianshu.com/p/46c7bed70f75

感觉中了docker的毒,简直神器,这次带来部署WordPress的教程

一、pull MySQL镜像

sudo docker pull mysql

二、运行MySQL

docker run -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql

三、pull WordPress镜像

sudo docker pull wordpress

四、运行WordPress

sudo docker run --name wordpress --link mysql:mysql -p 80:80 -d wordpress

五、浏览器访问

是不是很熟悉的界面

未分类

Ubuntu 14.04用apt在线/离线安装CDH5.1.2[Apache Hadoop 2.3.0]

1、CDH介绍

1.1、什么是CDH和CM?

  CDH一个对Apache Hadoop的集成环境的封装,可以使用Cloudera Manager进行自动化安装。
  Cloudera-Managerceql(本文中简称CM)是一个工具,CM能够管理一个大的Hadoop cluster并不是一只要下载tar files什么压缩并启动services这么简单。后续有非常多设定、监控等麻烦的事要处理,CM都能够做到,有些类似Casti。Cloudera Manager整合了一列的功能让系统管理者能更方便的维护Hadoop。
  

1.2、CDH的主要功能?

  • 管理
  • 监控
  • 诊断
  • 集成

1.3、CDH版本衍化

  Hadoop是一个开源项目,所以很多公司在这个基础进行商业化,Cloudera对hadoop做了相应的改变。
  Cloudera公司的发行版,我们将该版本称为CDH(Cloudera Distribution Hadoop)。截至目前为止,CDH共有5个版本,其中,前两个已经不再更新,最近的两个,分别是CDH4在Apache Hadoop 2.0.0版本基础上演化而来的),CDH5,它们每隔一段时间便会更新一次。
  Cloudera以Patch Level划分小版本,比如Patch Level为923.142表示在原生态Apache Hadoop 0.20.2基础上添加了1065个Patch(这些Patch是各个公司或者个人贡献的,在Hadoop jira上均有记录),其中923个是最后一个Beta版本添加的Patch,而142个是稳定版发行后新添加的Patch。由此可见,Patch Level越高,功能越完备且解决的Bug越多。
  Cloudera版本层次更加清晰,且它提供了适用于各种操作系统的Hadoop安装包,可直接使用apt-get或者yum命令进行安装,更加省事。

1.4、CDH5.1.2支持的主要组件简要介绍

  • HTTPFS
      1:Httpfs是Cloudera公司提供的一个Hadoop Hdfs的一个Http接口,通过WebHDFS REST API 可以对hdfs进行读写等访问
      2:与WebHDFS的区别是不需要客户端可以访问Hadoop集群的每一个节点,通过Httpfs可以访问放置在防火墙后面的Hadoop集群
      3:Httpfs是一个Web应用,部署在内嵌的Tomcat中

  • HBASE
      Hbase是Bigtable的开源山寨版本。是建立的Hdfs之上,提供高可靠性、高性能、列存储、可伸缩、实时读写的数据库系统。
      它介于Bosql和RDBMS之间,仅能通过主键(row key)和主键的Range来检索数据,仅支持单行事务(可通过Hive支持来实现多表Join等复杂操作)。主要用来存储非结构化和半结构化的松散数据。
      与Hadoop一样,Hbase目标主要依靠横向扩展,通过不断增加廉价的商用服务器,来增加计算和存储能力。

  • HDFS
      Hadoop分布式文件系统(HDFS)被设计成适合运行在通用硬件(commodity hardware)上的分布式文件系统。它和现有的分布式文件系统有很多共同点。但同时,它和其他的分布式文件系统的区别也是很明显的。HDFS是一个高度容错性的系统,适合部署在廉价的机器上。HDFS能提供高吞吐量的数据访问,非常适合大规模数据集上的应用。HDFS放宽了一部分POSIX约束,来实现流式读取文件系统数据的目的。HDFS在最开始是作为Apache Nutch搜索引擎项目的基础架构而开发的。HDFS是Apache Hadoop Core项目的一部分。

  • HIVE
      Hive 是一个基于 Hadoop 的开源数据仓库工具,用于存储和处理海量结构化数据。它把海量数据存储于 Hadoop 文件系统,而不是数据库,但提供了一套类数据库的数据存储和处理机制,并采用 HQL (类 SQL )语言对这些数据进行自动化管理和处理。我们可以把 Hive 中海量结构化数据看成一个个的表,而实际上这些数据是分布式存储在 HDFS 中的。 Hive 经过对语句进行解析和转换,最终生成一系列基于 hadoop 的 Map/Reduce 任务,通过执行这些任务完成数据处理。

  • HUE
      Hue是CDH专门的一套WEB管理器,它包括3个部分Hue Ui,Hue Server,Hue db。Hue提供所有的CDH组件的Shell界面的接口。你可以在Hue编写MR,查看修改HDFS的文件,管理Hive的元数据,运行Sqoop,编写Oozie工作流等大量工作。

  • Impala
      Impala对你存储在Apache Hadoop在HDFS,HBase的数据提供直接查询互动的SQL。除了像Hive使用相同的统一存储平台,Impala也使用相同的元数据,SQL语法(Hive SQL),ODBC驱动程序和用户界面(Hue Beeswax)。Impala还提供了一个熟悉的面向批量或实时查询和统一平台。

  • MapReduce
      MapReduce是一种编程模型,用于大规模数据集(大于1TB)的并行运算。概念”Map(映射)”和”Reduce(归约)”,和他们的主要思想,都是从函数式编程语言里借来的,还有从矢量编程语言里借来的特性。他极大地方便了编程人员在不会分布式并行编程的情况下,将自己的程序运行在分布式系统上。 当前的软件实现是指定一个Map(映射)函数,用来把一组键值对映射成一组新的键值对,指定并发的Reduce(归约)函数,用来保证所有映射的键值对中的每一个共享相同的键组。MapReduce更多运行于离线系统,而实时计算,可以使用Storm。关于Sotrm的使用和介绍,可以参考这篇文章《ubuntu12.04+storm0.9.2分布式集群的搭建》。

  • Oozie
      Oozie是Yahoo针对Apache Hadoop开发的一个开源工作流引擎。用于管理和协调运行在Hadoop平台上(包括:HDFS、Pig和MapReduce)的Jobs。Oozie是专为雅虎的全球大规模复杂工作流程和数据管道而设计。

  • Solr
      Solr是一个基于Lucene的Java搜索引擎服务器。Solr 提供了层面搜索、命中醒目显示并且支持多种输出格式(包括 XML/XSLT 和 JSON 格式)。它易于安装和配置,而且附带了一个基于 HTTP 的管理界面。Solr已经在众多大型的网站中使用,较为成熟和稳定。Solr 包装并扩展了 Lucene,所以Solr的基本上沿用了Lucene的相关术语。更重要的是,Solr 创建的索引与 Lucene 搜索引擎库完全兼容。通过对 Solr 进行适当的配置,某些情况下可能需要进行编码,Solr 可以阅读和使用构建到其他 Lucene 应用程序中的索引。此外,很多 Lucene 工具(如Nutch、 Luke)也可以使用 Solr 创建的索引。

  • Spark
      Spark是UC Berkeley AMP lab所开源的类Hadoop MapReduce的通用的并行计算框架,Spark基于map reduce算法实现的分布式计算,拥有Hadoop MapReduce所具有的优点;但不同于MapReduce的是Job中间输出结果可以保存在内存中,从而不再需要读写HDFS,因此Spark能更好地适用于数据挖掘与机器学习等需要迭代的map reduce的算法。
      Spark和Storm类似,都是基于内存的运行,不确定哪种方式在数据吞吐量上要具优势,不过Storm计算时间延迟要小。关于Sotrm的使用和介绍,可以参考这篇文章《ubuntu12.04+storm0.9.2分布式集群的搭建》。

  • Sqoop
      Sqoop中一大亮点就是可以通过hadoop的mapreduce把数据从关系型数据库中导入数据到HDFS。sqoop架构非常简单,其整合了Hive、Hbase和Oozie,通过map-reduce任务来传输数据,从而提供并发特性和容错。sqoop主要通过JDBC和关系数据库进行交互。理论上支持JDBC的database都可以使用sqoop和hdfs进行数据交互。
      

  • YARN
      YARN可以理解为是Hadoop MapReduceV2版本,YARN重构根本的思想是将 JobTracker 两个主要的功能分离成单独的组件,这两个功能是资源管理和任务调度 / 监控。新的资源管理器全局管理所有应用程序计算资源的分配,每一个应用的 ApplicationMaster 负责相应的调度和协调。一个应用程序无非是一个单独的传统的 MapReduce 任务或者是一个 DAG( 有向无环图 ) 任务。ResourceManager 和每一台机器的节点管理服务器能够管理用户在那台机器上的进程并能对计算进行组织。
      事实上,每一个应用的 ApplicationMaster 是一个详细的框架库,它结合从 ResourceManager 获得的资源和 NodeManager 协同工作来运行和监控任务。

  • Zookeeper
     Zookeeper 分布式服务框架是 Apache Hadoop 的一个子项目,它主要是用来解决分布式应用中经常遇到的一些数据管理问题,如:统一命名服务、状态同步服务、集群管理、分布式应用配置项的管理等。
      Zookeeper 作为一个分布式的服务框架,主要用来解决分布式集群中应用系统的一致性问题,它能提供基于类似于文件系统的目录节点树方式的数据存储,但是 Zookeeper 并不是用来专门存储数据的,它的作用主要是用来维护和监控你存储的数据的状态变化。通过监控这些数据状态的变化,从而可以达到基于数据的集群管理。

2、CDH的官网在哪里?

  http://www.cloudera.com/

3、CDH在哪里下载?

  由于CDH有多个版本,作者不建议单独下载安装,可以通过cloudera-manager-daemons、cloudera-manager-server、cloudera-manager-agent来安装,本文后面会有介绍。

4、如何安装

4.1、设置Host

  修改Host

root@m1:~# cat /etc/hosts 
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.10    m1.linuxidc.com   m1
192.168.1.11    m2.linuxidc.com   m2
192.168.1.12    s1.linuxidc.com   s1
192.168.1.13    s2.linuxidc.com   s2


# The following lines are desirable for IPv6 capable hosts
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

4.2、设置静态IP

  修改成静态IP地址

root@m1:~# vi /etc/network/interfaces
iface wlan0 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1
dns-nameservers 8.8.8.8

4.3、设置Host

  修改主机名称

root@m1:~# cat /etc/hostname 
m1.linuxidc.com

4.4、关闭防火墙

root@m1:~# ufw disable

4.5、安装JDK7,CDH5要求至少是Oracle JDK7

  添加 PPA repository 到系统

root@m1:~# add-apt-repository ppa:webupd8team/java
root@m1:~# apt-get update
root@m1:~# sudo apt-get upgrade
  • 1
  • 2
  • 3

  过程中会弹出个框,选择YES,因为要下载二进制包,所以可能会慢一些

root@m1:~# apt-get install oracle-java7-installer

  
  将Oracle 7 设置成默认版本

root@m1:~# apt-get install oracle-java7-set-default

   查看当前Java版本

root@m1:~# java -version 
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01) 
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

4.6、安装MySql最新版,CM的数据库我们用My Sql管理

  安装Mysql Server,后面在安装Cloudera Manager的时候会用到,如果你要使用PostGreSQL ,可以跳过这一步 (4.6-4.8)。
  

4.6.1、在主机上使用apt-get安装My Sql

  在主机上使用apt-get安装My Sql,安装过程中会有提示,一直接回车就可以 (4台机器都要执行)

root@m1:~# apt-get install mysql-server

4.6.2、修改MySql配置,方便CM使用

4.6.2.1、配置MySql的监听地址

  对MySQL的配置项进行修改,先备份,找到“bind-address = 127.0.0.1”这一行,然后注释掉,改成“bind-address = 0.0.0.0”

root@m1:~# cp /etc/mysql/my.cnf /etc/mysql/my.cnf.bak 
root@m1:~# vi /etc/mysql/my.cnf 
#bind-address = 127.0.0.1 
bind-address = 0.0.0.0

4.6.2.2、配置MySql的其他配置,为了CM使用

  MySql配置中,其中对于Cloudera的支持,可以参考官方描述

[client]
default-character-set=utf8
[mysqld]
transaction-isolation=READ-COMMITTED
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
character-set-server=utf8
key_buffer              = 16M
key_buffer_size         = 32M
max_allowed_packet      = 32M
thread_stack            = 256K
thread_cache_size       = 64
query_cache_limit       = 8M
query_cache_size        = 64M
query_cache_type        = 1

max_connections         = 550

# log-bin should be on a disk with enough free space
# NOTE: replace '/x/home/mysql/logs/binary' below with
#       an appropriate path for your system.
log-bin=/x/home/mysql/logs/binary/mysql_binary_log

# For MySQL version 5.1.8 or later. Comment out binlog_format for older versions.
binlog_format           = mixed

read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 8M

# InnoDB settings
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit  = 2
innodb_log_buffer_size          = 64M
innodb_buffer_pool_size         = 4G
innodb_thread_concurrency       = 8
innodb_flush_method             = O_DIRECT
innodb_log_file_size = 512M

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

4.7、创建后面在CM中会使用的数据库

root@m1:~# mysql -u root -p 
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or g. 
Your MySQL connection id is 42 
Server version: 5.5.38-0ubuntu0.14.04.1 (Ubuntu) 

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. 

Oracle is a registered trademark of Oracle Corporation and/or its 
affiliates. Other names may be trademarks of their respective 
owners. 

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. 

## Cloudera manager db user, database and grant
mysql> create user 'cmf'@'%' identified by 'xyz'; 
Query OK, 0 rows affected (0.00 sec) 

mysql> create database cmf  DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec) 

mysql> grant all privileges on cmf.* to 'cmf'@'%' identified by 'xyz'; 
Query OK, 0 rows affected (0.00 sec) 

## For activity monitor 
mysql> create user 'amon'@'%' identified by 'xyz'; 
Query OK, 0 rows affected (0.00 sec) 

mysql> create database amon  DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec) 

mysql> grant all privileges on amon.* to 'amon'@'%' identified by 'xyz'; 
Query OK, 0 rows affected (0.00 sec) 

## Hive Meta store 
mysql> create user 'hive'@'%' identified by 'xyz'; 
Query OK, 0 rows affected (0.00 sec) 

mysql> create database metastore  DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec) 

mysql> grant all privileges on metastore.* to 'hive'@'%' identified by 'xyz'; 
Query OK, 0 rows affected (0.00 sec) 

## Flush all changes 
mysql> FLUSH PRIVILEGES; 
Query OK, 0 rows affected (0.00 sec)

4.8、重启MySql,查看3306端口,并安装MySql、Java的支持

root@m1:~# service mysql restart
root@m1:~# netstat -tulpn | grep :3306 
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2207/mysqld
root@m1:~# apt-get install libmysql-java 
Reading package lists... Done 
Building dependency tree 
Reading state information... Done 
Suggested packages: 
liblog4j1.2-java libcommons-logging-java 
The following NEW packages will be installed: 
libmysql-java 
0 upgraded, 1 newly installed, 0 to remove and 4 not upgraded. 
Need to get 894 kB of archives. 
After this operation, 1,060 kB of additional disk space will be used. 
Get:1 http://mirrors.sohu.com/ubuntu/ trusty/universe libmysql-java all 5.1.28-1 [894 kB] 
Fetched 894 kB in 1s (718 kB/s) 
Selecting previously unselected package libmysql-java. 
(Reading database ... 96338 files and directories currently installed.) 
Preparing to unpack .../libmysql-java_5.1.28-1_all.deb ... 
Unpacking libmysql-java (5.1.28-1) ... 
Setting up libmysql-java (5.1.28-1) ... 
root@m1:~#

4.9、安装Cloudera Manager组件

4.9.1、将Ubuntu 14.04暂时伪造成Ubuntu12.04

  Ubuntu 14.04暂时伪造成Ubuntu12.04,因为在写本文时CM现在还不支持14.04这个版本,CDH以后的版本应该会支持吧(4台机器都要执行)
  备份文件:

root@m1:~# cp /etc/lsb-release /etc/lsb-release.bak 

  使用VI编译文件,暂时修改成Ubuntu12.04 LTS的信息:

root@m1:~# vi /etc/lsb-release 
DISTRIB_ID=Ubuntu 
DISTRIB_RELEASE=12.04 
DISTRIB_CODENAME=precise 
DISTRIB_DESCRIPTION="Ubuntu 12.04.3 LTS"

4.9.2、升级Ubuntu的utils包,CM所必需要

  在所有机器上安装debian的包,升级utils,执行以下命令:(4台机器都要执行)

root@m1:~# wget http://ftp.cn.debian.com/debian/pool/main/f/fuse/fuse-utils_2.9.0-2+deb7u1_all.deb
root@m1:~# dpkg -i fuse-utils_2.9.0-2+deb7u1_all.deb

4.9.3、将CDH5的软件源添加到Apt中

root@m1:~# curl "http://archive.cloudera.com/cm5/ubuntu/precise/amd64/cm/cloudera.list" -o /etc/apt/sources.list.d/cloudera_precise.list
root@m1:~# curl -s http://archive.cloudera.com/cdh5/ubuntu/precise/amd64/cdh/archive.key | sudo apt-key add -
root@m1:~# apt-get update

4.9.4、安装Cloudera Manager

  安装Cloudera Manager(4台机器都要执行)

root@m1:~# apt-get install cloudera-manager-daemons cloudera-manager-server

4.9.5、修改Cloudera-Manager-Server的配置文件db.properties,设置MySql连接

  修改Cloudera-Manager-Server的配置文件db.properties,设置刚才我们在(4.7)Mysql中创建的cmf数据库、用户名、密码(4台机器都要执行)

root@m1:~# vi /etc/cloudera-scm-server/db.properties 
com.cloudera.cmf.db.type=mysql
com.cloudera.cmf.db.host=m1.linuxidc.com
com.cloudera.cmf.db.name=cmf
com.cloudera.cmf.db.user=cmf
com.cloudera.cmf.db.password=xyz

4.9.6、安装ntp ,CM agents需要用到”ntpdc”

  安装ntp ,CM agents需要用到”ntpdc”(4台机器都要执行)

root@m1:~# apt-get install ntp 
Reading package lists... Done 
Building dependency tree 
Reading state information... Done 
The following extra packages will be installed: 
libopts25 
Suggested packages: 
ntp-doc 
The following NEW packages will be installed: 
libopts25 ntp 
0 upgraded, 2 newly installed, 0 to remove and 4 not upgraded. 
Need to get 666 kB of archives. 
After this operation, 1,668 kB of additional disk space will be used. 
Do you want to continue? [Y/n] y 
Get:1 http://mirrors.sohu.com/ubuntu/ trusty/main libopts25 amd64 1:5.18-2ubuntu2 [55.3 kB] 
Get:2 http://mirrors.sohu.com/ubuntu/ trusty/main ntp amd64 1:4.2.6.p5+dfsg-3ubuntu2 [611 kB] 
Fetched 666 kB in 1s (537 kB/s) 
Selecting previously unselected package libopts25:amd64. 
(Reading database ... 95843 files and directories currently installed.) 
Preparing to unpack .../libopts25_1%3a5.18-2ubuntu2_amd64.deb ... 
Unpacking libopts25:amd64 (1:5.18-2ubuntu2) ... 
Selecting previously unselected package ntp. 
Preparing to unpack .../ntp_1%3a4.2.6.p5+dfsg-3ubuntu2_amd64.deb ... 
Unpacking ntp (1:4.2.6.p5+dfsg-3ubuntu2) ... 
Processing triggers for man-db (2.6.7.1-1) ... 
Processing triggers for ureadahead (0.100.0-16) ... 
Setting up libopts25:amd64 (1:5.18-2ubuntu2) ... 
Setting up ntp (1:4.2.6.p5+dfsg-3ubuntu2) ... 
* Starting NTP server ntpd [ OK ] 
Processing triggers for libc-bin (2.19-0ubuntu6.1) ... 
Processing triggers for ureadahead (0.100.0-16) ... 
root@m1:~#

4.9.7、重启Cloudera Manager Server

  启动Cloudera manager (4台机器都要执行)

root@m1:~# service cloudera-scm-server start 
Starting cloudera-scm-server: * cloudera-scm-server started 
root@m1:~#
  • 1
  • 2
  • 3

  查看Cloudera manager的启动日志,如果能够看到下面的类似信息,说明启动正确,tailf -100 /var/log/cloudera-scm-server/cloudera-scm-server.log或者/var/log/cloudera-scm-server/cloudera-scm-server.out,如果看不到类似下面的信息,那么也可以看到哪里出了问题,大多数都是和数据库的配置有关系。

2014-08-26 23:07:52,643 INFO [JvmPauseMonitor:debug.JvmPauseMonitor@236] Detected pause in JVM or host machine (e.g. a stop the world GC, or JVM not scheduled): paused approximately 1182ms: GC pool 'Copy' had collection(s): count=1 time=1641ms 
2014-08-26 23:07:52,644 INFO [JvmPauseMonitor:debug.JvmPauseMonitor@236] Detected pause in JVM or host machine (e.g. a stop the world GC, or JVM not scheduled): paused approximately 1634ms: GC pool 'Copy' had collection(s): count=1 time=1641ms 
2014-08-26 23:07:52,696 INFO [WebServerImpl:servlet.DispatcherServlet@339] FrameworkServlet 'Spring MVC Dispatcher Servlet': initialization completed in 18068 ms 
2014-08-26 23:07:52,793 INFO [WebServerImpl:cmon.JobDetailGatekeeper@127] ActivityMonitor configured to allow job details for all jobs. 
2014-08-26 23:07:53,407 INFO [SearchRepositoryManager-0:components.SearchRepositoryManager@399] Initializing SearchTemplateManager:2014-08-27T06:07:53.407Z 
2014-08-26 23:07:53,730 INFO [SearchRepositoryManager-0:components.SearchRepositoryManager@403] Generating entities:2014-08-27T06:07:53.730Z 
2014-08-26 23:07:53,821 INFO [SearchRepositoryManager-0:components.SearchRepositoryManager@407] Num entities:112 
2014-08-26 23:07:53,822 INFO [SearchRepositoryManager-0:components.SearchRepositoryManager@409] Generating documents:2014-08-27T06:07:53.822Z 
2014-08-26 23:07:53,891 INFO [SearchRepositoryManager-0:components.SearchRepositoryManager@411] Num docs:124 
2014-08-26 23:07:53,892 INFO [SearchRepositoryManager-0:components.SearchRepositoryManager@352] Constructing repo:2014-08-27T06:07:53.892Z 
2014-08-26 23:07:53,979 INFO [WebServerImpl:mortbay.log@67] jetty-6.1.26.cloudera.2 
2014-08-26 23:07:54,008 INFO [WebServerImpl:mortbay.log@67] Started [email protected]:7180 
2014-08-26 23:07:54,009 INFO [WebServerImpl:cmf.WebServerImpl@292] Started Jetty server. 
2014-08-26 23:07:55,276 INFO [SearchRepositoryManager-0:components.SearchRepositoryManager@354] Finished constructing repo:2014-08-27T06:07:55.276Z

4.10、通过Web方式继续安装

4.10.1、创建update-alternatives工具在/usr/sbin/下创建软链

  创建update-alternatives工具在/usr/sbin/下创建软链(在4台机器上一起执行)(4台机器都要执行)

root@m1:~# sudo ln -s /usr/bin/update-alternatives /usr/sbin/update-alternatives
  • 1

4.10.2、打开浏览器,输入 http://m1.linuxidc.com:7180/ 开始安装

  使用浏览器打开能够看到登录页面,那么恭喜你成功了。 http://m1.linuxidc.com:7180/(帐号和密码都是admin)

未分类

4.10.3、选择安装的CDH版本

  我们来安装Cloudera Express,之前官方有说这个版本有50个节点的限制,在CDH5.1.0版本也有看到,在写本文记录时的5.1.2版本不知道为什么我在安装的时候并未看到。
  
未分类

4.10.4、为CDH集群添加主机

  选择指定的CDH集群,可以添加多台机器,也可以使用IP匹配,输入完机器名称后,点search按钮,我输入的内容为”m1.linuxidc.com”
  
未分类

  CDH会根据你给出的内容,搜索到机器
  
未分类

4.10.5、选择CDH的安装方式

  选择存储方式,我们使用Parcel方式安装。系统会自动下载Parcel
  
未分类
  
  是否需要加密,如果你不考虑这些,可以不用选择这个复选框
  
未分类

  
  提供SSH登录凭据,这里建议使用root帐号,避免一些新同学,对其他帐号的权限设置不完整,导致后面安装出现错误。如何设置4台机器之前SSH免密码登录,就不在这里介绍了,如果不会,可以去搜索下。在这之前4台机器请配置好SSH免密码登录。
 
未分类
  
  安装过程中的状态,会下载CDH使用的包,可能会慢一些,要有耐心~~~~
  
未分类
  
  如果在安装过程中出现了以下错误“ImportError: No module named _io”,或者如下图中的提示,不用担心,这是一个已知问题。这是因为CDH5使用的Python版本问题。执行完下面的脚本后,点击重试就可以顺利的完成安装了。如果出现打不开CM Agent的log日志提示,那很可能是你的Host配置有问题,请参考本文最初写的Host配置。

root@m1:~# mv /usr/lib/cmf/agent/build/env/bin/python /usr/lib/cmf/agent/build/env/bin/python.bak
root@m1:~# cp /usr/bin/python2.7 /usr/lib/cmf/agent/build/env/bin/python

  安装完成了

未分类 

4.10.6、离线方式安装CDH的Parcel

  继续安装选定 Parcel

  如果你想要提高速度,可以按以下方法离线安装

    (1)、使用迅雷到http://archive.cloudera.com/cdh5/parcels/5.1.2/目录,下载CDH-5.1.2-1.cdh5.1.2.p0.3-precise.parcel和mainfest.json文件

    (2)、上传到/opt/cloudera/parcel-repo目录中,同时创建一个CDH-5.1.2-1.cdh5.1.2.p0.3-precise.parcel.sha文件,内容为”a492e4b6dece2850f0a37f2bf613ecb2980dfd37”,这个值可以在下载目录中的manifest.json文件中找到。然后看相对应的json->parcelName同一级的hash值。

    (3)、下载http://archive.cloudera.com/accumulo-c5/parcels/1.6.0.51/ACCUMULO-1.6.0-1.cdh5.1.0.p0.51-precise.parcel、http://archive.cloudera.com/sqoop-connectors/parcels/1.2/SQOOP_NETEZZA_CONNECTOR-1.2c5-precise.parcel、http://archive.cloudera.com/sqoop-connectors/parcels/1.2/SQOOP_TERADATA_CONNECTOR-1.2c5-precise.parcel

    (4)、参考步骤2,创建相应的.sha文件,.sha文件中的内容如下:

root@m1:/opt/cloudera/parcel-repo# echo "a719f373833a63108c616afb034d97c4e11405d5" >> ACCUMULO-1.6.0-1.cdh5.1.0.p0.51-precise.parcel.sha
root@m1:/opt/cloudera/parcel-repo# echo "a492e4b6dece2850f0a37f2bf613ecb2980dfd37"  >> CDH-5.1.2-1.cdh5.1.2.p0.3-precise.parcel.sha
root@m1:/opt/cloudera/parcel-repo# echo "48bedfff38f742d32541854e24b3310992616027" >> SQOOP_NETEZZA_CONNECTOR-1.2c5-precise.parcel.sha
root@m1:/opt/cloudera/parcel-repo# echo "76566b4797bd061d01cf25b36b21b26927ada9a4" >> SQOOP_TERADATA_CONNECTOR-1.2c5-precise.parcel.sha

    (5)、设置文件的使用权限

root@m1:/opt/cloudera/parcel-repo# chmod 777 -R .
root@m1:/opt/cloudera/parcel-repo# chown cloudera-scm:cloudera-scm ./*

    (6)、查看下载后的文件列表

root@m1:/opt/cloudera/parcel-repo# ll 
total 1709280 
drwxrwxrwx 2 cloudera-scm cloudera-scm 4096 Sep 1 01:16 ./ 
drwxr-xr-x 6 root root 4096 Sep 1 01:51 ../ 
-rwxrwxrwx 1 cloudera-scm cloudera-scm 13204338 Aug 31 21:37 ACCUMULO-1.6.0-1.cdh5.1.0.p0.51-precise.parcel* 
-rwxrwxrwx 1 cloudera-scm cloudera-scm 41 Sep 1 01:15 ACCUMULO-1.6.0-1.cdh5.1.0.p0.51-precise.parcel.sha* 
-rwxrwxrwx 1 cloudera-scm cloudera-scm 1727519860 Sep 1 00:27 CDH-5.1.2-1.cdh5.1.2.p0.3-precise.parcel* 
-rwxrwxrwx 1 cloudera-scm cloudera-scm 41 Sep 1 01:15 CDH-5.1.2-1.cdh5.1.2.p0.3-precise.parcel.sha* 
-rwxrwxrwx 1 cloudera-scm cloudera-scm 41602 Sep 1 01:13 SQOOP_NETEZZA_CONNECTOR-1.2c5-precise.parcel* 
-rwxrwxrwx 1 cloudera-scm cloudera-scm 41 Sep 1 01:16 SQOOP_NETEZZA_CONNECTOR-1.2c5-precise.parcel.sha* 
-rwxrwxrwx 1 cloudera-scm cloudera-scm 9499051 Sep 1 01:13 SQOOP_TERADATA_CONNECTOR-1.2c5-precise.parcel* 
-rwxrwxrwx 1 cloudera-scm cloudera-scm 41 Sep 1 01:16 SQOOP_TERADATA_CONNECTOR-1.2c5-precise.parcel.sha*

未分类
   
  主机正确性检查,和当前m1.linuxidc.com的CDH5.12组件版本汇总。
  
未分类

未分类    

4.10.7、在m1.linuxidc.com上安装ZooKeeper服务

  选择要安装的集群服务,我们来安装ZooKeeper。如下图选择

未分类
  
  自定义角色分配

未分类
  
  数据库设置,我们输入之前在MySql中(4.7)创建的Activity Monitor使用的数据库amon以及用户名、密码,点击测试链接,可以看到成功信息。
  
未分类
  
  审核更改,如果你没有邮件要配置,可以什么都不用输入

未分类
  
  
  升级完成,并且成功启动ZooKeeper、CM Service服务。

未分类  

4.10.8、初始化完成,进入CM主页

  升级完成,就可以进入主页

未分类
  
  查看m1.linuxidc.com的运行状态

未分类

4.10.9、恢复Ubuntu 14.04版本信息

  最后我们恢复ubuntu 14.04版本信息

root@cm1:~# rm /etc/lsb-release /etc/lsb-release.bak
root@cm1:~# mv /etc/lsb-release.bak  /etc/lsb-release
  • 1
  • 2

4.11、通过CM管理多个集群

4.11.1、添加1个新的集群,机器名称为m2.linuxidc.com

  有的时候,因为业务原因,不同的服务我们要使用不同的集群,便于管理和维护,下面我们再使用CM来测试创建一个新集群Cluster 2
  添加其他主机,我们测试将m2.linuxidc.com也做为一个新集群添加到CM中。点击CM主页右上角的添加集群,会重复看到(参考4.10.4章节)的页面
  
未分类

未分类

  再继续安装,可以参考(4.10.5章节-4.10.7章节)的页面重复操作,下面只给出将m2.linuxidc.com加入到集群的安装过程中部分截图。
  m2.linuxidc.com机器上要有cloudera-manager-server、cloudera-manager-daemons、cloudera-manager-agent(这个可以不用安装,但机器上要有包)。cloudera-manager-server、cloudera-manager-daemons的安装,可以参考4.9.4章节,配置可以参考4.9.5章节,服务是启动状态。
  
未分类

未分类

未分类

4.11.2、完成安装,验证m2.linuxidc.com是否成功地添加到集群Cluster 2

未分类

4.12、向1个集群添加1台新主机

4.12.1、开始添加,输入要添加的机器名称s1.linuxidc.com

未分类
  
  选择存储库,为了保持统一,建议使用与当前CM一样的版本,然后会继续走4.10.5的步骤
  
未分类
  
  再继续安装,可以参考(4.10.5章节-4.10.7章节)的页面重复操作,下面只给出将s1.linuxidc.com加入到集群的安装过程中部分截图。
  m2.linuxidc.com机器上要有cloudera-manager-server、cloudera-manager-daemons、cloudera-manager-agent(这个可以不用安装,但机器上要有包)。
  cloudera-manager-server、cloudera-manager-daemons的安装,可以参考4.9.4章节,配置参考4.9.5章节。cloudera-manager-server的服务要在启动状态。

未分类

未分类

4.12.2、选择主机模

未分类

未分类

未分类

4.12.3、完成将s1.linuxidc.com添加到集群

未分类

4.12.4、验证s1.linuxidc.com是否成功地添加到集群Cluster 1

未分类

未分类

  到此为主,在Ubuntu 14.04下使用apt-get方式,安装CDH5.12已经成功。并且支持中文,后面有什么服务或者机器要添加的,可以自己来做了。

5、FAQ

5.1、过程中如果出现”Incorrect string value: ‘x“的提示

  是和数据库的编码有关,在mysql中执行以下语句:

alter table CLIENT_CONFIGS convert to character set utf8;
alter table CLUSTERS convert to character set utf8;
alter table CLUSTERS_AUD convert to character set utf8;
alter table CLUSTER_ACTIVATED_RELEASES convert to character set utf8;
alter table CLUSTER_ACTIVATED_RELEASES_AUD convert to character set utf8;
alter table CLUSTER_MANAGED_RELEASES convert to character set utf8;
alter table CLUSTER_UNDISTRIBUTED_RELEASES convert to character set utf8;
alter table CM_PEERS convert to character set utf8;
alter table CM_VERSION convert to character set utf8;
alter table COMMANDS convert to character set utf8;
alter table COMMAND_SCHEDULES convert to character set utf8;
alter table CONFIGS convert to character set utf8;
alter table CONFIGS_AUD convert to character set utf8;
alter table CONFIG_CONTAINERS convert to character set utf8;
alter table CREDENTIALS convert to character set utf8;
alter table GLOBAL_SETTINGS convert to character set utf8;
alter table HOSTS convert to character set utf8;
alter table HOSTS_AUD convert to character set utf8;
alter table HOST_TEMPLATES convert to character set utf8;
alter table HOST_TEMPLATE_TO_ROLE_CONF_GRP convert to character set utf8;
alter table METRICS convert to character set utf8;
alter table PARCELS convert to character set utf8;
alter table PARCEL_COMPONENTS convert to character set utf8;
alter table PROCESSES convert to character set utf8;
alter table PROCESS_ACTIVE_RELEASES convert to character set utf8;
alter table RELEASES convert to character set utf8;
alter table RELEASES_AUD convert to character set utf8;
alter table REVISIONS convert to character set utf8;
alter table ROLES convert to character set utf8;
alter table ROLES_AUD convert to character set utf8;
alter table ROLE_CONFIG_GROUPS convert to character set utf8;
alter table ROLE_CONFIG_GROUPS_AUD convert to character set utf8;
alter table ROLE_STALENESS_STATUS convert to character set utf8;
alter table SCHEMA_VERSION convert to character set utf8;
alter table SERVICES convert to character set utf8;
alter table SERVICES_AUD convert to character set utf8;
alter table SNAPSHOT_POLICIES convert to character set utf8;
alter table USERS convert to character set utf8;
alter table USER_ROLES convert to character set utf8;
alter table USER_SETTINGS convert to character set utf8;

apt方式安装LNMP环境教程(ubuntu17.10|PHP7.1)

1. 简要说明

安装环境是阿里云ubuntu17.10,这个教程里我把域名都写成hostname.com, ip都写成192.168.1.1,你可以根据自己的需要更换。另外如果不是root账户的话,最好切换到root账户。

sudo su

2. 安装MYSQL 5.7

我们使用apt-get方式安装MySQL:

apt-get -y install mysql-server mysql-client

安装的时候会要求你输入MySQL的root密码,建议此时输入,比较方便。
输入以下命令,让MySQL更安全:

mysql_secure_installation

我们将会被问这些问题:

root@root:~# mysql_secure_installationSecuring the MySQL server deployment.Enter password for user root: 这里输入MySQL密码VALIDATE PASSWORD PLUGIN can be used to test passwordsand improve security. It checks the strength of passwordand allows the users to set only those passwords which aresecure enough. Would you like to setup VALIDATE PASSWORD plugin?Press y|Y for Yes, any other key for No: 想要让MySQL验证密码强度可以填Y,但个人建议N。otherwise.Using existing password for root.Change the password for root ? ((Press y|Y for Yes, any other key for No) : 建议NoBy default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them. This is intended only fortesting, and to make the installation go a bit smoother.You should remove them before moving into a productionenvironment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : 这个要填YSuccess.Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess atthe root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : 是否允许root远程登录?想要更安全选Y,但我建议选N,可以避免很多问题。Success.By default, MySQL comes with a database named 'test' thatanyone can access. This is also intended only for testing,and should be removed before moving into a productionenvironment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : 这个选Y,移除没用的test表。- Dropping test database...Success.- Removing privileges on test database...Success.Reloading the privilege tables will ensure that all changesmade so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : 选YSuccess.All done!

MySQL就装好了。

3. 安装Nginx

apt-get install nginx
apt-get install nginx

然后你打开你的IP地址或域名,就能看见nginx默认页面了。

未分类

nginx默认的路径在/var/www/html

4. 安装PHP7.1

我们搭建wordpress博客主要要用到php-fpm组件,我们apt-get它,ubuntu会自动安装必要的php程序。

apt-get -y install php7.1-fpm

5. 配置nginx

编辑nginx的默认站点配置文件

vim /etc/nginx/sites-available/default
server { listen 80 default_server; listen [::]:80 default_server; # SSL configuration # # listen 443 ssl default_server; # listen [::]:443 ssl default_server; # # Note: You should disable gzip for SSL traffic. # See: https://bugs.debian.org/773332 # # Read up on ssl_ciphers to ensure a secure configuration. # See: https://bugs.debian.org/765782 # # Self signed certs generated by the ssl-cert package # Don't use them in a production server! # # include snippets/snakeoil.conf;root /var/www/html;# Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html;server_name _;location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; }# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ .php$ { include snippets/fastcgi-php.conf; # With php7.0-cgi alone: fastcgi_pass 127.0.0.1:9000; # With php7.0-fpm: # fastcgi_pass unix:/run/php/php7.0-fpm.sock; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /.ht { deny all; }}

另外需要注意,我们是要安装wordpress的,所以又一个index的地方(# Add index.php to the list),在index后面要增加index.php

PHP-FPM默认是通过socket连接的,我们要改成用TCP链接。

vim /etc/php/7.0/fpm/pool.d/www.conf

修改listen:

;listen = /var/run/php5-fpm.sock
listen = 127.0.0.1:9000

像上面那样修改后,重启nginx:

service nginx restart

然后打开:

vim /etc/php/7.1/fpm/php.ini

设置cgi.fix_pathinfo=0

; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting; of zero causes PHP to behave as before. Default is 1. You should fix your scripts; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.; http://php.net/cgi.fix-pathinfocgi.fix_pathinfo=0

reload php-fpm:

service php7.0-fpm reload

新建一个文件:

vim /var/www/html/info.php

写入

<?php
phpinfo();
?>

然后我们可以打开浏览器输入域名,例如 192.168.1.1/info.php(你的显示应该是php7.1)

未分类

你可以看到PHP已经工作了,包括现在支持的一些模块。

6. 使PHP7.1支持MySQL

我们可以先看一下有哪些PHP7.1的模块:

apt-cache search php7.1

可以选一些你喜欢的模块安装(以下是我自己安装的):

apt-get -y install php7.1-mysql php7.1-gd php7.1-curl php7.1-intl php7.1-mcrypt

reload PHP-FPM:

service php7.1-fpm reload

刷新一下192.168.1.1/info.php,看一下自己的模块是否都安装好了。

这样就安装配置好了,接下来就可以在/var/www/html里上传wordpress文件了。

Ubuntu 16.04 配置 Let’s Encrypt 实现站点 SSL

Let’s Encrypt 的服务相信很多人都知道了,我个人认为这是最好的免费 SSL 服务。下面内容即使如何在自己的网站上使用 Let’s Encrypt 实现 SSL.

前提条件

  • 自己拥有一个域名,备案了的域名最好。

  • Ubuntu 16.04 的服务器,你可以到腾讯云或者阿里云购买这样的云主机。

  • 将域名自己解析到你的 Ubuntu 16.04 的云主机 ip;注意如果你的域名没备案,在购买主机的时候,推荐大家购买腾讯云或者阿里云境外的主机。

1. 安装 Certbot

Certbot 其实就是维护 Let’s Encrypt 的 Package,在 Ubuntu 16.04 上,我们可以这样安装:

首先安装 Nginx:

sudo apt-get install nginx

以上过程,等待安装完毕就好。

然后添加 package repository

sudo add-apt-repository ppa:certbot/certbot

这个过程中,等待验证完毕,按下 ENTER 就好。然后更新 apt 源数据:

sudo apt-get update

最后,安装 Certbot 的 Nginx package:

sudo apt-get install python-certbot-nginx

2. 配置 Nginx

安装完 Nginx 和 Certbot 之后,需要简单配置 Nginx 以便于 Let’s Encrypt 能起作用:

sudo vi /etc/nginx/sites-available/default

使用 vi 编辑器打开 /etc/nginx/sites-available/default,可以直接删除里面的所有内容,然后再添加下面的配置:

server {
    listen 80;
    listen [::]:80;
    server_name your-domain.com www.your-domain.com;
}

注意这里的 your-domain.com 换成你自己的域名。

保存退出之后,执行以下命令来检测 Nginx 的配置文件是否有错:

sudo nginx -t

如果出现类似 syntax ok 这样的语句,就说明 Nginx 的配置文件没有问题。之后就是重新加载 Nginx 的配置文件了:

sudo service nginx reload

3. 签发 SSL 证书

前面的两大步配置完成,就可以使用 Let’s Encrypt 签发 SSL 证书了:

sudo certbot --nginx -d your-domian.com -d www.your-domain.com

注意这里的 your-domain.com 换成你自己的域名。

如果你第一次运行 certbot 命令的话,你需要在弹出的窗口输入你的邮箱地址还有需要接受 Let’s Encrypt 的协议,这样之后,你大概会看到下面的文字:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):

在上面这里选择 1 或者 2,我推荐大家直接选择 2,因为这个会直接将你的 nginx 文件配置好并且是会将 http 跳转到 https 的。

选择完毕之后,等待 SSL 生成完毕,就会有类似这样的输出:

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/your-domain.com/fullchain.pem. Your cert will
   expire on 2017-12-29. To obtain a new or tweaked version of this
   certificate in the future, simply run certbot again with the
   "certonly" option. To non-interactively renew *all* of your
   certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

然后在上面的文字中,这个 /etc/letsencrypt/live/your-domain.com/fullchain.pem 路径很重要,就是你的 SSL 证书路径。

其实到这里,访问 your-domain.com 应该就可以看到 https 的效果了。

4. 自动更新证书

因为 Let’s Encrypt 签发的 SSL 证书有效期只有 90 天,所有在过期之前,我们需要自动更新 SSL 证书,而如果你使用最新的 certbot 的话,Let’s Encrypt 会帮你添加自动更新的脚本到 /etc/cron.d 里,你只需要去检测一下这个命令是否生效就OK!

sudo certbot renew --dry-run

如果这个命令你没看到什么 error 的话,那就是没什么问题了。

5. 总结

本文主要是介绍了在 Ubuntu 16.04 的云服务器上,使用 Nginx 作为服务器软件情况下,如何配置 Let’s Encrypt 的 SSL 证书,使得网站得以支持 https 的过程。内容很浅,但是我觉得还是挺有用的。

ubuntu安装nodejs并升级到最新版本

ubuntu版本信息如下:

Linux muir 4.13.0-16-generic #19-Ubuntu SMP Wed Oct 11 18:35:14 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

nodejs最新版本为:8.8.1

一、安装之前首先update

sudo apt-get update
sudo apt-get upgrade

二、安装nodejs

sudo apt-get install nodejs-dev
sudo apt-get install npm

三、查看版本

node -v
npm -v

可以看到版本是6.xxx.xx

四、升级node版本

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

未分类

再看版本号:

未分类

Ubuntu配置和修改IP地址

配置Ubuntu的IP地址

鉴于目前的工作中需要经常配置Ubuntu的IP地址,所以百度一番之后发现了一个比较不错的文章,故此抄袭之。

第一步

sudo vi /etc/network/interfaces

auto eth0                  #设置自动启动eth0接口
iface eth0 inet static     #配置静态IP
address 192.168.1.100      #IP地址
netmask 255.255.255.0      #子网掩码
gateway 192.168.1.1        #默认网关

第二步

很多人都会第一步,但是会经常忽略第二部,我经常也会配置nameserver在resolve.conf文件中。

配置这个文件有什么问题呢?如果你一直不关机的话是没有问题。但是能一直不关么?显然不能。

sudo vi /etc/resolvconf/resolv.conf.d/base
# 在这个文件中添加以下内容,然后保存退出
nameserver 8.8.8.8
nameserver 114.114.114.114

第三步

重启网络

sudo /etc/init.d/networking restart

禁用 Ubuntu 自动挂载功能

打开终端

禁止自动挂载:

$ gsettings set org.gnome.desktop.media-handling automount false

禁止自动挂载并打开

$ gsettings set org.gnome.desktop.media-handling automount-open false

允许自动挂载

$ gsettings set org.gnome.desktop.media-handlingautomount true

允许自动挂载并打开

$ gsettings set org.gnome.desktop.media-handling automount-open true

ubuntu开启ssh服务

安装openssh-server

sudo apt-get update
sudo apt-get install openssh-server

查看ssh服务

sudo ps -e|grep ssh #是否存在sshd进程

如果没有sshd进程,执行:

sudo service ssh start

查看ubuntu IP

ifconfig

使用ssh客户端工具连接

ssh 你的ip