lnmp
来源:互联网 发布:汽车行业制图软件 编辑:程序博客网 时间:2024/06/07 15:25
lamp架构
LAMP指的Linux(操作系统)、ApacheHTTP 服务器,MySQL(有时也指MariaDB,数据库软件) 和PHP(有时也是指Perl或Python) 的第一个字母,一般用来建立web应用平台。
l —> linux unix windows
a —> apache nginx iis
m —> mysql mariadb percona postgressql oracle
p —> php jsp xml python -> django falsk tornador css js api
lnmp架构
LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构
nginx基本配置
安装:
(1)server1:
tar zxf nginx-1.12.0.tar.gz ##解压包
cd nginx-1.12.0/
useradd -M -d /usr/local/lnmp/nginx -s /sbin/nologin -u 800 nginx ##创建用户,-M指定家目录
id nginx
##需要的模块
yum install pcre-devel
yum install -y openssl-devel
cd nginx-1.12.0/src/core/
vim nginx.h
#define NGINX_VER "nginx"
nginx-1.12.0/auto/cc/gcc
##源码编译cd nginx-1.12.0/ ./configure \--prefix=/usr/local/lnmp/nginx \--user=nginx \--group=nginx \--with-threads \--with-file-aio \--with-http_ssl_module \--with-http_stub_status_module
make && make install ##安装
/usr/local/lnmp/nginx/sbin/nginx ##启动nginx
ln /usr/local/lnmp/nginx/sbin/nginx /bin/nginx ##创建链接
测试:
curl -I localhost
nginx绑定cpu
vim /usr/local/lnmp/nginx/conf/nginx.conf ##nginx主配置文件
worker_processes 2; ##进程数worker_cpu_affinity 01 10; ##cpu绑定,01 10 表示第一二块cpu,必须符合物理cpu数目events { worker_connections 65535; ##最大连接数}
vim /etc/security/limits.conf
nginx - nofile 65535
lscpu ##查看cpu
sysctl -a | grep file ##查看系统最大连接数
nginx -t ##检测nginx配置文件的语法是否正确
nginx -s reload ##nginx重新加载
测试:
[root@server1 conf]# usermod -s /bin/bash nginx
[root@server1 conf]# su - nginx
-bash-4.1$ ulimit -a
open files (-n) 65535 ##打开的文件数变为65535
nginx虚拟主机
vim /usr/local/lnmp/nginx/conf/nginx.conf
http {server { listen 80; server_name www.westos.org; location / { root /web1; index index.html; }}}
mkdir /web1 ##建立发布目录
vim /web1/index.html ##编辑发布页面
nginx -s reload ##重新加载
测试:
浏览器访问
www.westos.org –> 虚拟主机发布页
172.25.32.1 –> nginx默认发布页
nginx证书
vim /usr/local/lnmp/nginx/conf/nginx.conf
# HTTPS server # server { listen 443 ssl; server_name localhost; ssl_certificate cert.pem; ##cert.pem证书 ssl_certificate_key cert.pem; ##cert.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; } }
##redhat6版本生成证书/etc/pki/tls/certs
cd /etc/pki/tls/certs ##可以查看该目录下的Makefile查看生成证书的指令
make cert.pem ##生成pem证书
##证书内容填写
##国家 省 市 公司 主机 邮箱
mv cert.pem /usr/local/lnmp/nginx/conf/
nginx -t
nginx -s reload
测试:
浏览器访问
https://172.25.32.1/
监控
vim /usr/local/lnmp/nginx/conf/nginx.conf ##编辑主配置文件
#access_log logs/host.access.log main; location / { root html; index index.html index.htm; } location /status { stub_status on; ##打开监控 access_log off; ##日志关闭 allow 127.0.0.1; ##允许本机 deny all; ##拒绝其他 } #error_page 404 /404.html;
nginx -t ##检查语法
nginx -s reload ##重新加载
测试:
本机 -> crul localhost/status
其他 -> crul http://172.25.32.1/status
当其他主机查看时,显示403禁止
网页重写
vim /usr/local/lnmp/nginx/conf/nginx.conf
location / { root /web1; index index.html index.htm; } }server { listen 80; server_name www.westos.org; rewrite ^(.*)$ https://www.westos.org$1 redirect;##重写,redirect302临时,permanent永久301 }}
nginx -t
nginx -s reload
测试:
浏览器 www.westos.org -> https://…
mkdir /web1/admin
vim /web1/admin/index.html
浏览器 www.westos.org/admin -> https://…
负载均衡 反向代理
502 apache服务关闭
5 种算法 :
轮询 权重 ip_hash 第三方..
server1:
vim /usr/local/lnmp/nginx/conf/nginx.conf
http { upstream westos { #ip_hash server 172.25.32.2:80;##权重weigth 2,默认3 server 172.25.32.3:8080; server 127.0.0.1:8000 backup; ##backup表示当2和3都无法启用时,才启用 }server { listen 80; server_name www.westos.org; #rewrite ^(.*)$ https://www.westos.org$1 permanent; location / { proxy_pass http://westos; } }}
nginx -t
nginx -s reload
server3:
改变httpd的端口为8080
vim /etc/httpd/conf/httpd.conf
136 Listen 8080
/etc/init.d/httpd restart
vim /var/www/html/index.html
测试:
浏览器 www.westos.com
mysql php
安装mysql
(1)安装包的获取
mysql-boost-5.7.17.tar.gz
php-5.6.20.tar.bz2
cmake-2.8.12.2-4.el6.x86_64.rpm
(2)
tar zxf mysql-boost-5.7.17.tar.gz ##解压mysql源码包
yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y ##安装必备cmake
yum install gcc-c++ -y ##安装c++编译
yum install ncurses-devel ##下载需要模块
(3)
cd mysql-5.7.17/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql \ ##安装目录-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \ ##数据库存放目录 -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \ ##Unix socket 文件路径-DWITH_MYISAM_STORAGE_ENGINE=1 \ ##安装 myisam 存储引擎-DWITH_INNOBASE_STORAGE_ENGINE=1 \ ##安装 innodb 存储引擎-DDEFAULT_CHARSET=utf8 \ ##使用 utf8 字符 -DDEFAULT_COLLATION=utf8_general_ci \ ##校验字符-DEXTRA_CHARSETS=all \ ##安装所有扩展字符集-DWITH_BOOST=boost/boost_1_59_0/
make && make install
mysql初始化设置
groupadd -g 27 mysql ##建立mysql组
useradd -u 27 -g 27 -s /sbin/nologin -M -d /usr/local/lnmp/mysql/ mysql ##建立mysql用户
vim /etc/passwd ##编辑用户文件
mysql:x:27:27::/usr/local/lnmp/mysql/data:/sbin/nologin
chown mysql.mysql /usr/local/lnmp/mysql/ -R ##更改mysql目录权限,-R表示递归
vim ~/.bash_profile ##编辑变量
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
source ~/.bash_profile ##使其生效
cp /etc/my.cnf /etc/my.cnf.bak ##备份文件
cp /usr/local/lnmp/mysql/support-files/my-default.cnf /etc/my.cnf ##覆盖文件
cp /usr/local/lnmp/mysql/support-files/mysql.server /etc/init.d/mysqld ##建立脚本命令
chown root.root /usr/local/lnmp/mysql -R ##更改mysql目录权限
mysqld –initialize –user=mysql ##初始化
##会有初始化密码2017-07-25T22:33:52.122332Z 1 [Note] A temporary password is generated for root@localhost: ycu<u9i:rGBl
chown mysql.root /usr/local/lnmp/mysql/data -R ##更改权限
/etc/init.d/mysqld start ##开启mysql
mysql_secure_installation ##mysql安全初始化,需要初始化生成的密钥
##会出现passwd安全性检查There are three levels of password validation policy:LOW Length >= 8MEDIUM Length >= 8, numeric, mixed case, and special charactersSTRONG Length >= 8, numeric, mixed case, special characters and dictionary filePlease enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
mysql -uroot -p ##进入mysql
php
php安装
(1)需要的包
php-5.6.20.tar.bz2
libmcrypt-2.5.8-9.el6.x86_64.rpm
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
re2c-0.13.5-1.el6.x86_64.rpm
(2)安装
yum install libxml2-devel -y
yum install -y curl-devel
yum install libjpeg-turbo-devel
yum install freetype-devel
yum install gmp-devel -y
rpm -ivh libmcrypt-2.5.8-9.el6.x86_64.rpm
yum install net-snmp-devel -y
yum install bison -y
rpm -ivh re2c-0.13.5-1.el6.x86_64.rpm
yum install libmcrypt-devel-2.5.8-9.el6.x86_64.rpm -y
yum install libpng-devel -y
tar jxf php-5.6.20.tar.bz2
编译php
cd php-5.6.20./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-zlib --with-gd --with-libxml-dir --with-curl --with-png-dir --with-jpeg-dir --with-freetype-dir --with-gmp --with-gettext --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
make && make install ##安装
php初始设置
cp php-5.6.20/php.ini-production /usr/local/lnmp/php/etc/php.ini ##复制源码包中的文件到php配置目录
cp php-5.6.20/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm ##创建脚本命令
chmod +x /etc/init.d/php-fpm ##添加x权限
vim /usr/local/lnmp/php/etc/php.ini ##编辑php配置文件
date.timezone = Asia/Shanghai ##时区
cp /usr/local/lnmp/php/etc/php-fpm.conf.default /usr/local/lnmp/php/etc/php-fpm.conf ##配置文件的产生
vim /usr/local/lnmp/php/etc/php-fpm.conf ##编辑配置文件
25 pid = run/php-fpm.pid
/etc/init.d/php-fpm start ##开启php服务
vim ~/.bash_profile ##添加局部变量
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php
source ~/.bash_profile ##使变量生效
php -m ##查看php的可用模块
netstat -antlp | grep :9000
vim /usr/local/lnmp/nginx/conf/nginx.conf ##编辑nginx配置文件
53 index index.php index.html index.htm;79 location ~ \.php$ { ##php配置80 root html;81 fastcgi_pass 127.0.0.1:9000;82 fastcgi_index index.php;83 #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name ; 84 include fastcgi.conf; ##该文件在/usr/local/lnmp/nginx/conf/目录下85 }
nginx -t ##检测文件语法
nginx -s reload ##重新加载服务
vim /usr/local/lnmp/nginx/html/index.php ##编辑发布页内容
<?phpphpinfo()?>
测试:
http://172.25.32.1/
php 应用(实现一个论坛)
(1)安装包
Discuz_X3.2_SC_UTF8.zip
unzip Discuz_X3.2_SC_UTF8.zip
(2)
mv upload/ /usr/local/lnmp/nginx/html/bbs
cd /usr/local/lnmp/nginx/html/bbs/
chmod 777 config/ data/ uc_client/ uc_server/ -R
vim /usr/local/lnmp/php/etc/php.ini
1007 pdo_mysql.default_socket= /usr/local/lnmp/mysql/data/mysql.sock1156 mysql.default_socket = /usr/local/lnmp/mysql/data/mysql.sock1215 mysqli.default_socket = /usr/local/lnmp/mysql/data/mysql.sock
/etc/init.d/php-fpm reload
chmod 777 /usr/local/lnmp/mysql/data/mysql.sock
chmod 755 /usr/local/lnmp/mysql/data/ -R
测试:
172.25.32.1/bbs
php 添加模块memcache
tar zxf memcache-2.2.5.tgz
cd memcache-2.2.5/phpize./configure make && make install
yum remove php-common-5.3.3-26.el6.x86_64 php-5.3.3-26.el6.x86_64 php-cli-5.3.3-26.el6.x86_64 -y
vim /usr/local/lnmp/php/etc/php.ini
/etc/init.d/php-fpm reload
/usr/local/lnmp/php/etc/php -m | grep memcache
yum install -y memcached -y
/etc/init.d/memcached start
netstat -antpl | grep :112
cp memcache.php /usr/local/lnmp/nginx/html/
cp example.php /usr/local/lnmp/nginx/html/
vim /usr/local/lnmp/nginx/html/memcache.php
/etc/init.d/php-fpm reload
- LNMP
- lnmp
- LNMP
- LNMP
- lnmp
- LNMP
- LNMP
- lnmp
- lnmp
- LNMP
- LNMP
- lnmp
- lnmp
- LNMP
- lnmp
- LNMP
- LNMP
- 安装lnmp
- js动态改变地址栏url,不刷新页面
- java死锁的原因分析及解锁和预防措施
- mysql事务
- Visual Studio 实用插件
- C++之析构函数和构造函数调用时间---补充(2)《Effective C++》
- lnmp
- kaggle Code :手写识别 TensorFlow
- MATLAB R2011b 神经网络工具箱注意事项
- java中的运算符
- idea默认文件编码格式设置
- python list排序的两种方法及实例讲解
- 深度学习batchsize,iteration,epoch的关系
- 关于uEditor,上传图片到指定主机(图片服务器)
- android viewpager和fragment