msyql+apache+tomcat+nginx 安装手册

1.软件环境:
jdk-6u10-linux-i586.bin
mysql-enterprise-gpl-5.0.78-linux-i686.tar.gz
apache-tomcat-6.0.20.tar.gz
httpd-2.0.54.tar.gz
nginx-0.7.61.tar.gz

2.安装
a.安装jdk
# cd /usr/local/
# mkdir jdk
# cp /server/install/jdk-6u10-linux-i586.bin /usr/local/jdk
# cd jdk
# chmod +x jdk-6u10-linux-i586.bin
# ./jdk-6u10-linux-i586.bin
#------------- cd /usr/java/
#--------- ln -s /usr/java/jdk /usr/local/java

修改profile:
# vi /etc/profile
添加如下内容
JAVA_HOME=/usr/local/jdk/jdk1.6.0_10
CLASSPATH=/usr/local/jdk/jdk1.6.0_10/lib/dt.jar:/usr/local/jdk/jdk1.6.0_10/lib/tools.jar
PATH=/usr/local/jdk/jdk1.6.0_10/bin:$PATH
export PATH JAVA_HOME CLASSPATH


b.安装mysql
方法一:免安装
* MySQL免安装版/二进制版软件,不用编译,下载地址:http://dev.mysql.com/downloads/
文件格式:mysql-enterprise-gpl-5.0.78-linux-i686.tar.gz

* 创建mysql组,建立mysql用户并加入到mysql组中。

不同版本的Unix中,groupadd和useradd的语法可能会稍有不同。
#groupadd mysql
#useradd -g mysql mysql

* 进入目录/usr/local,解压缩免安装版,并在此目录中建立名为mysql的软链接。
#cd /usr/local
#gunzip < /path/to/mysql-enterprise-gpl-5.0.78-linux-i686.tar.gz | tar xvf -

该命令会在本目录下创建一个名为MYSQL-VERSION-OS的新目录。
使用GNU tar,则不再需要gunzip。你可以直接用下面的命令来解包和提取分发:
#> tar zxvf /path/to/mysql-enterprise-gpl-5.0.78-linux-i686.tar.gz)
#ln -s mysql-enterprise-gpl-5.0.78-linux-i686 mysql

* 添加MySQL配置文件。
如果你想要设置一个选项文件,使用support-files目录中的一个作为模板。在这个目录中有4个模板文件,是根据不同机器的内存定制的。
#cp support-files/my-medium.cnf /etc/my.cnf
可能你需要用root用户运行这些命令。

* 设定目录访问权限,用mysql_install_db创建MySQL授权表初始化,并设置mysql,root帐号访问权限。
#cd mysql
#chown -R mysql .
#chgrp -R mysql .
#scripts/mysql_install_db --user=mysql
#chown -R root .
#chown -R mysql data

注意以上命令中的" . "符号不能少。

* 运行mysql
#bin/mysqld_safe --user=mysql
如果没有问题的话,应该会出现类似这样的提示:
[1] 42264
# Starting mysqld daemon with databases from /usr/local/mysql/var
如果出现 mysql ended这样的语句,表示Mysql没有正常启动,你可以到log中查找问题,Log文件的通常在/etc/my.cnf中配置。大多数问题是权限设置不正确引起的。

* 设置root密码。默认安装密码为空,为了安全你需要修改密码。

#/usr/local/mysql/bin/mysqladmin -uroot password yourpassword

* 拷贝编译目录的一个脚本,设置开机自动启动。
#cp support-files/mysql.server /etc/rc.d/init.d/mysqld
#chmod 700 /etc/init.d/mysqld
#chkconfig --add mysqld
#chkconfig --level 345 mysqld on

* 启动/关闭mysqld服务。
关闭
#service mysqld stop
启动
#service mysqld start

使用下面命令启动、停止mysql
  启动mysql
  /etc/init.d/mysql start 或 service mysql start

  停止mysql
  /etc/init.d/mysql stop 或 service mysql stop

* 查看3306端口是否打开。要注意在防火墙中开放该端口。
#netstat -atln

* 授权mysql的root用户
#mysql -u root -p  (默认的root用户没有设置密码)
Enter password:    (直接Enter)

mysql> use mysql;   (此DB存放MySQL的各种配置信息)
Database changed
mysql> select host,user from user; (查看用户的权限情况)
+-------------+-------+
| host            | user    |
+-------------+-------+
| build            |           |
| build            | root    |
| localhost      |           |
| localhost      | root    |
+-------------+-------+
6 rows in set (0.02 sec)

#mysql> Grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
mysql> flush privileges;  (运行为句才生效,或者重启MySQL)
mysql>exit

方法二:安装rmp版
* 以MySQL-server-4.0.14-0.i386.rpm为例,放在/data目录下
   cd /data
   rpm -ivh MySQL-server-4.0.14-0.i386.rpm

   安装完成后在/usr/share/mysql目录中会有一个mysql的启动脚本mysql.server及示例配置文件等(如my-huge.cnf、my-large.cnf、my-medium.cnf)
  * 拷贝一个示例配置文件作为mysql的配置文件:
   cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

  * rpm包安装完后自动将mysql安装成系统服务,所以可以使用下面命令启动、停止mysql
   启动mysql
   /etc/init.d/mysql start 或 service mysqld start

  停止mysql
   /etc/init.d/mysql stop 或 service mysqld stop
  到此,mysql服务就安装配置完成。
  
* 安装mysql客户端
   rpm -ivh MySQL-client-4.0.14-0.i386.rpm

  * mysql安装好后目录结构如下:
  工具程序在/usr/bin目录中---ls /usr/bin/mysql*

  服务器程序/usr/sbin/mysqld

  数据目录/var/lib/mysql

  默认情况下mysql将错误日志文件、二进制日志文件及进程文件写在/var/lib/mysql目录中,如localhost.err、localhost.pid、localhost-bin.001等

  要改变这些情况可以修改/etc/my.cnf文件

  如将日志文件写在/var/log目录中,可以在my.cnf文件中加入下面两行:

  [mysqld_safe]
  err-log = /var/log/mysqld.log

  有个实用程序/usr/bin/mysql_install_db,该程序可以用来初始化 mysql数据库,即创建/var/log/mysql目录,及创建mysql数据库(mysql授权表等信息)及test数据库(空库),如果不小心删除了/var/log/mysql目录可以通过该程序来初始化.

  卸载mysql
  rpm -qa|grep -i mysql
  rpm -ev MySQL-server-4.0.14-0 MySQL-client-4.0.14-0

  卸载后/var/lib/mysql中的数据及/etc/my.cnf不会删除,如果确定没用后就手工删除
  rm -f /etc/my.cnf
  rm -rf /var/lib/mysql


   *  配置编码
    my.cnf
    [mysql]
default-character-set=utf8
    [mysqld]
    default-character-set=utf8
    default-storage-engine=INNODB

show variables like 'character\_set\_%';


c.安装tomcat
tar xvfz apache-tomcat-6.0.20.tar.gz
cp -R apache-tomcat-6.0.20 /usr/local/tomcat

CATALINA_HOME="/usr/local/tomcat_manage"
JAVA_HOME="/usr/local/jdk1.6.0_10"
JAVA_OPTS="-server -XX:PermSize=128M -XX:MaxPermSize=256M -Xms128m -Xmx1024m -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true"


d.安装httpd
# cd /usr/local/
# tar xvfz httpd-2.0.54.tar.gz
# cd httpd-2.0.54
# ./configure --prefix=/usr/local/apache --enable-module=so
# make
# make install
# cd /usr/local/apache/conf
# vi ./httpd.conf

将Listen 80 修改为Listen 127.0.0.1:80 (219行)
将ServerName 修改为ServerName LocalHost:80 (291行)
在DirectoryIndex中添加 index.jsp (394行)

# cd /usr/local/apache/bin/
# ./apachectl configtest

显示Syntax ok则表明安装成功
#./apachectl start

启动apache服务,浏览器中访问本机80端口,查看端口是否正常,输入127.0.0.1:80
# ./apachectl stop

关闭服务

e.安装nginx
# tar zxfv nginx-0.7.61.tar.gz
# cd nginx-0.7.61/
# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module
# make && make install

如果error:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

# rpm -qa|grep pcre
# rpm -ivh pcre-devel-6.6-1.1.i386.rpm

* 测试配置文件
# /usr/local/nginx/sbin/nginx -t

* 启动
nginx

* 查看
ps fax

# wget http://ncu.dl.sourceforge.net/project/pcre/pcre/7.9/pcre-7.9.tar.gz
* 解压
# tar zxf pcre-7.9.tar.gz
* 配置编译参数
# cd pcre-7.9
# ./configure --prefix=/usr
* 编译PCRE
# make
* 安装PCRE
# make install
完成PCRE安装

* 下载nginx0.7.61最新安装包
# wget http://sysoev.ru/nginx/nginx-0.7.61.tar.gz
* 解压
# tar zxf nginx-0.7.61.tar.gz
* 配置编译参数
# cd nginx-0.7.61
# ./configure --user=webmaster \
--group=users \
--prefix=/opt/nginx \
--with-http_flv_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--http-client-body-temp-path=/opt/nginx/temp/client_body_temp \
--http-proxy-temp-path=/opt/nginx/temp/proxy_temp \
--http-fastcgi-temp-path=/opt/nginx/temp/fastcgi_temp

* 编译nginx
# make
* 安装nginx
# make install
* 完成nginx安装

* 启动/停止nginx进程
# 启动
/app/nginx/sbin/nginx
# 停止
/app/nginx/sbin/nginx -s stop
# 当前所有连接请求完成后停止
/app/nginx/sbin/nginx -s quit
# 重启
/app/nginx/sbin/nginx -s reopen
# 重新加载配置文件
/app/nginx/sbin/nginx -s reload
# 设置开机自启动
  echo /app/nginx/sbin/nginx >> /etc/rc.local

f.安装PHP
* 编译安装PHP(FastCGI模式)
tar zxvf php-5.2.5.tar.gz
cd php-5.2.5/
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-mysql=/usr/local/mysql \
--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir \
--enable-xml --disable-debug --disable-rpath --enable-discard-path --enable-fastcgi \
--enable-force-cgi-redirect --enable-mbstring
make
make install
cp php.ini-dist /usr/local/php/etc/php.ini

* 编译安装PHP5扩展模块
tar zxvf memcache-2.2.1.tgz
cd memcache-2.2.1/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
cd php-5.2.5/ext/gd/
/usr/local/php/bin/phpize
./configure --with-jpeg-dir --with-png-dir --with-zlib-dir --with-ttf --with-freetype-dir --with-php-config=/usr/local/php/bin/php-config
make
make install

* 修改php.ini文件
手工修改:查找/usr/local/php/etc/php.ini中的extension_dir = "./"
修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
并在此行后增加以下几行,然后保存:
extension = "memcache.so"
extension = "gd.so"

* 创建www用户和组,以及其使用的目录:
/usr/sbin/groupadd www -g 48
/usr/sbin/useradd -u 48 -g www www
mkdir -p /data0/vshare/htdocs
chmod +w /data0/vshare/htdocs
chown -R www:www /data0/vshare/htdocs

* 安装lighttpd中附带的spawn-fcgi,用来启动php-cgi
注:压缩包中的spawn-fcgi程序为已经编译成二进制的版本。
cp spawn-fcgi /usr/local/php/bin
chmod +x /usr/local/php/bin/spawn-fcgi

* 启动php-cgi进程,监听127.0.0.1的10080端口,进程数为64(如果服务器内存小于3GB,可以只开启25个进程),用户为www:
/usr/local/php/bin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 64 -u www -
f /usr/local/php/bin/php-cgi

g.其它修改
* 拷贝
cp -r apache-tomcat-6.0.20/* /usr/local/tomcat 拷贝apache-tomcat-6.0.20下所有文件到/usr/local/tomcat下
rm -r -f -rf ****   删除-r目录下所有文件,需确认 -f 不需确定

* 检查gcc是否安装
rpm -q gcc

* 检查pcre
rpm -qa|grep pcre

* 安装
rpm -ivh gcc-4.1.2-14.el5.i386.rpm

* 修改iptables文件:(配置允许端口)
vi /etc/sysconfig/iptables
增加:
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
如要开21等端口就把3306替换成21端口即可。
重启iptable:
service iptables restart

* 更改时间:
#date -s 07/26/2005
#date -s 14:04:00

猜你喜欢

转载自zhb1208.iteye.com/blog/811990