在操作前 执行 yum install –y epel-release yum install –y net-tools yum install –y vim-enhanced

搭建LNMP

1.安装mysql(二进制包) ● cd /usr/local/src ##进入src目录 ● wget mysql-5.5.55-linux2.6-x86_64.tar.gz ##下载mysql二进制安装包 ● tar -zxvf mysql-5.5.55-linux2.6-x86_64.tar.gz ##解压mysql二进制安装包 ● mv mysql-5.5.55-linux2.6-x86_64 /usr/local/mysql ##移动解压的mysql目录到 /usr/local/mysql
● useradd mysql ##添加用户名称为mysql cd /usr/local/mysql/ ##打开mysql的目录 ● ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql ##重置mysql,指定用户mysql *提示错误 ./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory 使用 yum install –y libiao 再次执行 ● ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql [root@localhost mysql]# echo $?
0(没有拷贝配置文件与脚本+没有启动 ,站点使用的数据库在 另一台数据库主机上,使用不启动/配置,只是关联php-fpm)

2.PHP安装 ● wget … (下载多个xxx.tar.bz2 加压都出错,下载了xxx.tar.gz的正常) ● tar –zxvf php.xxx.tar.gz (解压包) ● cd php
(打开解压的目录) ●初始化 (关联安装问题 –with-mysql=, 数据库不在本地还要关联) ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl (初始化中,出现却小应用安装错误查询 http://www.bkjia.com/PHPjc/1008013.html)

● echo $? (输出0,初始化完成)

● make && make install (编辑+安装)

● echo $? (输出0,编译+安装成功)

● cp ./php.ini-production /usr/local/php-fpm/etc/php.ini //拷贝配置文件

● vim /usr/local/php-fpm/etc/php-fpm.conf (输入内容如下)

[global] //定义全局参数
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock     #listen = 127.0.0.1:9000 等于 listen = /tmp/php-fcgi.sock 
listen.mode = 666 //定义sock的权限
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

● cp /usr/local/src/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm //拷贝启动脚本 ● chmod 755 /etc/init.d/php-fpm (启动脚本755权限) ● chkconfig --add php-fpm (添加php-fpm服务) ● chkconfig php-fpm on (开机启动 ) ● service php-fpm start (启动) ● ps aux |grep php-fpm (检查启动后进程)
检查是否正常 /usr/local/php-fpm/sbin/php-fpm -i //查看配置信息 /usr/local/php-fpm/sbin/php-fpm -m //查看模块 /usr/local/php-fpm/sbin/php-fpm -t //检测模块配置是否正确 安装 Nginx ● wget .... nginx-1.6.3.tar.gz (下载nginx) ● tar -zxvf nginx-1.6.3.tar.gz (解压nginx) ● cd nginx-1.6.3 (打开解压后的目录) ● mkdir /usr/local/nginx (创建nginx安装目录) ●./configure --prefix=/usr/local/nginx (初始化,指定安装nginx目录) ● make && make install (编译+安装) ● echo $? (检查编译安装命令有没有报错)

● vim /etc/init.d/nginx ///编辑nginx启动脚本,内容如下:

#!/bin/bash
#chkconfig: - 30 21
#description: http service.
#Source Function Library
. /etc/init.d/functions
#Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start() 
{
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop() 
{
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload()
{
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart()
{
stop
start
}
configtest()
{
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL

●chmod 755 /etc/init.d/nginx //修改启动脚本权限,确保开可以启动执行

●chkconfig --add nginx //将nginx添加到服务

●chkconfig nginx on //nginx服务设置开机启动

●vim /usr/local/nginx/conf/nginx.conf //nginx配置文件,nginx.conf是有默认配置,清空写入内容

user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 6000;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
' $host "$request_uri" $status'
' "$http_referer" "$http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm 
application/xml;
include vhost/*.conf
}

●mkdir /user/local/nginx/conf/vhost

●vim /user/local/nginx/conf/vhost/dedecms.conf

server
{
   listen 80 ;  
   server_name www.dedecmsgroup02.com;
   index index.php index.html index.htm;
   root /home/wwwroot/dedecms;        
  location ~ \.php$ 
        {
            include fastcgi_params;
            fastcgi_pass unix:/tmp/php-fcgi.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /home/wwwroot/dedecms$fastcgi_script_name;
        }   
}

●vim /user/local/nginx/conf/vhost/discuz.conf

server
{
   listen 80 default_server;  
   server_name www.discuzgroup02.com;
   index index.php index.html index.htm;
   root /home/wwwroot/discuz;        
  location ~ \.php$ 
        {
            include fastcgi_params;
            fastcgi_pass unix:/tmp/php-fcgi.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /home/wwwroot/discuz$fastcgi_script_name;
        }   
}

● 下载discuz+dedecms cd /usr/local/src/ wget xxxxx.discuz.tar.gz wget xxxxx.dedecms.tar.gz tar –zxvf discuz.tar.gz tar –zxvf dedecms.tar.gz mv discus.xxx /home/wwwroot/discus mv dedecms.xxx /home/wwwroot/dedecms chmod 755 /home/wwwroot/discus chmod 755 /home/wwwroot/discus ● /usr/local/nginx/sbin/nginx -t //检测配置文件 配置正确与否 ● /usr/local/nginx/sbin/nginx -s reload //重新加载配置文件

安装配置tomcat + jdk

安装jdk的版本 1.6 1.7 1.8 ● 官网下载http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 页面下载 ● tar -zxvf jdk-8u144-linux-x64.tar.gz //解压包 ● mv dk-8u144-linux-x64 /usr/local/jdk1.8 //移动重命名文件目录 ● vim /etc/profile //最后面增加(这个环境变量文件 修改) JAVA_HOME=/usr/local/jdk1.8 JAVA_BIN=/usr/local/jdk1.8/bin JRE_HOME=/usr/local/jdk1.8/jre PATH=$PATH:/usr/local/jdk1.8/bin:/usr/local/jdk1.8/jre/bin CLASSPATH=/usr/local/jdk1.8/jre/lib:/usr/local/jdk1.8/lib:/usr/local/jdk1.8/jre/lib/charset.jar

● source /etc/profile //令刚刚添加的环境变量生效 ● java -version //检测版本是否安装成功,命令成功,会显示版本信息是否与安装版本一样

安装Tomcat(二进制码安装) ● cd /usr/local/src ● wget http://apache.fayea.com/tomcat/tomcat-8/v8.5.20/bin/apache-tomcat-8.5.20.tar.gz ● tar zxvf apache-tomcat-8.5.20.tar.gz //解包 ● mv apache-tomcat-8.5.20 /usr/local/tomcat //移动重命名目录 ● /usr/local/tomcat/bin/startup.sh //安装 ● ps aux|grep tomcat //查看tomcat是否运行 ● netstat -lntp |grep java

ps aux |grep java 查看Java是否正常启动

配置zrlog

wget xxxx.zrlog.zip 下载zrlog uzip zrlog.xxxx.zip 解压文件 mv zrlog.war /usr/local/tomcat/wedapps/ 将war包移动到这个目录后会自动解压 mv /usr/local/tomcat/wedapps/zrlog /home/wwwroot/zrloggroup02

修改nginx配置文件,在http{}中添加内容
vi /usr/local/nginx/conf/nginx.conf 添加内容 ...... log_format access '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; access_log off;

    ####### 添加以下内容 #######
    upstream tomcat_server {
          server 127.0.0.1:8080;
          
    }

创建新建一个nginx配置文件,将请求交给Tomcat处理 vi /usr/local/nginx/conf/proxy-tomcat.conf

location ~ .(jsp|jsp|do|action)?$
使用下面的配置是将请求全部交给tomcat,上一行配置了交给tomcat处理的后缀

server { location / { proxy_redirect off;

#后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://tomcat_server;

client_max_body_size 100m; #客户端允许上传的最大文件大小
client_body_buffer_size 128k; #允许客户端请求的最大单文件字节数

proxy_connect_timeout 5; #nginx跟后端服务器连接超时时间
proxy_read_timeout 60; #连接成功后,后端服务器响应时间
proxy_send_timeout 5; #后端服务器发送时间

proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传递请求,而不缓冲到磁盘
#proxy_ignore_client_abort on; #不允许代理端主动关闭连接

} }

修改Tomcat配置文件 vi /usr/local/tomcat/conf/server.xml 添加一个站 <Host name="www.zrloggroup02.com" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <!-- 绑定其他域名 --> <!-- <Alias> zrloggroup02.com</Alias> --> <!-- 获取真实IP --> <Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="X-Forwarded-For" requestAttributesEnabled="true" internalProxies="127.0.0.1" /> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="aqjlb_access_log" suffix=".txt" pattern="%{X-Forwarded-For}i %l %u %t "%r" %s %b" /> <Context path="" docBase="/home/wwwroot/ zrloggroup02" debug="0" reloadable="true" /> </Host>

重启nginx /etc/init.d/nginx restart 或者/usr/local/nginx/sbin/nginx -s reload //重新加载配置文件

重启 tomcat /usr/local/tomcat/bin/shutdown.sh 关闭 /usr/local/tomcat/bin/startup.sh 启动

LNMP+TOMCAT+JDK 环境搭建完成 +配置discuz /dedecms /zrlog (使用mysql数据库不在本机,设置192.168.200.127.所以这可以配置mysql,如果使用本地的数据库要启用mysql 服务,创建用户+库+指定用户 等 即可) 文章中设置3个站点域名 定义为 www.discuozgroup02.com www.dedecmsgroup02.com www.zrloggroup02.com 请根据实际设置

安装数据库服务器 (主从)

192.168.200.127 无论数据库还是网站 iptables -F 必须做

root@localhost src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36- linux-glibc2.5-x86_64.tar.gz wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz [root@localhost src]# tar zxvf mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz [root@localhost src]# mv mysql-5.6.36-linux-glibc2.5-x86_64 /usr/local/mysql [root@localhost src]# ls /usr/local/mysql/ bin data include man README share support-files COPYING docs lib mysql-test scripts sql-bench [root@localhost src]# useradd mysql [root@localhost src]# mkdir /data/ [root@localhost mysql]# yum install perl gcc kernel-devel [root@localhost mysql]# yum install -y perl-Data-Dumper.x86_64 [root@localhost mysql]# yum install libaio* -y [root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql [root@localhost mysql]# vim /etc/my.cnf [root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@localhost mysql]# vim /etc/init.d/mysqld [root@localhost mysql]# chkconfig --add mysqld [root@localhost mysql]# service mysqld start

配置MySQL主从库 主上操作 [root@localhost ~]# vim /etc/my.cnf

[mysqld] datadir=/data/mysql socket=/tmp/mysql.sock server-id=127 log_bin=db1 # 改这两个地方

/etc/init.d/mysqld restart #mysql mysqldump -uroot dedecms118 > /tmp/dedecms118.sql mysqldump -uroot discuz118 > /tmp/discuz118.sql mysqldump -uroot zrlog118 > /tmp/zrlog118.sql

mysql> grant replication slave on . to 'group2'@'192.168.200.128' identified by '123'; Query OK, 0 rows affected (0.01 sec)

mysql> flush tables with read lock; Query OK, 0 rows affected (0.07 sec)

从上操作 (128主机上要安装好mysql) vim /etc/my.cnf server-id=128

scp 192.168.200.127:/tmp/*.sql /tmp/ /usr/local/mysql/bin/mysql -uroot discuz118 < /tmp/discuz118.sql /usr/local/mysql/bin/mysql -uroot dedecms118 < /tmp/dedecms118.sql /usr/local/mysql/bin/mysql -uroot zrlog118 < /tmp/zrlog118.sql /usr/local/mysql/bin/mysql /etc/init.d/mysqld restart mysql> create database discuz118; mysql> create database dedecms118; create database zrlog118; mysql> stop slave; mysql> change master to master_host='192.168.200.127', master_user='group2', master_password='123', master_log_file='db1.000001', master_log_pos=1069; mysql> start slave; mysql> show slave status\G Master_User: group2 Master_Port: 3306 Connect_Retry: 60 Master_Log_File: db1.000001 Read_Master_Log_Pos: 1096 Relay_Log_File: localhost-relay-bin.000002 Relay_Log_Pos: 277 Relay_Master_Log_File: db1.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes # 出现两个yes就OK了 Replicate_Do_DB: Replicate_Ignore_DB: