在Centos 7上使用rclone挂载OneDrive网盘

前期准备

客户端授权

在本地Windows电脑上下载rclone,下载地址:https://rclone.org/downloads/ 。然后解压出来,进入cmd,输入以下命令:

rclone authorize "onedrive"

之后会弹出窗口认证,然后复制token

Paste the following into your remote machine --->
{"access_token":"xxxx"}  #请复制{xx}整个内容(包括花括号),后面需要用到
<---End paste

安装fuse

在服务器上安装fuse,在挂载时会用到

yum install fuse

安装rclone

安装

curl https://rclone.org/install.sh | sudo bash

初始化配置

rclone config

No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> Spirit #随便填
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / A stackable unification remote, which can appear to merge the contents of several remotes
    "union"
 2 / Alias for a existing remote
    "alias"
 3 / Amazon Drive
    "amazon cloud drive"
 4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc)
    "s3"
 5 / Backblaze B2
    "b2"
 6 / Box
    "box"
 7 / Cache a remote
    "cache"
 8 / Dropbox
    "dropbox"
 9 / Encrypt/Decrypt a remote
    "crypt"
10 / FTP Connection
    "ftp"
11 / Google Cloud Storage (this is not Google Drive)
    "google cloud storage"
12 / Google Drive
    "drive"
13 / Hubic
    "hubic"
14 / JottaCloud
    "jottacloud"
15 / Local Disk
    "local"
16 / Mega
    "mega"
17 / Microsoft Azure Blob Storage
    "azureblob"
18 / Microsoft OneDrive
    "onedrive"
19 / OpenDrive
    "opendrive"
20 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
    "swift"
21 / Pcloud
    "pcloud"
22 / QingCloud Object Storage
    "qingstor"
23 / SSH/SFTP Connection
    "sftp"
24 / Webdav
    "webdav"
25 / Yandex Disk
    "yandex"
26 / http Connection
    "http"
Storage> 18 #选择18,Microsoft OneDrive
** See help for onedrive backend at: https://rclone.org/onedrive/ **

Microsoft App Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id> #留空
Microsoft App Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret> #留空
Edit advanced config? (y/n)
y) Yes
n) No
y/n> n
Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes
n) No
y/n> n  #选择n
For this to work, you will need rclone available on a machine that has a web browser available.
Execute the following on your machine:
    rclone authorize "onedrive"
Then paste the result below:
result> {"access_token":""}  #输入之前在客户端授权的内容
--------------------
Choose a number from below, or type in an existing value
 1 / OneDrive Personal or Business
    "onedrive"
 2 / Root Sharepoint site
    "sharepoint"
 3 / Type in driveID
    "driveid"
 4 / Type in SiteID
    "siteid"
 5 / Search a Sharepoint site
    "search"
Your choice> 1 #选择1
--------------------
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y  #选择y
Current remotes:

Name                 Type
====                 ====
Spirit                 onedrive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q  #选择q退出

挂载

rclone mount Spirit:Wallpapers /mnt/3/ --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000

Spirit为初始化配置填的nameWallpapers为OneDrive里的文件夹,/mnt/3/为VPS上的本地文件夹

卸载

fusermount -qzu /mnt/3/

设置开机自启

下载脚本

wget -N --no-check-certificate https://raw.githubusercontent.com/x91270/Centos/master/rcloned

修改一下内容

vim rcloned
NAME=""  #rclone name名,及配置时输入的Name
REMOTE=''  #远程文件夹,OneDrive 网盘里的挂载的一个文件夹
LOCAL=''  #挂载地址,VPS本地挂载目录

设置自启

mv rcloned /etc/init.d/rcloned
chmod +x /etc/init.d/rcloned
chkconfig rcloned on
bash /etc/init.d/rcloned start

CentOS 7 安装 PHP 7.2

本文将介绍如何在 CentOS 7 服务器上使用 yum 命令安装 PHP7.2,内容提炼自外文网站,点击查看原文

安装 PHP7.2

安装 EPEL 软件包:

$ sudo yum install epel-release

安装 remi 源:

$ sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

安装 yum 扩展包:

$ sudo yum install yum-utils

启用 remi 仓库:

$ sudo yum-config-manager --enable remi-php72
$ sudo yum update

安装 PHP7.2

$ sudo yum install php72

安装 php-fpm 和一些其他模块

$ sudo yum install php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache

输入 php72 -v 查看安装结果

php-fpm 服务

设置开机自启

$ sudo systemctl enable php72-php-fpm.service

常用 php-fpm 命令

# 开启服务
$ sudo systemctl start php72-php-fpm.service

# 停止服务
$ sudo systemctl stop php72-php-fpm.service

# 查看状态
$ sudo systemctl status php72-php-fpm.service

通过 egrep 查询 nginx 服务器的用户和用户组:

$ egrep '^(user|group)' /etc/nginx/nginx.conf

结果示例:

user nginx;

编辑 /etc/opt/remi/php72/php-fpm.d/www.conf,修改执行 php-fpm 的权限:

$ sudo vi /etc/opt/remi/php72/php-fpm.d/www.conf

设置用户和用户组为 nginx:

user = nginx
group = nginx

保存并关闭文件,重启 php-fpm 服务:

$ sudo systemctl restart php72-php-fpm.service

路径整理

# php 安装路径
/etc/opt/remi/php72

# nginx 配置文件
/etc/nginx/nginx.conf

# nginx 默认项目路径
/usr/share/nginx/html

CentOS 7 root 密码忘记了怎么修改恢复

前言

本文主要是演示如何破解CentOS 7的密码。如果你因种种原因而没有获取系统原来的管理密码时,可以使用此方法。注意的是,破解必须是通过本地显示器或者服务器远程管理卡界面进行,也就是说,你能获取到机房物理服务器的管理权限。否则,不能对root用户进行密码重置。

Step1: 开机选择内核

开机,快速的按上下键,选择第一个

未分类

Step2: 进入grub编辑模式

按下字母e进入grub编辑模式

未分类

Step3: 修改grub启动的参数

找到linux16开头的行

未分类

到该行的最后,向前删除字符到ro

未分类

把ro改成rw rd.break

未分类

修改好后按ctrl+x,即表示临时使用刚刚修改的grub参数启动系统

Step4: 切换到伪根目录

chroot /sysroot/

未分类

chroot,即 change root directory (更改 root 目录)。在 linux 系统中,系统默认的目录结构都是以 /,即以根 (root) 开始的。而在使用 chroot 之后,系统的目录结构将以指定的位置作为 / 位置。

为什么要使用 chroot 命令
增加了系统的安全性,限制了用户的权力:
在经过 chroot 之后,在新根下将访问不到旧系统的根目录结构和文件,这样就增强了系统的安全性。一般会在用户登录前应用 chroot,把用户的访问能力控制在一定的范围之内。

建立一个与原系统隔离的系统目录结构,方便用户的开发:
使用 chroot 后,系统读取的是新根下的目录和文件,这是一个与原系统根下文件不相关的目录结构。在这个新的环境中,可以用来测试软件的静态编译以及一些与系统不相关的独立开发。

切换系统的根目录位置,引导 Linux 系统启动以及急救系统等:
chroot 的作用就是切换系统的根位置,而这个作用最为明显的是在系统初始引导磁盘的处理过程中使用,从初始 RAM 磁盘 (initrd) 切换系统的根位置并执行真正的 init,本文的最后一个 demo 会详细的介绍这种用法。

Step5: 修改root密码

使用passwd命令修改root密码

passwd root

未分类

方块的地方应该是显示中文的,但默认情况下,grub并没有使用utf-8字符编码。
不用理会这个,连续两次输入一样的密码即表示设置成功。但要注意的是,密码要使用大写字母、小写字母、特殊符号组合,不然系统可能因安全策略设置拒绝新密码,但你又看不懂提示的情况。

Step6: 重打系统文件的selinux标签

SElinux开启时必须需要创建,重打selinux标签,如果没这步,系统起不来的。

重打selinux标签,然后退出伪根目录

touch /.autorelabel
exit

未分类

Step7:然后重启系统

reboot

Step8: 验证新密码是否生效

输入刚刚设置的新密码验证,如果失败,请返回Step5重来一次。

未分类

总结

CentOS 7重置密码和CentOS 6不一样,但原理基本相同,而且重置密码的操作不能通过远程进行,只能在本地显示器上或者服务器的远程管理卡界面上进行,这是一种安全策略。

CentOS 7 防火墙FirewallD的常用命令

FirewallD 是 CentOS 7 服务器上默认可用的防火墙管理工具,它通过iptables命令充当Linux内核的netfilter框架的前端,提供防火墙功能,作为iptables服务的替代品。名称FirewallD通过附加字母“d”遵守命名系统守护进程的Unix约定,FirewallD是用Python编写的。

安装FirewallD

yum install firewalld

FirewallD基本命令:

# systemctl start firewalld # 启动,
# systemctl restart firewalld # 重启
# systemctl enable firewalld # 开机启动
# systemctl stop firewalld # 关闭
# systemctl disable firewalld # 取消开机启动
# firewall-cmd --state #查看运行状态
firewall-cmd --zone=public --list-ports # 查看打开端口

命令含义:

--zone #作用域
--add-port=80/tcp  #添加端口,格式为:端口/通讯协议
--permanent   #永久生效,没有此参数重启后失效

打开网站的日常端口

firewall-cmd --zone=public --add-port=22/tcp --permanent

firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --zone=public --add-port=443/tcp --permanent

firewall-cmd --zone=public --add-port=3306/tcp --permanent

开启udp端口

firewall-cmd --zone=public --add-port=443/udp --permanent

CentOS 7.2 编译安装 Nginx1.12.2

环境说明

1、系统:CentOS最小化安装;升级软件补丁,内核和系统版本不升级;关闭SELinux和防火墙。系统安装可参考CentOS 7系统部署

2、软件:安装包统一放置在/usr/src目录下,安装位置统一在/usr/local目录下。

开始安装

1、安装Nginx所需pcre库,官方网站(www.pcre.org)。安装pcre库是为了使Nginx支持具备URL重写功能的Rewite模块,如不安装则Nginx无法使用此模块功能(典型功能为伪静态)。

[root@localhost ~]# yum -y install pcre-devel
Loaded plugins: fastestmirror
base                                                                                                                                                                                    | 3.6 kB  00:00:00     
extras                                                                                                                                                                                  | 3.4 kB  00:00:00     
updates                                                                                                                                                                                 | 3.4 kB  00:00:00     
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package pcre-devel.x86_64 0:8.32-17.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================================
 Package                                             Arch                                            Version                                               Repository                                     Size
===============================================================================================================================================================================================================
Installing:
 pcre-devel                                          x86_64                                          8.32-17.el7                                           base                                          480 k

Transaction Summary
===============================================================================================================================================================================================================
Install  1 Package

Total download size: 480 k
Installed size: 1.4 M
Downloading packages:
pcre-devel-8.32-17.el7.x86_64.rpm                                                                                                                                                       | 480 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : pcre-devel-8.32-17.el7.x86_64                                                                                                                                                               1/1 
  Verifying  : pcre-devel-8.32-17.el7.x86_64                                                                                                                                                               1/1 

Installed:
  pcre-devel.x86_64 0:8.32-17.el7                                                                                                                                                                              

Complete!

2、安装编译需要的组件

[root@localhost ~]# yum -y install zlib-devel openssl-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package openssl-devel.x86_64 1:1.0.2k-8.el7 will be installed
--> Processing Dependency: krb5-devel(x86-64) for package: 1:openssl-devel-1.0.2k-8.el7.x86_64
---> Package zlib-devel.x86_64 0:1.2.7-17.el7 will be installed
--> Running transaction check
---> Package krb5-devel.x86_64 0:1.15.1-8.el7 will be installed
--> Processing Dependency: libkadm5(x86-64) = 1.15.1-8.el7 for package: krb5-devel-1.15.1-8.el7.x86_64
--> Processing Dependency: libverto-devel for package: krb5-devel-1.15.1-8.el7.x86_64
--> Processing Dependency: libselinux-devel for package: krb5-devel-1.15.1-8.el7.x86_64
--> Processing Dependency: libcom_err-devel for package: krb5-devel-1.15.1-8.el7.x86_64
--> Processing Dependency: keyutils-libs-devel for package: krb5-devel-1.15.1-8.el7.x86_64
--> Running transaction check
---> Package keyutils-libs-devel.x86_64 0:1.5.8-3.el7 will be installed
---> Package libcom_err-devel.x86_64 0:1.42.9-10.el7 will be installed
---> Package libkadm5.x86_64 0:1.15.1-8.el7 will be installed
---> Package libselinux-devel.x86_64 0:2.5-11.el7 will be installed
--> Processing Dependency: libsepol-devel(x86-64) >= 2.5-6 for package: libselinux-devel-2.5-11.el7.x86_64
--> Processing Dependency: pkgconfig(libsepol) for package: libselinux-devel-2.5-11.el7.x86_64
---> Package libverto-devel.x86_64 0:0.2.5-4.el7 will be installed
--> Running transaction check
---> Package libsepol-devel.x86_64 0:2.5-6.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================================
 Package                                                   Arch                                         Version                                               Repository                                  Size
===============================================================================================================================================================================================================
Installing:
 openssl-devel                                             x86_64                                       1:1.0.2k-8.el7                                        base                                       1.5 M
 zlib-devel                                                x86_64                                       1.2.7-17.el7                                          base                                        50 k
Installing for dependencies:
 keyutils-libs-devel                                       x86_64                                       1.5.8-3.el7                                           base                                        37 k
 krb5-devel                                                x86_64                                       1.15.1-8.el7                                          base                                       266 k
 libcom_err-devel                                          x86_64                                       1.42.9-10.el7                                         base                                        31 k
 libkadm5                                                  x86_64                                       1.15.1-8.el7                                          base                                       174 k
 libselinux-devel                                          x86_64                                       2.5-11.el7                                            base                                       186 k
 libsepol-devel                                            x86_64                                       2.5-6.el7                                             base                                        74 k
 libverto-devel                                            x86_64                                       0.2.5-4.el7                                           base                                        12 k

Transaction Summary
===============================================================================================================================================================================================================
Install  2 Packages (+7 Dependent packages)

Total download size: 2.3 M
Installed size: 4.6 M
Downloading packages:
(1/9): keyutils-libs-devel-1.5.8-3.el7.x86_64.rpm                                                                                                                                       |  37 kB  00:00:00     
(2/9): libcom_err-devel-1.42.9-10.el7.x86_64.rpm                                                                                                                                        |  31 kB  00:00:00     
(3/9): libkadm5-1.15.1-8.el7.x86_64.rpm                                                                                                                                                 | 174 kB  00:00:00     
(4/9): krb5-devel-1.15.1-8.el7.x86_64.rpm                                                                                                                                               | 266 kB  00:00:00     
(5/9): libselinux-devel-2.5-11.el7.x86_64.rpm                                                                                                                                           | 186 kB  00:00:00     
(6/9): libsepol-devel-2.5-6.el7.x86_64.rpm                                                                                                                                              |  74 kB  00:00:00     
(7/9): libverto-devel-0.2.5-4.el7.x86_64.rpm                                                                                                                                            |  12 kB  00:00:00     
(8/9): zlib-devel-1.2.7-17.el7.x86_64.rpm                                                                                                                                               |  50 kB  00:00:00     
(9/9): openssl-devel-1.0.2k-8.el7.x86_64.rpm                                                                                                                                            | 1.5 MB  00:00:00     
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                          4.2 MB/s | 2.3 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libkadm5-1.15.1-8.el7.x86_64                                                                                                                                                                1/9 
  Installing : libsepol-devel-2.5-6.el7.x86_64                                                                                                                                                             2/9 
  Installing : libselinux-devel-2.5-11.el7.x86_64                                                                                                                                                          3/9 
  Installing : libcom_err-devel-1.42.9-10.el7.x86_64                                                                                                                                                       4/9 
  Installing : libverto-devel-0.2.5-4.el7.x86_64                                                                                                                                                           5/9 
  Installing : keyutils-libs-devel-1.5.8-3.el7.x86_64                                                                                                                                                      6/9 
  Installing : krb5-devel-1.15.1-8.el7.x86_64                                                                                                                                                              7/9 
  Installing : zlib-devel-1.2.7-17.el7.x86_64                                                                                                                                                              8/9 
  Installing : 1:openssl-devel-1.0.2k-8.el7.x86_64                                                                                                                                                         9/9 
  Verifying  : zlib-devel-1.2.7-17.el7.x86_64                                                                                                                                                              1/9 
  Verifying  : keyutils-libs-devel-1.5.8-3.el7.x86_64                                                                                                                                                      2/9 
  Verifying  : libverto-devel-0.2.5-4.el7.x86_64                                                                                                                                                           3/9 
  Verifying  : libselinux-devel-2.5-11.el7.x86_64                                                                                                                                                          4/9 
  Verifying  : krb5-devel-1.15.1-8.el7.x86_64                                                                                                                                                              5/9 
  Verifying  : libcom_err-devel-1.42.9-10.el7.x86_64                                                                                                                                                       6/9 
  Verifying  : libsepol-devel-2.5-6.el7.x86_64                                                                                                                                                             7/9 
  Verifying  : 1:openssl-devel-1.0.2k-8.el7.x86_64                                                                                                                                                         8/9 
  Verifying  : libkadm5-1.15.1-8.el7.x86_64                                                                                                                                                                9/9 

Installed:
  openssl-devel.x86_64 1:1.0.2k-8.el7                                                                     zlib-devel.x86_64 0:1.2.7-17.el7                                                                    

Dependency Installed:
  keyutils-libs-devel.x86_64 0:1.5.8-3.el7     krb5-devel.x86_64 0:1.15.1-8.el7        libcom_err-devel.x86_64 0:1.42.9-10.el7     libkadm5.x86_64 0:1.15.1-8.el7     libselinux-devel.x86_64 0:2.5-11.el7    
  libsepol-devel.x86_64 0:2.5-6.el7            libverto-devel.x86_64 0:0.2.5-4.el7    

Complete!

3、创建软件配套专用的用户(禁止登录及不创建家目录)

[root@localhost ~]# useradd www -s /sbin/nologin  -M

4、进入/usr/src目录下载并解压软件包

[root@localhost src]# cd /usr/src/
[root@localhost src]# wget http://nginx.org/download/nginx-1.12.2.tar.gz && tar -zxf nginx-1.12.2.tar.gz
--2018-03-02 13:05:56--  http://nginx.org/download/nginx-1.12.2.tar.gz
Resolving nginx.org (nginx.org)... 206.251.255.63, 95.211.80.227, 2606:7100:1:69::3f, ...
Connecting to nginx.org (nginx.org)|206.251.255.63|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 981687 (959K) [application/octet-stream]
Saving to: ‘nginx-1.12.2.tar.gz’

100%[=====================================================================================================================================================================>] 981,687     8.26KB/s   in 2m 10s 

2018-03-02 13:08:07 (7.36 KB/s) - ‘nginx-1.12.2.tar.gz’ saved [981687/981687]

5、进入解压的软件目录并编译配置文件 ./configure –user=www –group=www –prefix=/usr/local/nginx-1.12.2 –with-mail_ssl_module –with-http_stub_status_module –with-http_ssl_module –with-http_v2_module –with-http_gzip_static_module –with-http_sub_module

[root@localhost src]# cd nginx-1.12.2
[root@localhost nginx-1.12.2]# ./configure --user=www --group=www --prefix=/usr/local/nginx-1.12.2 --with-mail_ssl_module --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module
checking for OS
 + Linux 3.10.0-327.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
......此处省略......
checking for PCRE library ... found
checking for PCRE JIT support ... found
checking for OpenSSL library ... found
checking for zlib library ... found
creating objs/Makefile

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/local/nginx-1.12.2"
  nginx binary file: "/usr/local/nginx-1.12.2/sbin/nginx"
  nginx modules path: "/usr/local/nginx-1.12.2/modules"
  nginx configuration prefix: "/usr/local/nginx-1.12.2/conf"
  nginx configuration file: "/usr/local/nginx-1.12.2/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx-1.12.2/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx-1.12.2/logs/error.log"
  nginx http access log file: "/usr/local/nginx-1.12.2/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp

6、编译及安装软件

[root@localhost nginx-1.12.2]# make && make install
make -f objs/Makefile
make[1]: Entering directory `/usr/src/nginx-1.12.2'
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs 
        -o objs/src/core/nginx.o 
        src/core/nginx.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs 
        -o objs/src/core/ngx_log.o 
        src/core/ngx_log.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs 
        -o objs/src/core/ngx_palloc.o 
        src/core/ngx_palloc.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs 
        -o objs/src/core/ngx_array.o 
        src/core/ngx_array.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs 
        -o objs/src/core/ngx_list.o 
        src/core/ngx_list.c
......此处省略......
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I src/http/v2 
        -o objs/src/http/modules/ngx_http_upstream_least_conn_module.o 
        src/http/modules/ngx_http_upstream_least_conn_module.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I src/http/v2 
        -o objs/src/http/modules/ngx_http_upstream_keepalive_module.o 
        src/http/modules/ngx_http_upstream_keepalive_module.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I src/http/v2 
        -o objs/src/http/modules/ngx_http_upstream_zone_module.o 
        src/http/modules/ngx_http_upstream_zone_module.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I src/http/v2 
        -o objs/src/http/modules/ngx_http_stub_status_module.o 
        src/http/modules/ngx_http_stub_status_module.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs 
        -o objs/ngx_modules.o 
        objs/ngx_modules.c
cc -o objs/nginx 
objs/src/core/nginx.o 
objs/src/core/ngx_log.o 
objs/src/core/ngx_palloc.o 
objs/src/core/ngx_array.o 
objs/src/core/ngx_list.o 
......此处省略......
objs/src/http/modules/ngx_http_upstream_least_conn_module.o 
objs/src/http/modules/ngx_http_upstream_keepalive_module.o 
objs/src/http/modules/ngx_http_upstream_zone_module.o 
objs/src/http/modules/ngx_http_stub_status_module.o 
objs/ngx_modules.o 
-ldl -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lz 
-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/nginx-1.12.2|" 
        -e "s|%%PID_PATH%%|/usr/local/nginx-1.12.2/logs/nginx.pid|" 
        -e "s|%%CONF_PATH%%|/usr/local/nginx-1.12.2/conf/nginx.conf|" 
        -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx-1.12.2/logs/error.log|" 
        < man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/usr/src/nginx-1.12.2'
make -f objs/Makefile install
make[1]: Entering directory `/usr/src/nginx-1.12.2'
test -d '/usr/local/nginx-1.12.2' || mkdir -p '/usr/local/nginx-1.12.2'
test -d '/usr/local/nginx-1.12.2/sbin' 
        || mkdir -p '/usr/local/nginx-1.12.2/sbin'
test ! -f '/usr/local/nginx-1.12.2/sbin/nginx' 
        || mv '/usr/local/nginx-1.12.2/sbin/nginx' 
                '/usr/local/nginx-1.12.2/sbin/nginx.old'
cp objs/nginx '/usr/local/nginx-1.12.2/sbin/nginx'
test -d '/usr/local/nginx-1.12.2/conf' 
        || mkdir -p '/usr/local/nginx-1.12.2/conf'
cp conf/koi-win '/usr/local/nginx-1.12.2/conf'
cp conf/koi-utf '/usr/local/nginx-1.12.2/conf'
cp conf/win-utf '/usr/local/nginx-1.12.2/conf'
test -f '/usr/local/nginx-1.12.2/conf/mime.types' 
        || cp conf/mime.types '/usr/local/nginx-1.12.2/conf'
cp conf/mime.types '/usr/local/nginx-1.12.2/conf/mime.types.default'
test -f '/usr/local/nginx-1.12.2/conf/fastcgi_params' 
        || cp conf/fastcgi_params '/usr/local/nginx-1.12.2/conf'
cp conf/fastcgi_params 
        '/usr/local/nginx-1.12.2/conf/fastcgi_params.default'
test -f '/usr/local/nginx-1.12.2/conf/fastcgi.conf' 
        || cp conf/fastcgi.conf '/usr/local/nginx-1.12.2/conf'
cp conf/fastcgi.conf '/usr/local/nginx-1.12.2/conf/fastcgi.conf.default'
test -f '/usr/local/nginx-1.12.2/conf/uwsgi_params' 
        || cp conf/uwsgi_params '/usr/local/nginx-1.12.2/conf'
cp conf/uwsgi_params 
        '/usr/local/nginx-1.12.2/conf/uwsgi_params.default'
test -f '/usr/local/nginx-1.12.2/conf/scgi_params' 
        || cp conf/scgi_params '/usr/local/nginx-1.12.2/conf'
cp conf/scgi_params 
        '/usr/local/nginx-1.12.2/conf/scgi_params.default'
test -f '/usr/local/nginx-1.12.2/conf/nginx.conf' 
        || cp conf/nginx.conf '/usr/local/nginx-1.12.2/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx-1.12.2/conf/nginx.conf.default'
test -d '/usr/local/nginx-1.12.2/logs' 
        || mkdir -p '/usr/local/nginx-1.12.2/logs'
test -d '/usr/local/nginx-1.12.2/logs' 
        || mkdir -p '/usr/local/nginx-1.12.2/logs'
test -d '/usr/local/nginx-1.12.2/html' 
        || cp -R html '/usr/local/nginx-1.12.2'
test -d '/usr/local/nginx-1.12.2/logs' 
        || mkdir -p '/usr/local/nginx-1.12.2/logs'
make[1]: Leaving directory `/usr/src/nginx-1.12.2'

7、创建软链接

[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx-1.12.2/ /usr/local/nginx

8、检查Nginx配置文件语法

[root@localhost nginx-1.12.2]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.12.2/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.12.2/conf/nginx.conf test is successful

9、把Nginx服务添加进启动自定义文件内并启动Nginx软件

echo "/usr/local/nginx/sbin/nginx" >>/etc/rc.local && /usr/local/nginx/sbin/nginx

10、检查端口情况判断Nginx软件是否运行正常

[root@localhost nginx-1.12.2]# ss -lnat|grep 80
LISTEN     0      128          *:80                       *:*

Web访问验证

未分类

调整参数

1、当我们安装完Nginx程序后首先有几个参数需要调整下,需要调整的参数为user、worker_processes、worker_connections;Nginx主配置文件位于/usr/local/nginx/conf目录下的nginx.conf

[root@localhost conf]# vim nginx.conf

user  www www;    #指定运行Worker进程的用户和组,根据编译安装时指定的用户及组修改,默认为nobody;例如:user www www;
worker_processes  auto;    #常规调优选项 Worker线程的个数;通常应该为物理CPU核心个数减1;自动为auto

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  51200;    #常规调优选项 设定单个Worker进程所能够处理响应的最大并发请求数(worker_connections * worker_processes);默认为1024,建议为51200,最大为65535。
}

2、调整参数后验证配置文件是否有误

[root@localhost conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.12.2/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.12.2/conf/nginx.conf test is successful

3、重新加载配置文件或重启系统均可

[root@localhost conf]# /usr/local/nginx/sbin/nginx -s reload

在CentOS 7系统上安装PostGIS的方法

本文介绍在CentOS 7系统上安装PostGIS的方法。

简介

PostGIS是一个PostgreSQL数据库扩展,它允许GIS(地理信息系统)对象存储在数据库中。

PostGIS包括对基于GiST的R-Tree空间索引的支持,以及用于分析和处理GIS对象的功能,它是一种根据知识共享署名,相同方式共享3.0许可证授权的开源软件。

一、安装PostgreSQL数据库参考文章

PostgreSQL是usinf PostGIS功能的依赖项,需要安装PostgreSQL,参考在CentOS 7系统上安装PostgreSQL 11的步骤

二、将EPEL存储库添加到CentOS 7

EPEL存储库中有许多依赖项,运行以下命令在CentOS 7计算机中安装epel存储库:

sudo yum -y install epel-release

三、在CentOS 7上安装PostGIS

安装PostgreSQL并添加EPEL存储库后,继续从添加的PostgreSQL安装PostGIS,使用如下命令添加存储库:

sudo yum install https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm

然后通过运行以下命令在CentOS 7上安装PostGIS:

sudo yum install postgis25_11

这将为PostgreSQL 11安装PostGIS v2.5,可以使用以下命令检查安装的版本:

$ rpm -qi postgis25_11

返回的信息如下图:

未分类

根据上图的信息得出,安装的版本是PostGIS 2.5.1。

四、启用PostGIS Spatial功能

你需要先激活数据库上的PostGIS功能,然后才能存储空间数据,下面的示例将向你展示如何创建数据库并激活Spacial功能。

1.切换到postgres用户

sudo -i -u postgres

2.创建测试用户/数据库

-bash-4.2$ createuser test_user

-bash-4.2$ createdb test_db -O test_user

3.连接到测试数据库

-bash-4.2$ psql -d test_db

psql (11.2)

Type "help" for help.

4.在数据库上启用PostGIS扩展

test_db=# CREATE EXTENSION postgis;

CREATE EXTENSION

5.验证

test_db=# SELECT PostGIS_version();

postgis_version            

2.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1

(1 row)

test_db=# q

CentOS 7.0关闭默认防火墙启用iptables防火墙

操作系统环境:CentOS Linux release 7.0.1406(Core) 64位
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤。

1. 关闭firewall:

systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

2. iptables防火墙(这里iptables已经安装,下面进行配置)

  • 编辑防火墙配置文件
vi /etc/sysconfig/iptables

这里使用80和8080端口为例。

    # sampleconfiguration for iptables service
    # you can edit thismanually or use system-config-firewall
    # please do not askus to add additional ports/services to this default configuration
    *filter
    :INPUT ACCEPT [0:0]
    :FORWARD ACCEPT[0:0]
    :OUTPUT ACCEPT[0:0]
    -A INPUT -m state--state RELATED,ESTABLISHED -j ACCEPT
    -A INPUT -p icmp -jACCEPT
    -A INPUT -i lo -jACCEPT
    -A INPUT -p tcp -mstate --state NEW -m tcp --dport 22 -j ACCEPT
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -jACCEPT
    -A INPUT -p tcp -m state --state NEW -m tcp --dport 8080-j ACCEPT
    -A INPUT -j REJECT--reject-with icmp-host-prohibited
    -A FORWARD -jREJECT --reject-with icmp-host-prohibited
    COMMIT
  • 保存退出
    :wq!

备注:

一般添加到“-A INPUT -p tcp -m state –state NEW -m tcp–dport 22 -j ACCEPT”行的上面或者下面,切记不要添加到最后一行,否则防火墙重启后不生效。

systemctl restart iptables.service #最后重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动

CentOS 7 解决丢失 nginx.pid

导语

上一篇文章中,已经将 Nginx 编译安装完成。重启服务器之后,再次开启 Nginx 服务的时候出错了,错误信息如下

未分类

解决错误

出现错误就要解决错误。从上图中可以看出,错误原因是缺少 nginx.pid 这个文件,这个文件中的内容只有一行,记录的是相应进程的 pid,即进程号。
解决的方法是输入 ./nginx -c /usr/local/nginx/conf/nginx.conf 重新设置配置文件

未分类

CentOS 7 时区设置

设置时区同样, 在 CentOS 7 中, 引入了一个叫 timedatectl 的设置设置程序.
用法很简单:

timedatectl # 查看系统时间方面的各种状态

$timedatectl status
Local time: 四 2014-12-25 10:52:10 CST
Universal time: 四 2014-12-25 02:52:10 UTC
RTC time: 四 2014-12-25 02:52:10
Timezone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
timedatectl list-timezones # 列出所有时区
timedatectl set-local-rtc 1 # 将硬件时钟调整为与本地时钟一致, 0 为设置为 UTC 时间
timedatectl set-timezone Asia/Shanghai # 设置系统时区为上海

其实不考虑各个发行版的差异化, 从更底层出发的话, 修改时间时区比想象中要简单:

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

CentOS 7上Apache配置SSL证书

未分类

Certbot配置SSL证书

Certbot是让vultr加密认证中心的自动SSL证书颁发者。它被开发为让vps加密的客户端,并且还将与支持ACME协议的任何其他CA协同工作。

接下来将介绍在CentOS 7上的Apache安装Certbot的过程,并配置它发布和续订我们加密SSL证书。

1. 安装

Certbot在EPEL Yum Repository上可用。如果没有安装EPEL,可以使用以下命令安装:

# yum -y install epel-release mod_ssl openssl

接下来,我们将需要安装Certbot及其Apache插件

# yum -y install certbot python-certbot-apache

运行Certbot:

# certbot --apache

为了避免错误,请确保已为希望使用SSL证书的域和DNS配置正确的域设置了虚拟主机。(像我一样,略过)

运行Certbot Apache Plugin后,会出现一个安装向导。可配置选项包括邮箱,域名,订阅,看不懂英文的可复制到Google翻译,以免出错。

  • 选择要颁发证书的域名(注意:www.example.com和example.com将分发SSL证书)。
  • SSL强制选项。

本站配置ssl时没有输入通配符www,如果加入www访问,会提示https不安全 https://www.toavoid.cc,不加www即可。
当然你也可以选择输入www如www.toavoid.cc,配置ssl完毕之后在后台设置为域名加上www即可。已加上的略过。

2. 自动续订

加密证书90天后过期。Certbot可以轻松处理自动续订。

# certbot renew --dry-run

# certbot renew --quiet

现在打开网站发现https已经生效

未分类

如果出现不安全,确认是否在后台设置域名通配符,我这里没设置~

未分类