php linux 微软 wordpress 开源 Ubuntu Windows google shell nginx centos linux命令 程序员 Python mysql Firefox Android HTML5 java apache

Discuz!运行环境搭建教程:CentOS+Nginx

本文主要撰写discuzCentOS系统上的运行环境搭建过程,服务器软件采用轻量级的web服务器Nginx,下面是详细过程:

一、系统约定

  • 软件源代码包存放位置 /usr/local/src
  • 源码包编译安装位置(prefix) /usr/local/software_name
  • 脚本以及维护程序存放位置 /usr/local/sbin
  • mysql 数据库位置 /var/lib/mysql(可按情况设置)
  • 网站根目录 /home/www/wwwroot(可按情况设置)
  • 虚拟主机日志根目录 /home/www/logs(可按情况设置)
  • 运行账户 www:www

二、系统环境部署及调整

1、检查系统是否正常

# more /var/log/messages (检查有无系统级错误信息)
# dmesg (检查硬件设备是否有错误信息)
# ifconfig(检查网卡设置是否正确)
# ping www.163.com (检查网络是否正常)
# cat /proc/cpuinfo (检查CPU频率是否正常)
# top (按1检测CPU核数是否正常,内存大小是否正常

2、关闭不需要的服务

# ntsysv

  • 以下仅列出需要启动的服务,未列出的服务一律推荐关闭:
  • atd
  • crond
  • irqbalance
  • microcode_ctl
  • network
  • sendmail
  • sshd
  • syslog

关闭SElinux:修改/etc/selinux/config文件中的SELINUX= 为 disabled

3、更换yum国内源

# cd /etc/yum.repos.d
# mv CentOS-Base.repo CentOS-Base.repo.save
# wget http://centos.ustc.edu.cn/CentOS-Base.repo.5
# mv CentOS-Base.repo.5 CentOS-Base.repo
# yum clean all

4、服务器时间检查和设置

#data (检查时间是否正确,是否是中国时间CST)
#cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime (如果时区不对,则执行,时间正常的跳过)
#yum -y install ntp (安装ntp对时工具)
#chkconfig ntpd on (让对时服务开机启动)

5、使用 yum 对系统进行更新并且安装必要软件包

#yum update –y
#yum -y install make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel

6. 重新启动系统

# init 6

三、编译安装L.A.M.P环境

1、下载软件

# cd /usr/local/src
#wget http://sysoev.ru/nginx/nginx-0.7.63.tar.gz
#wget http://download.scientificlinux.net/nginx
#wget http://download.scientificlinux.net/PHP-fpm.conf
#wget http://download.scientificlinux.net/nginx.conf
#wget http://download.scientificlinux.net/fcgi.conf
#wget http://download.scientificlinux.net/php-5.2.10.tar.gz
#wget http://download.scientificlinux.net/php-5.2.10-fpm-0.5.13.diff.gz
#wget http://download.scientificlinux.net/ZendOptimizer-3.3.3-Linux-glibc23-i386.tar.gz (32位系统)
#wget http://download.scientificlinux.net/ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz (64位系统)
#wget http://download.scientificlinux.net/mysql-5.1.39-linux-i686-glibc23.tar.gz (32位系统)
#wget http://download.scientificlinux.net/mysql-5.1.39-linux-x86_64-glibc23.tar.gz (64位系统)

2、安装MySQL

# cd /usr/local/src
# tar zxvf mysql-5.1.39-linux-i686-glibc23.tar.gz
# mv mysql-5.1.39-linux-i686-glibc23 /usr/local/
# ln -s /usr/local/mysql-5.1.39-linux-i686-glibc23/ /usr/local/mysql
# groupadd mysql
# useradd -g mysql mysql
# chown -R mysql:mysql /usr/local/mysql
# chown -R mysql:mysql /usr/local/mysql-5.1.39-linux-i686-glibc23/
# cd /usr/local/mysql
# ./scripts/mysql_install_db --user=mysql
# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --level 3 mysqld on
# cp ./support-files/my-huge.cnf /etc/my.cnf
# mv /usr/local/mysql/data /var/lib/mysql
# chown -R mysql:mysql /var/lib/mysql

编辑/etc/my.cnf,在 [mysqld] 段增加

datadir = /var/lib/mysql
skip-innodb
wait-timeout = 10
max_connections = 512
max_connect_errors = 10000000

在 [mysqld] 段修改

max_allowed_packet = 16M
thread_cache_size = CPU个数*2

将 log-bin 注释

# service mysqld start
# bin/mysqladmin -u root password 'password_for_root'
其中引号内的password_for_root是要设置的root密码

3、安装Nginx

# cd /usr/local/src/
# tar zxvf nginx-0.7.63.tar.gz
# cd nginx-0.7.63
# ./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --with-http_realip_module --with-http_addition_module --with-# http_gzip_static_module --with-http_random_index_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_module
# make
# make install
# cp /usr/local/src/nginx /etc/init.d/nginx
# chmod 755 /etc/init.d/nginx
# chkconfig --add nginx
# chkconfig nginx on

4、安装PHP和Zend

# cd /usr/local/src
# tar zxvf php-5.2.10.tar.gz
# gzip -cd php-5.2.10-fpm-0.5.13.diff.gz | patch -d php-5.2.10 -p1
# cd php-5.2.10
# ./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/etc/cgi --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --enable-magic-quotes --with-mysql=/usr/local/mysql --with-pear --enable-sockets --with-ttf --with-freetype-dir=/usr --enable-gd-native-ttf --with-zlib --enable-sysvsem --enable-sysvshm --with-libxml-dir=/usr --enable-force-cgi-redirect --enable-fastcgi --with-xmlrpc --enable-zip --enable-fpm
# make
# make install
# mkdir -p /usr/local/etc/cgi/
# cp php.ini-dist /usr/local/etc/cgi/php.ini
# mv -f /usr/local/src/php-fpm.conf /usr/local/php5/etc/php-fpm.conf
# groupadd www
# useradd -g www www
# echo 'ulimit -SHn 65535' >> /etc/rc.local
# echo '/usr/local/php5/sbin/php-fpm start' >> /etc/rc.local
# cd /usr/local/src
# tar zxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
# cd ZendOptimizer-3.3.3-linux-glibc23-i386
# ./install

(注意第一个要填的路径是Zend安装路径,第二个是php.ini所在的路径,即/usr/local/etc/cgi) (不要选重启apache)

5、启动Nginx和php

# mv -f /usr/local/src/fcgi.conf /usr/local/nginx/conf/
# cp -f /usr/local/src/nginx.conf /usr/local/nginx/conf/nginx.conf
# mkdir -p /home/www/wwwroot
# ulimit -SHn 65535
# /usr/local/php5/sbin/php-fpm start
# service nginx start
在/home/www/wwwroot放入一个index.php,内容为:<?php phpinfo(); ?>
打开浏览器访问,即可看到phpinfo页面

6、设置系统防火墙

编辑/usr/local/sbin/fw.sh,复制以下内容进去

#!/bin/bash
# Stop iptables service first
service iptables stop
# Load FTP Kernel modules
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
# Inital chains default policy
/sbin/iptables -F -t filter
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT accept
# Enable Native Network Transfer
/sbin/iptables -A INPUT -i lo -j ACCEPT
# Accept Established Connections
/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# ICMP Control
/sbin/iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 10 -j ACCEPT
# WWW Service
/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# FTP Service
/sbin/iptables -A INPUT -p tcp --dport 21 -j ACCEPT
# ssh Service
/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT

退出编辑,执行以下命令

# chmod 755 /usr/local/sbin/fw.sh
# echo '/usr/local/sbin/fw.sh' >> /etc/rc.local
# /usr/local/sbin/fw.sh

延伸阅读

评论