月度归档:2017年05月

CloudStack 4.5安装配置完成之全局重点配置

expunge.delay 决定在卷被销毁之前卷存在多长时间,以秒计算。
expunge.interval 决定回收检查运行频率。
management.network.cidr 修改实例以及管理列所在段 即HTTP服务器所在网段CIDR.192.168.121.0/24
secstorage.allowed.internal.sites 修改实例以及管理列所在段 即HTTP服务器所在网段CIDR.
system.vm.use.local.storage 修改为true表示允许使用本地存储
enable.dynamic.scale.vm 修改为true表示动态主机
mem.overprovisioning.factor = 2 用来进行内存过度提供计算。(内存超载2倍,如果HOST内存足够大,可忽略)
Dynamically Scalable 模板里面 勾选上
cpu.overprovisioning.factor 用来进行cpu过度提供计算。可利用的cpu是实际cpu容量与cpu过度提供因子的乘积。
max.account.volumes 存储卷可以为一个帐户创建默认的最大数量
job.expire.minutes 给快照请求等待队列的长度设置一个最大值,如果达到限制,返回报错
router.template.kvm 更改系统模板后,修改全局设置中的系统vm名称 KVM64bitTemplate
concurrent.snapshots.threshold.perhost 这个值代表了在同一时刻有多少快照工作在hypervisor主机上执行

Windows下MySQL(MariaDB)数据库破解各版本root密码

方法一:(适用于MySQL5.0/5.1/5.2/5.5)

开始-运行-cmd 输入以下命令停止mysql,或者 开始-运行-services.msc 找到mysql服务并停止。

D:\MySQL\MySQL Server 5.2\bin>Net stop mysql

到mysql的具体安装路径BIN目录下执行:

D:\MySQL\MySQL Server 5.2\bin>mysqld-nt --skip-grant-tables
或
D:\MySQL\MySQL Server 5.2\bin>mysqld --skip-grant-tables

当前窗口将会停止。

重开cmd命令窗口到mysql的bin目录直接运行mysql

D:\MySQL\MySQL Server 5.2\bin>mysql
D:\MySQL\MySQL Server 5.2\bin>use mysql;
D:\MySQL\MySQL Server 5.2\bin>update user set password=password("RenwoleNEWPass") where user="root";
D:\MySQL\MySQL Server 5.2\bin>flush privileges;
D:\MySQL\MySQL Server 5.2\bin>exit;

方案二;(适用于mysql5.6/5.7/8.0)
以下操作到mysql安装目录BIN下的执行;

D:\MySQL\MySQL Server 5.6\bin>Net stop mysql
D:\MySQL\MySQL Server 5.6\bin>mysqld --skip-grant-tables
D:\MySQL\MySQL Server 5.6\bin>use mysql;
D:\MySQL\MySQL Server 5.6\bin>update mysql.user set authentication_string=password('RenwoleNEWPass') where user='root';
D:\MySQL\MySQL Server 5.6\bin>flush privileges;
D:\MySQL\MySQL Server 5.6\bin>exit;

最后结束mysql进程,重启mysql服务即可。

Linux Centos7 MariaDB(MySQL)10.2 主从半同步复制模式安装配置

实验环境情况;

操作系统:CentOS Linux release 7.3.1611 (Core)
数据库:MariaDB-10.2.6-linux-glibc_214-x86_64

1.实现半同步复制功能需要在主从服务器上安装google提供的插件。插件在MySQL二进制/usr/local/mysql/lib/plugin目录下,分别是;

主插件: semisync_master.so
从插件: sosemisync_slave.so

2.分别在主从节点上安装插件

3.主服务器安装插件:

MariaDB [(none)]> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so'; //安装插件 
MariaDB [(none)]> SET GLOBAL rpl_semi_sync_master_enabled = 1; //启动插件模块 
MariaDB [(none)]> SET GLOBAL rpl_semi_sync_master_timeout = 1000; //设置超时时间

4.从服务器安装插件;

MariaDB [(none)]> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so'; //安装插件 
MariaDB [(none)]> SET GLOBAL rpl_semi_sync_slave_enabled = 1; //启动插件模块
MariaDB [(none)]> STOP SLAVE IO_THREAD; START SLAVE IO_THREAD; //重启进程使插件模块生效

5.在主Master和从Slave的my.cnf中编辑添加以下:

[mysqld]
rpl_semi_sync_master_enabled = 1
rpl_semi_sync_master_timeout = 1000

[mysqld]
rpl_semi_sync_slave_enabled = 1

6.我们至此已经实现了mysql数据库复制的半同步方式的架构。在主服务器的数据库中创建一个数据库或表,在从服务器停止后,查看主服务器是否初次延迟,二次创建数据库则降为异步同步,当从服务器启动后如果同步成功,那说明配置已经没有问题。

推荐:海外知名主机 SSD VPS 云服务器

//www.vultr.com/ 美国知名云服务器提供商
//www.digitalocean.com/ 纽约知名云主机商家(数字海洋)
//www.cloudflare.com/ 旧金山CDN提供商
//www.linode.com/ 日本VPS主机商
//www.cacloud.com/ 加拿大云服务机商
//www.ovh.com/ 法国知名IDC

以上VPS主机提供商均有全球云服务资源,特别适合站长,价格便宜,自定义权限大,可控度高。

Windows server 2003&iis6&PHP5.3&Zend&FastCGI安装配置

1.相关软件下载篇

//windows.php.net/downloads/releases/archives/ 下载所需php版本
//www.iis.net/downloads/microsoft/fastcgi-for-iis 下载FastCGI组件
//www.zend.com/en/products/loader/downloads#Windows 下载所需ZEND版本
Microsoft Visual C++ 2008 Redistributable Package x86(默认安装)

默认安装FastCGI,将下载下来的php解压到E盘并命名为PHP文件夹,给php目录users默认权限。

2.FastCGI配置篇

在FastCGI配置文件最后一行添加参数;

C:\WINDOWS\system32\inetsrv\fcgiext.ini

[Types]
php=PHP
[PHP]
ExePath=E:\PHP\php-cgi.exe
InstanceMaxRequests=10000
EnvironmentVars=PHP_FCGI_MAX_REQUESTS:10000
ActivityTimeout=3600
RequestTimeout=3600

添加系统环境变量:

我的电脑->属性->高级->环境变量->系统变量,在Path的最后面中加上;E:\PHP\
3.php.ini配置篇

将E:\php\php.ini-development 重命名为php.ini,并开启PHP相关参数
在php目录新建E:\PHP\tmp目录并给缓存users写入权限。

short_open_tag = On
upload_tmp_dir="E:\PHP\tmp"
cgi.force_redirect=0
fastcgi.impersonate=1;
extension_dir="E:\PHP\ext"
date.timezone =PRC ;或Asia/Shanghai

extension=php_curl.dll
extension=php_gd2.dll
extension=php_ldap.dll
extension=php_mbstring.dll
extension=php_exif.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_sockets.dll
extension=php_xmlrpc.dll

4.iis6.0配置篇

IIS扩展添加,打开iis-网站-属性-主目录-配置-应用程序扩展-添加,可执行文件以下;

C:\WINDOWS\system32\inetsrv\fcgiext.dll

扩展名;PHP

其他默认
5.Zend安装配置篇
将解压的zend包对应php版本的DLL文件放入E:\php\ext目录,然后在php.ini的最后一行添加以下zend配置参数;

[ZendGuardLoader]

zend_loader.enable=1

zend_loader.disable_licensing=1

zend_loader.obfuscation_level_support=3

zend_loader.license_path=

zend_extension="E:\php\ext\ZendLoader.dll"

6.重启iis,并在iis中新建站点,写一个php探针测试是否成功

新建普通txt文件,将下面内容复制到txt文件中,并命名为php.php(注意扩展名);

<?
 phpinfo();
 ?>

访问成功就会显示php相关信息以及版本情况。

SQL server 无法删除用户对象架构解决方案

sql语句;

方法一;适用于SQL server 2000/2005/2008R2

use usernamedb
 go

declare tb cursor local
 for
 select 'sp_changeobjectowner '
 +quotename(
 +quotename(user_name(uid))
 +'.'+quotename(name),'''')
 +',''dbo'''
 from sysobjects
 where objectproperty(id,N'isusertable')=1
 and uid<>user_id('dbo')
 declare @s nvarchar(4000)
 open tb
 fetch tb into @s
 while @@fetch_status=0
 begin
 exec(@s)
 fetch tb into @s
 end
 close tb
 deallocate tb

方法二;适用于SQL server 2005/2008R2

ALTER AUTHORIZATION ON SCHEMA::db_owner TO dbo;

数据库-安全性-架构,先删除对应用户架构再删除用户。

方法三;适用于SQL server 2000

开始-程序-Microsoft SQL Server-企业管理器打开-点击本地服器-右击属性-服务器设置-允许对系统目录直接进行修改-确定-数据库-master-sysusers-右击-打开表-返回所有行-找到要删除的用户删除即可,通常在最后一行。

其他版本没尝试,你可以试试。如果有好的解决方案,可以留言,我好补充加上。

Linux MariaDB(MySQL)10.2 数据库基于GTID主从同步复制安装配置

原创作品,转载请注明本文地址

操作系统:CentOS Linux release 7.3.1611 (Core)
数据库:MariaDB-10.2.6-linux-glibc_214-x86_64

主服务器:10.10.10.56
从服务器:10.10.10.163

1.今天要做的事,单向主从同步

关于MariaDB(MySQL)数据库安装请参阅《Centos7.3 x64位二进制安装(MySQL)MariaDB 10.1.20数据库之生产篇》下面就开始MariaDB(MySQL)服务器集群的配置过程。

2.在MariaDB(MySQL)配置文件中修改或添加以下信息

vim /etc/my.cnf

主从通用配置

binlog-format = mixed #二进制日志记录的模式(高版本默认开启)
binlog-checksum = CRC32 #可使主机为写入二进制日志的事件写入校验(高版本默认开启)
sync-master-info = 1 #MariaDB依靠操作系统将master.info文件刷新到磁盘。
sync_relay_log_info = 1 #MariaDB依靠操作系统将relay-log.info文件刷新到磁盘。
expire_logs_days = 7 #日志文件过期天数,默认是 0,表示不过期 
master-verify-checksum = 1 #主服务器效验
slave-sql-verify-checksum = 1 #从服务器效验

3.主服务器Master除了通用配置外,还需要加入以下代码

server-id = 56 #MySQL服务器ID,不重复
log-bin = mysql-bin #二进制日志(默认开启)
sync-binlog = 1 #主服务器进行设置,用于事务安全
log-bin-index = mysql-bin

4.从服务器Slave除了通用配置外,还需要加入以下代码

server-id = 163
relay-log = relay-bin #中继日志
slave-parallel-threads = 2 #设定从服务器的SQL线程数
#replicate-do-db = renwoleblogdb#复制指定的数据库,多个写多行
replicate-ignore-db = mysql #不备份的数据库,多个写多行
relay_log_recovery = 1 #从站崩溃后可以使用,防止损坏的中继日志处理。
log-slave-updates = 1 #slave将复制事件写进自己的二进制日志
relay-log-index = relay-bin

此外Mysql从服务器没有必要开启二进制日志,但是在一些情况下,必须设置,例如;如果slave为其它slave的master,必须设置bin_log。我这里就默认开启。

5.以上只是简单的介绍了每个参数的作用,这些参数的具体设置还需根据用户的实际情况进行相关调整,具体可到官方了解

《复制和二进制日志服务器系统变量》
//mariadb.com/kb/en/mariadb/replication-and-binary-log-server-system-variables/

关于系统变量的兼容性,可参阅官方

《MariaDB与MySQL兼容性》
//mariadb.com/kb/en/mariadb/mariadb-vs-mysql-compatibility/

6.主服务器Master授权配置

主MariaDB服务器上创建专用账号并授权数据库权限,以及从服务器IP的远程访问

# mysql -uroot -p
Enter password:【输入你的MySQL密码回车】
MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO 'renwoleuseracc'@'%' IDENTIFIED BY 'renwoleuserpass'; //创建Slave专用备份账号
MariaDB [(none)]> flush privileges; //刷新MySQL权限
MariaDB [(none)]> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user; //查看授权情况
MariaDB [(none)]> flush tables with read lock; //锁定数据库防止master值变化
MariaDB [(none)]> show master status; //获取master状态值
+-----------------+----------+------------+-----------------+
| File |Position |Binlog_Do_DB|Binlog_Ignore_DB |
+-----------------+----------+------------+-----------------+
| mysql-bin.000006| 627 | | |
+-----------------+----------+------------+-----------------+
1 row in set (0.00 sec)

7.一旦获取了备份时正确的Binlog位点(文件名和偏移量),那么就可以用BINLOG_GTID_POS()函数来计算GTID

MariaDB [(none)]> SELECT BINLOG_GTID_POS("mysql-bin.000006", 627);
+------------------------------------------+
| BINLOG_GTID_POS('mysql-bin.000006', 627) |
+------------------------------------------+
| 0-56-4 |
+------------------------------------------+
1 row in set (0.01 sec)

8.从服务器Slave配置

正如官方所说从MariaDB 10.0.13版本开始,mysqldump会自动完成这个工作,并且把GTID的写在导出文件中,只要设置 –master-data 或 –dump-slave 的同时设置 –gtid 即可。

这样的话新的SLAVE就可以通过设置 @@gtid_slave_pos 的值来设定复制的起始位置,用 CHANGE MASTER 把这个值传给主库,然后开始复制:

# mysql -uroot -p
Enter password:【输入你的MySQL密码】
MariaDB [(none)]> SET GLOBAL gtid_slave_pos = "0-56-4";
MariaDB [(none)]> change master to master_host='10.10.10.56',MASTER_PORT = 3306,master_user='renwoleuseracc',master_password='renwoleuserpass',master_use_gtid=slave_pos; //进行主从授权
MariaDB [(none)]> START SLAVE; //启动Slave
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
 Slave_IO_State: Waiting for master to send event
 Master_Host: 10.10.10.56
 Master_User: renwoleuseracc
 Master_Port: 3306
 Connect_Retry: 60
 Master_Log_File: mysql-bin.000006
 Read_Master_Log_Pos: 627
 Relay_Log_File: relay.000035
 Relay_Log_Pos: 537
 Relay_Master_Log_File: mysql-bin.000006
 Slave_IO_Running: Yes
 Slave_SQL_Running: Yes
 ...
 ...
 ...
 Using_Gtid: Slave_pos
 Gtid_IO_Pos: 0-56-4

9.如果 Slave_IO_Running 与 Slave_SQL_Running 都为YES,表明从服务已经运行,Using_Gtid列判断GTID值是否一致。
说明:

master_host 表示master授权地址
MASTER_PORT MySQL端口
master_user 表示master授权账号
master_password 表示密码
master_use_gtid GTID变量值

10.接下来解锁主服务器数据库表

MariaDB [(none)]> unlock tables; //解锁数据表
MariaDB [(none)]> show slave hosts; //查看从服务器连接状态
MariaDB [(none)]> show global status like "rpl%"; //查看客户端

11.从服务器Slave查看relay的所有相关参数

MariaDB [(none)]> show variables like '%relay%';

12.主从已经配置完成。现在无论在主服务器上增、改、删、查,都会同步到从服务器,根据自己的需求进行相关测试即可。
关于master slave重置语法

重置master的核心语法

RESET MASTER; 意思是执行 RESET MASTER 将删除所有二进制日志文件,并创建一个空白的二进制日志文件,数字后缀为.000001,RESET MASTER 不会影响SLAVE服务器上的工作状态,所以执行这个命令会导致Slave找不到Master的binlog,从而造成同步失败。

重置slave的核心语法

RESET SLAVE; 含义是;RESET SLAVE 将清除slave上的同步位置并删除所有旧的同步中继日志文件,但重置前必须先停止slave服务(STOP SLAVE)

以后有时间,我将介绍基于GTID的半同步主从的文章,这也是在生产中所需要记录下来,以备以后使用。

更多介绍://mysql.taobao.org/monthly/2016/02/08/

推荐:DiskGenius Pro 4.7.2 64 专业绿色大文件恢复版

该软件经过详细测试,可以恢复单个文件大小100G以上(测试文件格式类型VHDX),有些版本只能恢复1G大小的文件,所以把好东西分享给大家,DiskGenius Pro软件包经过360杀毒和云查杀没有出现病毒等问题,如果不放心,可以使用专业web版扫描,地址://virscan.org/。此软件只能在windows下运行包含32&64位。

如有涉嫌侵权或违法违规内容,请在下方留言,以便我们及时处理。

linux Centos7平滑无缝升级PHP7.1.0到PHP 7.1.5新版本

我是一个比较喜欢爱好新技术的人,一旦有新的东西出现或发行,我都会拿来研究,最终用于生产中。新的东西有利有弊,PHP新版本有很多特性,同样也存在未知的BUG,所以无论是拿来学习,还是用于生产都要谨慎。不过话说回来既然发布了稳定版就不妨一试呗。

实验环境:CentOS Linux release 7.3.1611 (Core)
内核版本:Linux version 3.10.0-514.el7.x86_64

1.查看php版本有两种方法,显示结果相同。

第一种

# /usr/local/php/bin/php -v

第二种

# php  -v

PHP 7.1.0 (cli) (built: Dec 17 2016 17:00:32) ( ZTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.1.0, Copyright (c) 1999-2016, by Zend Technologies

2.升级前需要找到之前的configure配置模块信息,做到升级前后是一致,否则可能会影响网站正常访问,若不记得之前的configure信息,可以写个phpinfo探针查找即可,或者使用以下命令;

# php -i | grep configure

Configure Command => './configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--with-fpm-user=www' '--with-fpm-group=www' '--with-iconv-dir' '--with-freetype-dir' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl' '--enable-mbregex' '--enable-fpm' '--enable-mbstring' '--with-mcrypt' '--with-gd' '--enable-gd-jis-conv' '--enable-gd-native-ttf' '--with-openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--enable-opcache' '--with-libmbfl' '--with-onig' '--enable-pdo' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-pdo-mysql' '--enable-mysqlnd-compression-support' '--with-pear' '--enable-maintainer-zts' '--enable-session' '--with-gettext'

以上信息稍作修改后,即可安装配置使用。

3.重要:先备份老版本php,以备升级失败后快速回滚

 # mv /usr/local/php /usr/local/php7.1.bak
 # mkdir /renwole
 # cd /renwole
 # wget //am1.php.net/distributions/php-7.1.5.tar.gz
 # tar zxvf php-7.1.5.tar.gz
 # cd php-7.1.5
 # ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-fpm-user=www --with-fpm-group=www --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-jis-conv --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-mysql --enable-mysqlnd-compression-support --with-pear --enable-maintainer-zts --enable-session --with-gettext

PHP编译完成后,你会看到 “Thank you for using PHP.” 字样,表示编译完成,执行以下安装命令;

# make && make install

这个过程有些慢,但不影响你的网站正常访问,耐心等待…

4.php完成升级安装配置后,开始拷贝php配置文件

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# cp /renwole/php-7.1.5/php.ini-development /usr/local/php/etc/php.ini
# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

或者沿用老版php配置文件(如果PHP版本跨度不大,建议使用老版本php.ini,否则php配置文件中的很多东西需要重新配置),\cp -rf表示覆盖无提示

# \cp -rf /usr/local/php7.1.0.bak/etc/php-fpm.conf /usr/local/php/etc/php-fpm.conf
# \cp -rf /usr/local/php7.1.0.bak/etc/php.ini /usr/local/php/etc/php.ini
# \cp -rf /usr/local/php7.1.0.bak/etc/php-fpm.d/www.conf /usr/local/php/etc/php-fpm.d/www.conf

5.现在重启php-fpm

# systemctl restart php-fpm.server

6.再次查看php版本

# /usr/local/php/bin/php -v

PHP 7.1.5 (cli) (built: May 11 2017 16:18:43) ( ZTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.5, Copyright (c) 1999-2017, by Zend Technologies

打印出来的PHP版本信息显示;已经成功从PHP 7.1.0平滑无缝升级为PHP 7.1.5

Linux Nginx网站:Certbot安装配置Lets Encrypt SSL免费HTTPS加密证书

实验环境:CentOS Linux release 7.3.1611 (Core)
内核版本:Linux version 3.10.0-514.el7.x86_64
Nginx版本: Nginx-1.13.0

Let’s Encrypt是一个免费的、自动化、开放的证书颁发机构。由Mozilla、Cisco、Chrome、facebook、Akamai等众多公司和机构发起的,其安全稳定及其可靠。具体信息可以去letsencrypt官方网站了解详情。

今天我们就充分利用Lets Encrypt让你的网站实现https加密。

官网://letsencrypt.org/

1.安装certbot及源扩展包

$ yum install -y epel-release

Certbot是Let’s Encrypt官方指定推荐的客户端。通过 Certbot,你可以自动化部署 Let’s Encrypt SSL证书,以便为网站加上HTTPS加密支持。

$ yum install certbot
$ certbot certonly
Saving debug log to /var/log/letsencrypt/letsencrypt.log
How would you like to authenticate with the ACME CA?
//你是希望如何使用ACME CA进行身份验证?
-------------------------------------------------------------------------------
1: Place files in webroot directory (webroot)
//将文件放在webroot目录
2: Spin up a temporary webserver (standalone)
//使用临时Web服务器(独立目录)
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):1 【选择1回车】
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel):su@renwole.com【输入您的邮箱地址,用于紧急更新和安全通知】

Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
-------------------------------------------------------------------------------
Please read the Terms of Service at
//letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf. You must agree
in order to register with the ACME server at
//acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A【选择A回车同意服务条款,C为拒绝】
-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o:Y【您是否愿意分享您的电子邮件地址,建议选择Y回车】
Please enter in your domain name(s) (comma and/or space separated) (Enter 'c'
to cancel): blog.renwole.com【输入域名回车】
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for blog.renwole.com
Select the webroot for blog.renwole.com:
-------------------------------------------------------------------------------
1: Enter a new webroot
//输入网站绝对路径
-------------------------------------------------------------------------------
Press 1 [enter] to confirm the selection (press 'c' to cancel):1【选择数字1回车】
Input the webroot for blog.renwole.com: (Enter 'c' to cancel):/home/www/blog.renwole.com【输入网站所在绝对路径回车】
Waiting for verification...
Waiting for verification...
Cleaning up challenges
Generating key (2048 bits): /etc/letsencrypt/keys/0001_key-certbot.pem
Creating CSR: /etc/letsencrypt/csr/0001_csr-certbot.pem

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/blog.renwole.com/fullchain.pem. Your cert
will expire on 2017-08-09. To obtain a new or tweaked version of
this certificate in the future, simply run certbot again. To
non-interactively renew *all* of your certificates, run "certbot
renew"
- If you like Certbot, please consider supporting our work by:

Donating to ISRG / Let's Encrypt: //letsencrypt.org/donate
Donating to EFF:

恭喜!您的SSL证书和密钥链接已保存,你的证书将于2017-08-09到期。

注意:这里需要说明,在生成证书之前,你必须保证nginx 443端口是运行状态,否则会生成证书失败。

2.自动续订

Certbot可以配置为在证书过期之前自动更新证书。由于Let’s Encrypt SSL证书有效期时间为90天,所以建议您利用此功能。您可以通过运行以下命令来测试证书的自动续订:

$ sudo certbot --nginx certonly

如果以上正常工作,你可以通过添加运行以下操作的cron或systemd定时任务安排自动更新:

certbot renew

我们写一个自动执行脚本,建议每小时执行一次:

$ sudo crontab -e

添加以下内容:

0 */6 * * * /usr/bin/certbot renew --quiet && /bin/systemctl restart nginx

保存并退出!

通过命令查看是否添加成功:

$ crontab -l
0 */6 * * * /usr/bin/certbot renew --quiet && /bin/systemctl restart nginx

重启crontab

$ systemctl status crond.service
$ systemctl restart crond.service

通过命令观察 crontab 是否执行:

$ tail -f /var/log/cron

证书是否续订成功,可以通过以下命令管理查看证书信息:

$ certbot certificates

更多Certbot命令请参阅官方文档 //certbot.eff.org/docs/

3.配置nginx.conf
接下来修改Nginx配置文件,修改sever段,去掉相应注释,将生成的SSL证书填写到ssl_certificate后面,将生成的密钥填写到ssl_certificate_key后面,保存并重启nginx服务器即可。

# vi /usr/local/nginx/conf/nginx.conf

server {
 listen 443 ssl;

 ssl_certificate /etc/letsencrypt/live/blog.renwole.com/fullchain.pem;
 ssl_certificate_key /etc/letsencrypt/live/blog.renwole.com/privkey.pem;

# ssl_session_cache shared:SSL:1m;
 ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
 ssl_prefer_server_ciphers on;

# location / {
 # root html;
 # index index.html index.htm;
 # }
 }

使用谷歌浏览器访问//blog.renwole.com/可以看到绿色的安全小锁图标,说明网站已经https加密成功。