2018年6月

LNMP1.5安装工具

wget http://soft.vpser.net/lnmp/lnmp1.5.tar.gz -cO lnmp1.5.tar.gz && tar zxf lnmp1.5.tar.gz && cd lnmp1.5 && ./install.sh lnmp

如果需要安装LAMP或者LNMPA 需要把上面的lnmp改为lamp或者lnmpa 如需更改网站和数据库目录、自定义Nginx参数、PHP参数模块、开启lua等需在运行./install.sh 命令前修改安装包目录下的 lnmp.conf 文件

如提示wget: command not found ,使用yum install wget 或 apt-get install wget 命令安装。
1.
You have 10 options for your DataBase install.
1: Install MySQL 5.1.73
2: Install MySQL 5.5.60 (Default)
3: Install MySQL 5.6.40
4: Install MySQL 5.7.22
5: Install MySQL 8.0.11
6: Install MariaDB 5.5.60
7: Install MariaDB 10.0.35
8: Install MariaDB 10.1.33
9: Install MariaDB 10.2.14
0: DO NOT Install MySQL/MariaDB
Enter your choice (1, 2, 3, 4, 5, 6, 7, 8, 9 or 0):
目前提供了较多的MySQL、MariaDB版本和不安装数据库的选项,需要注意的是MySQL 5.6,5.7及MariaDB 10必须在1G以上内存的更高配置上才能选择!如仅需安装数据库在lnmp安装包目录下执行:./install.sh db
2.
Please setup root password of MySQL.
Please enter:
输入root的密码

3.
Do you want to enable or disable the InnoDB Storage Engine?
Default enable,Enter your choice [Y/n]:
询问是否需要启用MySQL InnoDB,InnoDB引擎默认为开启,一般建议开启,直接回车或输入 y ,如果确定确实不需要该引擎可以输入 n,(MySQL 5.7+版本无法关闭InnoDB),输入完成,回车进入下一步。
4.
You have 8 options for your PHP install.
1: Install PHP 5.2.17
2: Install PHP 5.3.29
3: Install PHP 5.4.45
4: Install PHP 5.5.38
5: Install PHP 5.6.36 (Default)
6: Install PHP 7.0.30
7: Install PHP 7.1.18
8: Install PHP 7.2.6
Enter your choice (1, 2, 3, 4, 5, 6, 7 or 8):
注意:选择PHP 7+版本时需要自行确认PHP版本是否与自己的程序兼容。

5.
You have 3 options for your Memory Allocator install.
1: Don't install Memory Allocator. (Default)
2: Install Jemalloc
3: Install TCMalloc
Enter your choice (1, 2 or 3):
可以选择不安装、Jemalloc或TCmalloc,输入对应序号回车,直接回车为默认为不安装。
(如果是LNMPA或LAMP的话还会提示设置邮箱和选择Apache“Please enter Administrator Email Address:”,需要设置管理员邮箱,该邮箱会在报错时显示在错误页面上。)

6.
提示"Press any key to install...or Press Ctrl+c to cancel"后,按回车键确认开始安装。
LNMP脚本就会自动安装编译Nginx、MySQL、PHP、phpMyAdmin等软件及相关的组件。

安装时间可能会几十分钟到几个小时不等,主要是机器的配置网速等原因会造成影响。

| phpMyAdmin: http://IP/phpmyadmin/ |
| phpinfo: http://IP/phpinfo.php |

Prober: http://IP/p.php
Add VirtualHost: lnmp vhost add
Default directory: /home/wwwroot/default
MySQL/MariaDB root password:
Manager for LNMP, Written by Licess
https://lnmp.org

提示这个框 则安装完成

7.
进入lnmp安装包解压目录,执行“./pureftpd.sh”安装FTP服务器。
cd lnmp1.4 进入lnmp1.4文件夹
./pureftpd.sh 安装FTP服务器

安装完成。FTP管理命令如下:
lnmp ftp add 添加FTP账号
lnmp ftp list FTP列表
lnmp ftp del 删除FTP账号

第二部分添加网站(创建虚拟主机)及安装SSL证书:

1、执行“lnmp vhost add”添加虚拟主机。提示需先安装FTP服务器,才会在创建虚拟主机时提示创建FTP账号,如果没有安装将不提示创建。

lnmp vhost add

[root@city ~]# lnmp vhost add
Manager for LNMP, Written by Licess
https://lnmp.org

Please enter domain(example: www.lnmp.org): 你的域名
Your domain: 你的域名
Enter more domain name(example: lnmp.org *.lnmp.org): 备用域名
domain list: 备用域名
Please enter the directory for the domain: 你的域名
Default directory: /home/wwwroot/你的域名: 网站目录设置
Virtual Host Directory: 网站目录设置
Allow Rewrite rule? (y/n) 静态设置
You choose rewrite:
Enable PHP Pathinfo? (y/n) PHP优化
Allow access log? (y/n) 是否创建日志文件
Enter access log filename(Default:你的域名.log): 日志创建
You access log filename: 日志创建.log
Create database and MySQL user with same name (y/n) 是否创建你的数据库
Add SSL Certificate (y/n) 是否创建SSL

然后按任意键即可创建完成

自动安装Let’s Encrypt证书,由于Let’s Encrypt有效期只有三个月,所以最好是设置一个定时更新证书的任务。,我们执行命令“crontab -e”,可以查看到已经自动添加好证书更新任务。如果没有的可以按下面命令执行添加,7天自动更新一次。

crontab -e
0 3 */7 * * /bin/certbot renew --renew-hook "/etc/init.d/nginx reload"

关于自动安装Let’s Encrypt证书生成的Key与PEM证书路径是:/etc/letsencrypt/live/1994.ml/,可以在这里查看到,以后更新证书就是在这个文件夹。

安装完成后编辑/usr/local/nginx/conf/vhost/找到你站点的.conf

server {
listen 80;
#server_name 1994.ml; #这个域名是你自己的域名,请行修改 但是测试 这行需要注释掉才能开启
rewrite ^/(.*) https://1994.ml/$1 permanent; #这个域名是你自己的域名,请行修改
}

第三步LNMP一键安装包相关管理命令:

命令使用方法,在虚拟主机管理命令lnmp vhost {add|list|del}中,如果我们要添加虚拟主机就执行“lnmp vhost add”,删除虚拟主机就执行“lnmp vhost del”。

名词解释:start开始、stop停止、reload重装、restart重启、kill杀、status状态、add添加、list列表、edit编辑、del删除、show显示。

LNMP状态管理:lnmp {start|stop|reload|restart|kill|status}
LNMP各个程序的状态管理:lnmp {nginx|mysql|mariadb|php-fpm|pureftpd {start|stop|reload|restart|kill|status}
虚拟主机管理:lnmp vhost {add|list|del}
数据库管理:lnmp database list{add|list|edit|del}
FTP用户管理:lnmp ftp {add|list|edit|del|show}
SSL添加:lnmp ssl add

采摘自 https://www.wn789.com/3812.html && https://lnmp.org/

1.用root用户登入

1.1.进入谷歌云实例面板

1.2.切换到root角色

sudo -i

1.3.修改SSH配置文件/etc/ssh/sshd_config

vi /etc/ssh/sshd_config


# Authentication:
PermitRootLogin yes //默认为no,需要开启root用户访问改为yes

# Change to no to disable tunnelled clear text passwords
PasswordAuthentication yes //默认为no,改为yes开启密码登陆

或者

CentOS和Debian通用,输入以下两条命令

sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config

sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config

Ubuntu系统,输入以下两条命令

sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config

sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config





1.4.给root用户设置密码

passwd root

1.5.重启SSH服务使修改生效

/etc/init.d/ssh restart

原文 https://blog.csdn.net/datadev_sh/article/details/79593360

第一步 - 添加Nginx存储库
要添加CentOS 7 EPEL仓库,请打开终端并使用以下命令:

sudo yum install epel-release
第二步 - 安装Nginx
现在Nginx存储库已经安装在您的服务器上,使用以下yum命令安装Nginx :

sudo yum install nginx
在对提示回答yes后,Nginx将在服务器上完成安装。

第三步 - 启动Nginx
Nginx不会自行启动。要运行Nginx,请输入:

sudo systemctl start nginx

原文链接https://blog.csdn.net/oldguncm/article/details/78855000

一.升级openssl

如果系统的openssl版本较低,比如低于 1.0.2 ,先升级下
1.安装必要软件

yum install gcc gcc-c++ autoconf automake zlib zlib-devel pcre-devel 

2.获取新版openssl,并解压

wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz
tar -zxvf openssl-1.0.2l.tar.gz

3.编译安装

cd openssl-1.0.2l
./config
make && make install

4.移除旧版本 OpenSSL

mv /usr/bin/openssl /tmp/
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl

5.检查是否为新版本了

# openssl version   
OpenSSL 1.0.2l  25 May 2017

二.升级nginx

通过yum安装的nginx版本虽然支持http2了,但由于使用的openssl版本还是低版本,所以要重新编译安装下
1.准备必要工具

yum -y install libxml2 libxml2-devel libxslt-devel gd-devel perl-devel perl-ExtUtils-Embed GeoIP GeoIP-devel GeoIP-data gperftools-devel

2.获取新的nginx,并解压

wget https://nginx.org/download/nginx-1.13.3.tar.gz
tar zxvf nginx-1.13.3.tar.gz

3.配置编译项

./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-openssl=../openssl-1.0.2l

这里注意下,最后的--with-openssl指向的是刚才解压的openssl那个路径
如果遇到某个错误无法完成,google下这个错误,安装相应的依赖后再次configure

4.编译安装

make 
make install

5.查看下是否是新版本了

nginx -V

三.获取ssl证书

ssl证书分免费和收费的,看自己的需求。免费的国内云主机厂商基本都会提供,我这次使用阿里云的。
步骤如下:

登录:阿里云控制台,产品与服务,证书服务,购买证书。
购买:证书类型选择 免费型DV SSL,然后完成购买。
补全:在 我的证书 控制台,找到购买的证书,在操作栏里选择 补全。填写证书相关信息。
域名验证:可以选择 DNS,如果域名用了阿里云的 DNS 服务,再勾选一下 证书绑定的域名在 阿里云的云解析。
上传:系统生成 CSR,点一下 创建。
提交审核。
如果一切正常,10 分钟左右,申请的证书就会审核通过。

审核通过后,将证书导出,并上传到nginx服务器上,放到nginx对应目录下,比如cert目录

mkdir /etc/nginx/cert 


参考:https://ninghao.net/blog/4449

四.配置nginx

关键配置文件如下,注意替换下相应的参数

server {
        #开启HSTS
        add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
        listen 443 ssl http2 default_server;
        server_name xiaoxiaoguo.cn www.xiaoxiaoguo.cn; #这里替换成实际的域名
        ssl on;
        ssl_certificate   cert/214212024460825.pem; #注意证书名称
        ssl_certificate_key  cert/214212024460825.key;#注意证书名称
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
}

五.启用新配置,并验证

systemctl reload nginx


本文转自https://blog.csdn.net/u012375924/article/details/76439505?locationNum=4&fps=1

yum install zlib-devel    #error: mod_deflate 
yum install openssl-devel    #error: mod_ssl

1.安装前期编译准备

wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.3.tar.gz
tar -zxvf apr-1.6.3.tar.gz
cd apr-1.6.3
./configure --prefix=/usr/local/apr
make && make install

cd ..
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-iconv-1.2.2.tar.gz
tar -zxvf apr-iconv-1.2.2.tar.gz
cd apr-iconv-1.2.2  
./configure --prefix=/usr/local/apr-iconv --with-apr=/usr/local/apr  
make && make install

cd ..
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz  
tar -zxvf apr-util-1.6.1.tar.gz  
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
make && make install

cd ..
wget https://ftp.pcre.org/pub/pcre/pcre-8.33.tar.gz
tar -zxvf pcre-8.33.tar.gz
cd pcre-8.33
./configure --prefix=/usr/local/pcre
make && make install

下载Apache2.4.33

wget http://www.apache.org/dist/httpd/httpd-2.4.33.tar.gz
tar -zxvf httpd-2.4.33.tar.gz
cd httpd-2.4.33
 ./configure --prefix=/usr/local/apache --enable-rewrite --enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre/ --enable-ssl --enable-deflate --enable-expires --with-mpm=event 
make && make install

cd ..
yum -y install epel-release   #安装源文件支持包
yum install libnghttp2-devel   #安装mod_http2模块

cd httpd-2.4.33
./configure --enable-http2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre/
./configure --with-nghttp2=/var/www/html  --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre/
./configure  --enable-nghttp2-staticlib-deps --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre/
make && make install 

编译OpenSSL

wget http://www.openssl.org/source/openssl-1.0.2j.tar.gz
tar -xzf openssl-1.0.2j.tar.gz
cd openssl-1.0.2j
./config --prefix=/usr/local/openssl
./config -t
make && make install