6. Create a Web server (LAMP):

Source: Internet
Author: User
Tags mcrypt rsync aliyun

Create a Web server (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

Chkconfig|egrep-v "Crond|sshd|network|rsyslog|sysstat" |awk ' {print "Chkconfig", $, "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 WEB02

Cat >/etc/sysconfig/network-scripts/ifcfg-eth0<<eof

Device=eth0

Type=ethernet

Onboot=yes

Nm_controlled=yes

Bootproto=static

ipaddr=10.0.0.7

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.7

netsk=255.255.255.0

Eof

Cat >/etc/sysconfig/network<<eof

Networking=yes

Hostname=web02

Eof

Hostname WEB02

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 ' XX * * * */bin/sh/server/scripts/bak.sh &>/dev/null ' >>/var/spool/cron/root

Crontab-l



#setup Apache

Yum-y install gcc gcc-c++ ncurses-devel perl

Yum-y Install zlib Zlib-devel

Cd/server/tools

TAR-XF httpd-2.2.32.tar.gz

CD httpd-2.2.32

Mkdir-p/application/apach2.2.31

./configure \

--prefix=/application/apache2.2.31 \

--enable-deflate \

--enable-expires \

--enable-headers \

--enable-modules=most \

--ENABLE-SO \

--with-mpm=worker \

--enable-rewrite

Make

Make install

Ln-s/application/apache2.2.31//application/apache

Ll/application/apache



#config Apache

cd/application/apache/htdocs/

mkdir BBS Blog www

echo "Apache www" > www/index.html

echo "Apache BBS" > bbs/index.html

echo "Apache Blog" > blog/index.html

Cd.. /conf/

Sed-i "[email protected] #Include Conf/extra/[email protected] conf/extra/[email protected]" httpd.conf

Sed-i "[email protected] #ServerName Www.example.com:[email protected] 127.0.0.1:[email protected]" httpd.conf

Sed-i "[email protected] Indexes [email protected]-indexes [email protected]" httpd.conf


Cat >/application/apache/conf/extra/httpd-vhosts.conf <<eof

Namevirtualhost *:80

<virtualhost *:80>

ServerAdmin [email protected]

DocumentRoot "/application/apache/htdocs/www"

ServerName www.etiantian.org

Serveralias etiantian.org

Errorlog "Logs/www-error_log"

Customlog "Logs/www-access_log" common

</VirtualHost>

<virtualhost *:80>

ServerAdmin [email protected]

DocumentRoot "/application/apache/htdocs/blog"

ServerName blog.etiantian.org

Errorlog "Logs/blog-error_log"

Customlog "Logs/blog-access_log" common

</VirtualHost>

<virtualhost *:80>

ServerAdmin [email protected]

DocumentRoot "/application/apache/htdocs/bbs"

ServerName bbs.etiantian.org

Errorlog "Logs/bbs-error_log"

Customlog "Logs/bbs-access_log" common

</VirtualHost>

Eof


/application/apache/bin/apachectl-t

/application/apache/bin/apachectl start

/application/apache/bin/apachectl Graceful


#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 openssl-devel libxslt

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.3.27 \

--WITH-APXS2=/APPLICATION/APACHE/BIN/APXS \

--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-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 \

--enable-ftp

Make

Make install

Cd.. /

Ln-s/application/php5.3.27//application/php

ll/application/php/


Cd/application/apache/conf

Sed-i ' 320iADDType application/x-httpd-php. php. phtml ' httpd.conf

Sed-i ' 321iADDType application/x-httpd-php-source. Phps ' httpd.conf

Sed-i "S#directoryindex index.html#directoryindex index.php index.html#g" httpd.conf

Sed-i "S#user daemon#user www#g" httpd.conf

Sed-i "S#group daemon#group www#g" httpd.conf

Sed-i "S#deny from All#allow from All#g" httpd.conf

Sed-i "[email protected] #Include Conf/extra/[email protected] conf/extra/[email protected]" httpd.conf

#sed-i "s#maxclients 150#maxclients 1500#g" extra/httpd-mpm.conf

Sed-i "S#maxrequestsperchild 0#maxrequestsperchild 5000#g" extra/httpd-mpm.conf

Useradd-u888-s/sbin/nologin www

ID www

/application/apache/bin/apachectl-t

/application/apache/bin/apachectl Graceful

Lsof-i: 80


#setup WordPress

cd/application/apache/htdocs/blog/

Tar-zxf/server/tools/blog-wordpress.tar.gz

Chown-r www.www/application/apache/htdocs/blog/

cd/application/apache/conf/


#mount

Yum-y Install Rpcbind nfs-utils

/etc/init.d/rpcbind start

Chkconfig Rpcbind on

SHOWMOUNT-E 172.16.1.31

Mount-t NFS 172.16.1.31:/data/application/apache/htdocs/blog/wp-content/uploads/

echo "/bin/mount-t NFS 172.16.1.31:/data/application/apache/htdocs/blog/wp-content/uploads/" >>/etc/rc.local

Cat/etc/rc.local

Df-h


/application/apache/bin/apachectl-t

/application/apache/bin/apachectl Graceful

Lsof-i: 80



WordPress is directly applied to the Niginx blog file, so Apache pseudo-static did not do!



Pit One:

[Email protected] extra]#/application/apache/bin/apachectl-t

[Tue June 13 21:49:01 2017] [Warn] _default_ VirtualHost overlap on port, the first has precedence

[Tue June 13 21:49:01 2017] [Warn] _default_ VirtualHost overlap on port, the first has precedence

Syntax OK

Apache configuration Check when there is an unknown cause of the error!

[Email protected] extra]# vim/etc/hosts

[Email protected] extra]# Curl www.etiantian.org

Apache www

[Email protected] extra]# Curl etiantian.org

Apache www

[Email protected] extra]# Curl bbs.etiantian.org

Apache www

[Email protected] extra]# Curl blog.etiantian.org

Apache www # page not read blog and BBS pages are displayed Apache WW


Answer: Namevirtualhost *:80 Follow-up comparison class WEB02 found httpd-vhosts.conf first line less this sentence!!!

6. Create a Web server (LAMP):

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.