LNMP
1、安装Nginx前的环境。
# yum -y install gcc gcc-c++ pcre-devel zlib-devel openssl-devel
2、添加www系统用户,在单机实现LNMP的情况下需要使得php的用户与nginx的用户身份相同。
# groupadd -r www
# useradd -r -g www www
3、编译安装Nginx。
# tar axf nginx-1.10.1.tar.gz
# cd nginx-1.10.1
# ./configure --prefix=/usr/local --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=www --group=www --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre
# make && make install
# vim /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=([^ ]*).*/1/g' -`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
# chmod +x /etc/init.d/nginx
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] mkdir() "/var/tmp/nginx/client" failed (2: No such file or directory)
nginx: configuration file /etc/nginx/nginx.conf test failed
# mkdir /var/tmp/nginx
# nginx -t && service nginx start
4、编译安装mysql。
# yum -y remove mysql mysql-server
# rm -rf /etc/my.cnf
# yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ cmake make
# groupadd -r mysql
# useradd -r -g mysql -s /sbin/nologin mysql
# tar xvf mysql-5.6.22.tar.gz
# cd mysql-5.6.22
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DMYSQL_DATADIR=/usr/local/mysql/data -DINSTALL_MANDIR=/usr/share/man -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DEXTRA_CHARSETS=all -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1
# make -j `grep 'processor' /proc/cpuinfo |wc -l`
# make install
# cd /usr/local/mysql
# chown -R mysql:mysql .
# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
# cp support-files/my-default.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
# service mysqld start
# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
# source /etc/profile
5、准备php环境。
# yum -y install bzip2-devel libxml2-devel libcurl-devel freetype-devel libpng-devel libjpeg-devel mysql-devel
6、安装libmcrypt-2.5.8.tar.gz。
# tar axf libmcrypt-2.5.8.tar.gz
# ./configure
# make && make install
7、安装php。
# cp php-5.5.38.tar.xz /tmp
# xz -d php-5.5.38.tar.xz
# tar axf php-5.5.38.tar
# cd php-5.5.38
# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-gd --with-libxml-dir=/usr/ --enable-xml --with-mhash --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl --with-fpm-user=www --with-fpm-group=www
此处的mysql如果为编译安装则需要指定当前编译安装的路径。
# make && make install
# cp php.ini-production /etc/php.ini
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chomd +x /etc/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# service php-fpm start
# ss -tunlp
此处查看9000端口如果已经处于监听状态,则php-fpm已启动。
8、配置nginx与php的通信。
# vim /etc/nginx/nginx.conf
location / {
root html;
index index.php index.html index.htm;
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
指定对于php的文件都发送到本地的9000端口使php进行处理。
# cat /usr/local/html/index.php
<?php
phpinfo();
?>
# service nginx restart
此时通过浏览器访问当前主机的页面即可显示php的相关信息。
9、为本地的mysql创建本地用户,使php与mysql建立联系。
# mysql
mysql> DROP USER ''@'localhost';
mysql> UPDATE mysql.user SET Password=PASSWORD('redhat') WHERE user='root';
mysql> FLUSH PRIVILEGES;
10、编辑index.php文件。
# vim /usr/local/html/index.php
<?php
$link = mysql_connect('127.0.0.1','root','redhat');
if ($link)
echo "Success...";
else
echo "Failure...";
mysql_close();
?>
编辑完成后通过浏览器查看即可。
QQ农场
#pwd
/tmp
#unzip farm-ucenter1.5.zip
#mysql -uroot -predhat
create database farm;
#mysql -uroot -predhat farm <qqfarm.sql
#cd /usr/local
#mv html html.bak
#mkdir html
#cd /tmp/upload
#mv * /usr/local/html
#chmod 777 -R /usr/local/html
#vim /etc/php.ini
:/short
short_open_tag = Off ==>On
#/etc/init.d/php-fpm restart
DNS解析
#yum -y install bind*
#vim /etc/named.conf
listen port 53 { any;}; 修改此行的127.0.0.1为any
allow-query { any;}; 修改此行的localhost为any
zone "ak.com" IN { type master; file "ak.com.zone"; };
#cd /var/named
#cp -p named.localhost ak.com.zone
#chkconfig named on
#cd /var/named
#vim ak.com.zone
$TTL 1D
@ IN SOA master.ak.com root.ak.com. (
2016081101 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
@ IN NS master.ak.com
master.ak.com IN A 192.168.11.6
ns1 IN A 192.168.11.6
www IN A 192.168.11.6
#/etc/init.d/named restart
#nslookup
server
server 192.168.11.6