lnmp 架构
1 安装mysql
yum install -y gcc gcc-c++ make ncurses-devel bison openssl-devel zlib-devel cmake
tar zxvf mysql-5.5.12.tar.gz
因为cmake 版本抵所以要安装cmake
编译报错
CMake Error at CMakeLists.txt:21 (CMAKE_MINIMUM_REQUIRED):
CMake 2.8.2 or higher is required. You are running version 2.6.4
安装cmake
yum install cmake-2.8.12.2-4.el6.x86_64.rpm
重新编译编译
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 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_SSL=yes -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=all
make && make install
cp /etc/my.cnf /etc/my.cnf.bak
把msyql .server 启动脚本 放入 /etc/init.d 下
cd /usr/local/lnmp/mysql/support-files
cp mysql.server /etc/init.d/mysqld
添加mysql 用户 并设置环境变量
useradd mysql
在~/.bash_profile 下添加环境变量
--PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
source ~/.bash_profile 生效
初始化
mysqld --initialize --user=mysql --basedir=/usr/local/lnmp/mysql/ --datadir=/usr/local/lnmp/mysql/data
进入mysql 目录 更改权限
cd /usr/local/lnmp/mysql
chown root.mysql /usr/local/lnmp/mysql/* -R
chown mysql.mysql /usr/local/lnmp/mysql/data -R
/etc/init.d/mysql start 启动数据库修改密码
mysql -p
mysql> alter user [email protected] identified by 'redhat';
安装php
tar -jxf php-5.6.35.tar.bz2
yum install libxml2-devel-2.7.6-14.el6.x86_6
yum install openssl-devel-1.0.1e-15.el6.x86_64
cd php-5.6.35 编译
./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --enable-mysqlnd --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --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
yum install libcurl-devel.x86_64 libjpeg-turbo-devel-1.2.1-1.el6.x86_64 libpng-devel-1.2.49-1.el6_2.x86_64 freetype-devel-2.3.11-14.el6_3.1.x86_64 gmp-devel-4.3.1-7.el6_2.2.x86_64 net-snmp-devel.x86_64 -y
rpm -ivh libmcrypt-2.5.8-9.el6.x86_64.rpm libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --enable-mysqlnd --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --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
添加nginx 用户
useradd nginx
拷贝
cd /user/local/lnmp/php/etc
cp php-fpm.conf.default php-fpm.conf
cd php-5.6.35
cp php.ini-production /usr/local/lnmp/php/etc/php.ini
修改 date.timezone =Asia/Shanghai
配置启动脚本
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm -p
chmod +x /etc/init.d/php-fpm 给可执行权限
/etc/init.d/php-fpm start 启动
/etc/init.d/php-fpm reload
nginx 安装
tar zxf nginx-sticky-module-ng.tar.gz
tar -zxf nginx-1.10.1.tar.gz
cd nginx-1.10.1
vim src/core/nginx.h
删除nginx 后
vim auto/cc/gcc
注释debug
yum install -y pcre-devel 安装 因为需要依赖
./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --add-module=/root/nginx-sticky-module-ng 编译
make && make install
cd /usr/local/lnmp/nginx/html
添加一个php文件
vim index.php
<?php
phoinfo()
?>
ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/bin 做链接
更改配置文件
user nginx; 2行
worker_processes auto; 3行
worker_connections 65535; 13行
index index.php index.html index.htm; 45 行
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 69 注释
vim /etc/security/limits.conf
nginx - nofile 65535
nginx -t
nginx 启动
浏览器中测试
安装论坛
unzip Discuz_X3.2_SC_UTF8.zip -d /usr/local/lnmp/nginx/html/ 解压到nginx 发布目录
cd /usr/local/lnmp/nginx/html/
mv upload/ bbs
cd bbs/
chmod 777 config/
chmod 777 data -R
chmod 777 uc_client/ uc_server/ -R
vim /usr/local/lnmp/php/etc/php.ini
3个socket后面加上/usr/local/lnmp/mysql/data/mysql.sock
chmod 755 data/ 给mysql 加权限
memcache 加速
yum install memcache -y
tar zxf memcache-2.2.5.tgz
[[email protected] memcache-2.2.5]# ls
config9.m4 example.php memcache.php memcache_standard_hash.c
config.m4 memcache.c memcache_queue.c php_memcache.h
config.w32 memcache_consistent_hash.c memcache_queue.h README
CREDITS memcache.dsp memcache_session.c
[[email protected] memcache-2.2.5]# cd /usr/local/lnmp/php/bin/
[[email protected] bin]# ls
pear peardev pecl phar phar.phar php php-cgi php-config phpize
[[email protected] bin]# vim ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin
[[email protected] bin]# source ~/.bash_profile
[[email protected] ~]# cd memcache-2.2.5
[[email protected] memcache-2.2.5]# phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
[[email protected] memcache-2.2.5]# ./configure --enable-memcache
[[email protected] memcache-2.2.5]# make && make install
Installing shared extensions: /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226/
[[email protected] memcache-2.2.5]# cd /usr/local/lnmp/php/lib/php/extensions/no-debug-non-zts-20131226/
[[email protected] no-debug-non-zts-20131226]# php -m |grep memcache
[[email protected] no-debug-non-zts-20131226]# cd /usr/local/lnmp/php/etc/
[[email protected] etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[[email protected] etc]# vim php.ini
extension=memcache.so
[[email protected] etc]# /etc/init.d/php-fpm reload
Reload service php-fpm done
[[email protected] etc]# php -m |grep memcache
memcache
[[email protected] ~]# cd memcache-2.2.5
[[email protected] memcache-2.2.5]# cp memcache.php /usr/local/lnmp/nginx/html/
[[email protected] memcache-2.2.5]# cp example.php /usr/local/lnmp/nginx/html/
[[email protected] memcache-2.2.5]# cd /usr/local/lnmp/nginx/html/
[[email protected] html]# vim memcache.php
define('ADMIN_USERNAME','memcache'); // Admin Username
define('ADMIN_PASSWORD','westos'); // Admin Password
$MEMCACHE_SERVERS[] = '172.25.254.1:11211'; // add more as an array
[[email protected] html]# yum install -y telnet
压力测试
http://172.25.254.1/memcache.php
http://172.25.254.1/example.php 每刷新一次 memcache 命中率会增加
多次刷新
OpenResty
tar zxf openresty-1.13.6.1.tar.gz
cd openresty-1.13.6.1
./configure
make && make install
cd /usr/local/openresty/nginx/conf/
nginx -s stop 关闭nginx
cp /usr/local/lnmp/nginx/html/index.php /usr/local/openresty/nginx/html/
cp /usr/local/lnmp/nginx/html/example.php /usr/local/openresty/nginx/html/
cp /usr/local/lnmp/nginx/html/memcache.php /usr/local/openresty/nginx/html/
编辑配置文件 /usr/loacl/openresty/nginx
vim /usr/local/openresty/nginx/nginx.conf
user nginx;
worker_processes 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 65535;
}
http {
upstream memcache {
server 172.25.254.1:11211;
keepalive 512;
}
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
location /memc {
internal;
memc_connect_timeout 100ms;
memc_send_timeout 100ms;
memc_read_timeout 100ms;
set $memc_key $query_string;
set $memc_exptime 300;
memc_pass memcache;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
set $key $uri$args;
srcache_fetch GET /memc $key;
srcache_store PUT /memc $key;
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# 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;
# }
#}
/usr/local/openresty/nginx/sbin/nginx -t
/usr/local/openresty/nginx/sbin/nginx -s reload
Tomcat
tar zxf jdk-7u79-linux-x64.tar.gz -C /usr/local/
tar zxf apache-tomcat-8.5.24.tar.gz -C /usr/local/
做链接
ln -s /usr/local/jdk1.7.0_79/ /usr/local/java
ln -s /usr/local/apache-tomcat-8.5.24/ /usr/local/tomcat
配置jdk
vim /etc/profile
export JAVA_HOME=/usr/local/java
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile
/usr/local/tomcat/bin/startup.sh 启动
测试
vim /usr/local/tomcat/webapps/ROOT/test.jsp
a
测试
不用加8080端口访问
添加一台tomocat
scp -r tomcat 172.25.254.2:/user/local scp -r java 172.25.254.2:/user/local scp /etc/profile 172.25.254.2:/etc/profile
在server2中执行 source /etc/profile
vim /usr/local/tomcat/webapps/ROOT/test.jsp
b
/usr/local/tomcat/bin/startup.sh
配置完成
在server1中修改nginx配置文件
vim /usr/local/openresty/nginx/conf/nginx.conf
upstream tomcat { 22
server 172.25.254.1:8080; 23
server 172.25.254.2.8080; 24
}
/usr/local/openresty/nginx/sbin/nginx -t
/usr/local/openresty/nginx/sbin/nginx -s reload
在浏览器中测试