5.创建web服务器(LNMP):

创建web服务器(LNMP):

# optimization by onekey

sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#‘ /etc/selinux/config

grep SELINUX=disabled /etc/selinux/config

setenforce 0

getenforce

/etc/init.d/iptables stop

/etc/init.d/iptables stop

chkconfig iptables off

chkconfig|egrep -v "crond|sshd|network|rsyslog|sysstat"|awk ‘{print "chkconfig",$1,"off"}‘|bash

useradd oldboy

\cp /etc/sudoers /etc/sudoers.bak

echo "oldboy ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

tail -l /etc/sudoers

visudo -c

echo ‘export TMOUT=1800‘ >> /etc/profile

echo ‘export HISTSIZE=5‘  >> /etc/profile

echo ‘export HISTFILESIZE=5‘ >> /etc/profile

. /etc/profile

echo ‘*                -       nofile          65535‘ >> /etc/security/limits.conf

echo ">/etc/udev/rules.d/70-persistent-net.rules" >>/etc/rc.local

#about selinux

cat >> /etc/sysctl.conf <<EOF

net.ipv4.tcp_fin_timeout = 2

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_syncookies = 1

net.ipv4.tcp_keepalive_time = 600

net.ipv4.ip_local_port_range = 4000   65000

net.ipv4.tcp_max_syn_backlog = 16384

net.ipv4.tcp_max_tw_buckets = 36000

net.ipv4.route.gc_timeout = 100

net.ipv4.tcp_syn_retries = 1

net.ipv4.tcp_synack_retries = 1

net.core.somaxconn = 16384

net.core.netdv_max_backlog = 16384

net.ipv4.tcp_max_orphans = 16384

net.nf_conntrack_max = 25000000

net.netfilter.nf_conntrack_max = 25000000

net.netfilter.nf_conntrack_tcp_timeout_established = 180

net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120

net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60

net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120

EOF

#set ip and hosts for web01

cat >/etc/sysconfig/network-scripts/ifcfg-eth0<<EOF

DEVICE=eth0

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=yes

BOOTPROTO=static

IPADDR=10.0.0.8

NETSK=255.255.255.0

GATEWAY=10.0.0.2

nameserver=202.96.128.86

EOF

cat >/etc/sysconfig/network-scripts/ifcfg-eth1 <<EOF

DEVICE=eth1

TYPE=Ethernet

ONBOOT=yes

NM_CONTROLLED=yes

IPADDR=172.16.1.8

NETSK=255.255.255.0

EOF

cat >/etc/sysconfig/network<<EOF

NETWORKING=yes

HOSTNAME=web01

EOF

hostname web01

cat >/etc/hosts <<EOF

127.0.0.1    localhost localhost.localdomain localhost4 localhost4.localdomain4

::1          localhost localhost.localdomain localhost6 localhost6.localdomain6

172.16.1.5   lb01

172.16.1.6   lb02

172.16.1.7   web02

172.16.1.8   web01

172.16.1.31  nfs01

172.16.1.41  backup

172.16.1.51  db01

172.16.1.61  m01

EOF

#/etc/init.d/network reload

#make some dir

mkdir -p /server/scripts /server/tools /application

reboot

====================================================================================================

#yum repo and epel

yum -y install  wget

\cp /etc/yum.repos.d/CentOS-Base.repo{,.backup}

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

yum clean all

yum makecache

#setup some tools and develpment

yum -y install lrzsz nmap tree dos2unix nc wget

yum groupinstall -y "Base" "Compatibility libraries" "Debugging Tools" "Development tools"

#set ntp cron

echo ‘#time sync by NTP Server at 20170608‘ >>/var/spool/cron/root

echo ‘*/5 * * * * /usr/sbin/ntpdate 172.16.1.61 >/dev/null 2>&1‘ >>/var/spool/cron/root

crontab -l

#tar configs for every server rsync to backup

#install rsync

yum -y install rsync

#create passwordfile

echo "oldboy" >/etc/rsync.password

chmod 600 /etc/rsync.password

cat >/server/scripts/bak.sh <<EOF

#!/bin/sh

##create by 20has at 2017-5-18

IP=\$(ifconfig eth1|awk -F "[ :]+" ‘NR==2{print \$4}‘)

TIME=\$(date +%F)

mkdir -p /backup/\$IP

cd / && \

tar -zcf /backup/\$IP/\$TIME.tar.gz var/spool/cron/root etc/rc.local server/scripts etc/sysconfig/iptables

md5sum /backup/\$IP/\$TIME.tar.gz >/backup/\$IP/flag.log

rsync -az /backup/ [email protected]::backup --password-file=/etc/rsync.password

#del

find /backup -type f -name "*.tar.gz" -mtime +7 |xargs rm -f

EOF

#add cron to rsync backup

echo ‘#add cron to rsync backup at 20170608‘ >>/var/spool/cron/root

echo ‘00 00 * * * /bin/sh /server/scripts/bak.sh &>/dev/null‘ >>/var/spool/cron/root

crontab -l

#setup nginx

yum -y install gcc gcc-c++ ncurses-devel perl openssl openssl-devel pcre pcre-devel

cd /server/tools/

tar -zxvf nginx-1.6.3.tar.gz

cd nginx-1.6.3

useradd www -u888 -s /sbin/nologin -M

./configure --user=www --group=www  --with-http_stub_status_module --with-http_ssl_module --prefix=/application/nginx-1.6.3/

make

make install

ln -s /application/nginx-1.6.3/ /application/nginx

mkdir -p /application/nginx/conf/extra

cd /application/nginx/conf/extra

cat >../nginx.conf<<EOF

worker_processes  1;

events {

worker_connections  1024;

}

error_log logs/error.log error;

http {

include       mime.types;

default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;

include extra/*.conf;

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;

}

EOF

cat >www.conf<<EOF

server {

listen       80;

server_name  www.etiantian.org etiantian.org;

location / {

root   html/www;

index index.html index.htm;

}

}

EOF

cat >blog.conf<<EOF

server {

listen       80;

server_name  blog.etiantian.org;

location / {

root   html/blog;

index index.html index.htm;

}

}

EOF

mkdir -p ../../html/www ../../html/blog

echo www >../../html/www/index.html

echo blog >../../html/blog/index.html

/application/nginx/sbin/nginx

/application/nginx/sbin/nginx -s reload

lsof -i :80

#setup php

yum -y install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel

yum -y install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel

yum -y install libmcrypt-devel mhash mcrypt

cd /server/tools/

tar zxf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local/libiconv

make

make install

cd ../

tar zxf php-5.5.32.tar.gz

cd php-5.5.32

./configure \

--prefix=/application/php5.5.32 \

--with-mysql=mysqlnd \

--with-pdo-mysql=mysqlnd \

--with-iconv-dir=/usr/local/libiconv \

--with-freetype-dir \

--with-jpeg-dir \

--with-png-dir \

--with-zlib \

--with-libxml-dir=/usr \

--enable-xml \

--disable-rpath \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-inline-optimization \

--with-curl \

--enable-mbregex \

--enable-fpm \

--enable-mbstring \

--with-mcrypt \

--with-gd \

--enable-gd-native-ttf \

--with-openssl \

--with-mhash \

--enable-pcntl \

--enable-sockets \

--with-xmlrpc \

--enable-soap \

--enable-short-tags \

--enable-static \

--with-xsl \

--with-fpm-user=www \

--with-fpm-group=www \

--enable-ftp \

--enable-opcache=no

ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/

touch ext/phar/phar.phar

make

make install

ln -s /application/php5.5.32/ /application/php

cp php.ini-production /application/php/lib/php.ini

cd /application/php/etc/

cp php-fpm.conf.default php-fpm.conf

/application/php/sbin/php-fpm

lsof -i :9000

ps -ef |grep php-fpm

cd /application/nginx/conf/extra/

cat >blog.conf<<EOF

server {

listen       80;

server_name  blog.etiantian.org;

location / {

root   html/blog;

index index.php index.html index.htm;

try_files \$uri \$uri/ /index.php?q=\$uri&\$args;

}

location ~ .*\.(php|php5)?\$ {

root   html/blog;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi.conf;

}

}

EOF

/application/nginx/sbin/nginx -t

/application/nginx/sbin/nginx -s reload

#setup wordpress

cd /server/tools/

tar xf wordpress-4.7.4-zh_CN.tar.gz

\cp -a wordpress/* /application/nginx/html/blog/

chown -R www.www /application/nginx/html/blog/

mkdir -p /application/nginx/html/blog/wp-content/uploads

#mount nfs to store uploads-files

yum -y install nfs-utils rpcbind

/etc/init.d/rpcbind start

chkconfig rpcbind on

chkconfig --list rpcbind

netstat -lntup |grep rpc

showmount -e 172.16.1.31

mount -t nfs 172.16.1.31:/data /application/nginx/html/blog/wp-content/uploads/

echo "mount -t nfs 172.16.1.31:/data /application/nginx/html/blog/wp-content/uploads/" >>/etc/rc.local

df -h

wordpress的伪静态搭建完成!

两种添加ip别名的方法:

[[email protected] conf]# ifconfig eth0:0 10.0.0.101/24 up

[[email protected] conf]# ip addr add 10.0.0.102/24 dev eth0 label eth0:1

时间: 2024-10-14 10:18:15

5.创建web服务器(LNMP):的相关文章

Linux服务器集群架构部署搭建(四)WEB服务器LNMP/LAMP搭建部署及站点产品安装(1)

命运是大海,当你能够畅游时,你就要纵情游向你的所爱,因为你不知道狂流什么会到来,卷走一切希望与梦想. 作者:燁未央_Estelle声明:测试学习,不足之处,欢迎指正. 第一章 集群WEB服务器LNMP生产应用 1.1 Nginx的应用场合:根据功能来进行应用 ①静态服务器(图片,视频服务)国内使用的只有两款,另一个是lighttpd.百度贴吧.豆瓣.html.js.css.flv等. ②动态服务:nginx+fastcgi的方式运行php.jsp.动态的并发很少(根据优化达到500-1500),

6.创建web服务器(LAMP):

创建web服务器(LAMP): # optimization by onekey sed -i 's#SELINUX=enforcing#SELINUX=disabled#' /etc/selinux/config grep SELINUX=disabled /etc/selinux/config setenforce 0 getenforce /etc/init.d/iptables stop /etc/init.d/iptables stop chkconfig iptables off c

AZURE快速创建WEB服务器。

部署前的准备: 由于快速部署使用的web apps,所以需要拥有Azure账号,并且拥有相关订阅. 首先创建Web应用,并且可以先看下介绍部分. 点击创建web应用,设置应用名称,选择订阅信息(如果有多个订阅的话).选择资源组,资源组可以新建,也可以使用现有项. 然后创建,稍等片刻,就创建完成了. 到这就相当于我们的运行环境就已经搭建好了.这里我们也可以看下初始的环境. 环境搭建好.下一步就要把文件导入到相应目录下.然后测试是否能正常运行.这里Azure提供多种部署方式,比如常用的FTp.Git

使用nodejs的http模块创建web服务器

[email protected] Contents 1.?web服务器基础知识 2.?Node.js的Web 服务器 3.?代码实现 1.?web服务器基础知识 接受HTTP请求(GET POST DELETE PUT PATCH HEAD) 处理HTTP请求(自己处理,或者请求别的程序处理CGI) 做出响应(返回页面.文件.各类数据等) 常见的web服务器架构: Nginx/Apache:负责接受HTTP请求,确定谁来处理请求,并返回请求的结果 php-fpm/php模块:处理分配给自己的请

Node创建web服务器并连接数据库

1.安装环境 (1)安装node: node官网:http://nodejs.cn/download/ 以管理员身份打开cmd,输入node -v,输出版本号证明安装成功. (1)安装mongodb: mongodb:https://www.mongodb.com/ 2.编写js代码 // 引入express框架 const express = require('express'); // 引入数据库处理模块 const mongoose = require('mongoose'); const

创建web服务器

用node创建本地web服务 1,创建本地文件server.js var http = require('http'); var url=require('url'); var fs=require('fs'); var mine=require('./mime').types; var path=require('path'); //创建服务器 http.createServer(function(request, response) { var pathname = url.parse(re

NodeJs 创建 Web 服务器

以下是演示一个最基本的 HTTP 服务器架构(使用8081端口),创建 ser.js 文件,代码如下所示: var http = require('http'); var fs = require('fs'); var url = require('url'); //创建服务器 server = http.createServer(function(req,res){ //解析请求,包括文件名 var pathname=url.parse(req.url).pathname; //输出请求的文件

使用express创建web服务器

[email protected] Contents 1.?简单的express服务器 2.?静态文件服务 3.?路由 4.?中间件 1.?简单的express服务器 安装npm install express使用npm找不到源,改用cnpm 第一版本 var express = require('express'); var app = express(); app.listen(18001,function afterlisten(){ console.log('express runnin

python web编程 创建一个web服务器

这里就介绍几个底层的用于创建web服务器的模块,其中最为主要的就是BaseHTTPServer,很多框架和web服务器就是在他们的基础上创建的 基础知识 要建立一个Web 服务,一个基本的服务器和一个“处理器”是必备的. 基础的(Web)服务器是一个必备的模具.它的角色是在客户端和服务器端完成必要HTTP 交互.在BaseHTTPServer 模块中你可以找到一个名叫HTTPServer 的服务器基本类. 处理器是一些处理主要“Web 服务”的简单软件.它们处理客户端的请求,并返回适当的文件,静