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/Debian/Ubuntu系统 TCP-BBR 一键安装脚本

其他BBR一键脚本:『逗比』Debian/Ubuntu系统 TCP拥塞控制技术 ——TCP-BBR 一键安装脚本

本脚本适用环境

系统支持:CentOS 6+,Debian 7+,Ubuntu 12+

虚拟技术:OpenVZ 以外的(KVM、Xen、VMware等)

内存要求:≥128M

日期  :2017 年 01 月 13 日

关于本脚本

  • 本脚本已在 Vultr 上的 VPS 全部测试通过。
  • 当脚本检测到 VPS 的虚拟方式为 OpenVZ 时,会提示错误,并自动退出安装。
  • 某些服务商(如 Linode、DigitalOcean)可能需要首先将 VPS 配置为可自定义内核,然后 grub2 的配置才会生效。
  • 脚本运行完重启发现开不了机的,打开 VPS 后台控制面板的 VNC, 开机卡在 grub 引导, 手动选择内核即可。
  • 由于是使用最新版系统内核,最好请勿在生产环境安装,以免产生不可预测之后果。

使用方法

使用root用户登录,运行以下命令:

wget -N --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh && chmod +x bbr.sh && bash bbr.sh

安装完成后,脚本会提示需要重启 VPS,输入 y 并回车后重启。

重启完成后,进入 VPS,验证一下是否成功安装最新内核并开启 TCP BBR,输入以下命令:

uname -r
# 查看内核版本,含有 4.9.0 就表示 OK 了
# ————————————
sysctl net.ipv4.tcp_available_congestion_control
# 返回值一般为:
# net.ipv4.tcp_available_congestion_control = bbr cubic reno
# ————————————
sysctl net.ipv4.tcp_congestion_control
# 返回值一般为:
# net.ipv4.tcp_congestion_control = bbr
# ————————————
sysctl net.core.default_qdisc
# 返回值一般为:
# net.core.default_qdisc = fq
# ————————————
lsmod | grep bbr
# 返回值有 tcp_bbr 模块即说明bbr已启动。

参考链接

更新日志

2017 年 01 月 13 日

1.更新 内核为 4.9.3。

2017 年 01 月 09 日

1.更新 内核为 4.9.1。

在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和ubuntu安装卸载软件(rpm/dpkg)

使用Linux系统,无论是Centos/RHEL/Fedoar系列还是Ubuntu/debian系列,都有独立的包管理体系,在Centos系列,使用rpm包进行软件安装配置管理,在Ubuntu系列,使用deb包进行软件安装配置管理

CentOS:

centos使用yum做自动化包管理,包格式为rpm包,常用命令有:

yum search xxx
yum install xxx
yum groupinstall  "xxx" //以组形式安装软件包组合

直接安装rpm

rpm -ivh xxx.rpm --force (--force表示强制安装)

直接卸载rpm

rpm -e xxx.rpm

查看包内容:

rpm -l xxx.rpm

查看一个文件在哪个rpm包:

rpm -f 文件名

查看系统安装哪些rpm

rpm -qa

Ubuntu:

Ubuntu使用apt做自动化包管理,包格式为deb,常用命令有:

apt-cache search xxx
apt-get install xxx
apt-get remote xxx

直接安装deb包:

dpkg -i xxx.deb

列出包关联:

dpkg -L xxx.deb

显示包版本

dpkg -l xxx.deb

查看系统安装哪些deb包

dpkg -l

卸载包

dpkg -P xxx   //全部卸载,  dpkg -r xxx 只卸载软件,保留配置

显示包信息

dpkg -s xxx

显示包文件

dpkg -L ovmf 
dpkg -c xxx.deb
dpkg-deb -c xxx.deb

查看一个文件在哪个deb包:

dpkg -S 文件

JDK的安装[Centos]

##JDK

给所有用户添加可执行权限

chmod +x jdk-****.rpm

或者直接放掉所有权限

chmod 777 jdk-****.rpm

开始安装程序

rpm -ivh jdk-8u45-linux-x64.rpm

配置环境变量

vi /etc/profile  
export JAVA_HOME=/usr/java/jdk1.*.*_**
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

保存设置并生效

source /etc/profile

例:

jdk-8u131-linux-x64.rpm 我们从Oracle的官网下载了JDK1.8的安装包,我们安装它  

推荐使用

yum localinstall jdk-8u131-linux-x64.rpm

也可以

rpm -ivh jdk-8u131-linux-x64.rpm

这样安装完成之后可以不用修改环境变量

如何测试?

  • 执行 java -version 查看JDK版本
  • 执行 java 测试java命令是否好用和支持的参数列表
  • 执行 javac 测试java编译器是否好用

CentOS 更新 yum 源

设置yum源

将yum源设置为国内yum源,可以提升软件包安装和更新的速度,同时避免一些常见软件版本无法找到。 国内源:可以使用wget获取或者直接下载

1.网易:

2.中科大的yum源:

3.sohu的yum源:

安装步骤

1.首先备份CentOS-Base.repo

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2.下载对应版本的CentOS-Base.repo, 放入/etc/yum.repos.d/ (可以直接cd /etc/yum.repos.d/ 然后使用wget下载)

3.运行以下命令生成缓存

yum clean all
yum makecache

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 #设置防火墙开机启动

CentOS7 安装 MySQL

系统环境

centOS7.5 64位

开始部署

1. 添加mysql yum源

在centOS上直接使用yum install mysql安装,最后安装上的会是MariaDB,所以要先添加mysql yum

rpm -Uvh https://repo.mysql.com//mysql80-community-release-el7-2.noarch.rpm

2. 安装(如果要安装最新版,可直接开始安装)

查看yum源中所有Mysql版本

yum repolist all | grep mysql

此时的最新版本是mysql8.0,把它禁用掉

yum-config-manager --disable mysql80-community

mysql5.7是我要安装的版本,启用mysql5.7

yum-config-manager --enable mysql57-community

检查刚才的配置是否生效

yum repolist enabled | grep mysql

开始安装

yum install mysql-community-server

3. 启动服务

service mysqld start

启动完成之后检查mysql状态,

service mysqld status

查看临时密码

grep 'temporary password' /var/log/mysqld.log

登录

mysql -uroot -p