您的位置:首页 > 运维架构 > Linux

【折腾】centos mini安装后安装lnmp~

2012-11-20 11:57 866 查看
自行下载各种包~

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

安装完centos后,检查网络是否通畅 ping -c 1 -t 1 www.baidu.com

安装setup工具

yum install setuptool

这样setup中的工具是不全的,还需要安装

yum install ntsysv     //系统服务管理 

yum install iptables   //防火墙

#安装setup中配套的防火墙设置

yum install system-config-securitylevel-tui

#安装setup中配套的网络设置

yum install system-config-network-tui

安装lrzsz  用于SecureCRT  方便上传文件

yum install -y lrzsz 

然后安装 wget 

yum install wget

然后更新 centos 

yum update -y

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

设置防火墙端口

vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
#新增 80 、3306端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT


重启防火墙

/etc/init.d/iptables restart

不重启的情况下,暂时关闭SELinux

setenforce 0

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

更新安装一些需要的包

yum install -y gcc gcc-c++ make sudo autoconf libtool-ltdl-devel gd-devel freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel curl-devel patch libmcrypt-devel libmhash-devel ncurses-devel bzip2 libcap-devel ntp sysklogd diffutils sendmail
iptables unzip

下载文件都保存在 /usr/local/src 目录下

cd /usr/local/src

wget http://www.cmake.org/files/v2.8/cmake-2.8.10.1.tar.gz
wget http://cdn.mysql.com/Downloads/MySQL-5.5/mysql-5.5.28.tar.gz #下载失败... - -

wget http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz
wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.6.tar.gz 
==========================

yum remove mysql  卸载系统自带的mysql  以免出错

tar zxvf cmake-2.8.10.1.tar.gz

cd cmake-2.8.10.1

./bootstrap

gmake

gmake install

///////////////安装完gmake

tar zxvf bison-2.5.tar.gz

cd bison-2.5

./configure

make 

make install

////////////////////////安装完 bison

cd ../

tar zxvf cd ncurses-5.6.tar.gz 

cd ncurses-5.6

./configure

make

make install

cd ../

/////////////////////////////安装完 ncurses

groupadd -g 27 mysql

useradd -g 27 -u 27 -d /dev/null -s /sbin/nologin mysql

#我将mysql 数据&日志保存在   /var/mysql 下

mkdir -p /var/mysql/data 

chmod 777 /var/mysql/data

tar zxvf mysql-5.5.28.tar.gz

cd mysql-5.5.28

# mysql 将被安装在 /usr/local/mysql/ 目录下    默认使用utf8 字符集

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1
-DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/var/mysql/data

make && make install

chmod +w /usr/local/mysql

chown -R mysql:mysql /usr/local/mysql

ln -s /usr/local/mysql/lib/libmysqlclient.so.18  /usr/lib/libmysqlclient.so.18

mkdir -p /var/mysql/log/

chown -R mysql:mysql /var/mysql/

cp support-files/my-large.cnf /var/mysql/my.cnf  ## my-large.cnf适用于1G内存左右的服务器  可按需求自行选择其他配置文件

cp support-files/my-large.cnf /etc/my.cnf

cp support-files/mysql.server /etc/init.d/mysqld

/// vi /etc/my.cnf 自行按需求修改mysql配置文件

mysql初始化

/usr/local/mysql/scripts/mysql_install_db \

--defaults-file=/var/mysql/my.cnf \

--basedir=/usr/local/mysql \

--datadir=/var/mysql/data \

--user=mysql

设置开机启动

chmod +x /etc/init.d/mysqld

修改 vi /etc/init.d/mysqld

basedir=/usr/local/mysql

datadir=/var/mysql/data

然后执行

chkconfig --add mysqld

chkconfig --level 35 mysqld on

ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

ln -s /usr/local/mysql/bin/mysql_config  /usr/bin/mysql_config

#启动mysql

service mysqld start

     Starting MySQL... SUCCESS!      搞定~

记得添加mysql用户名密码   

 /usr/local/mysql/bin/mysqladmin -u root password root   (测试用 所以密码写了 root)

试试登录mysql 

mysql -u root -p 

然后输入密码

输入命令 show databases;    

如果输出

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

+--------------------+

4 rows in set (0.03 sec)

OK~ 没问题

exit      退出mysql

================================mysql 安装完毕

tar zxvf pcre-8.31.tar.gz

cd pcre-8.31

./configure --prefix=/usr

make 

make install

==============nginx所需的pcre库安装完毕

groupadd -g 1000 www

useradd -g 1000 -u 1000 -d /dev/null -s /sbin/nologin www

mkdir -p /var/www/wwwlogs

mkdir -p /var/www/default

chown -R www.www /var/www

tar zxvf nginx-1.2.5.tar.gz 

cd nginx-1.2.5

./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --without-http_rewrite_module --with-http_ssl_module --with-pcre 

make && make install

ln -s /lib64/libpcre.so.0.0.1     /lib64/libpcre.so.1

vi /usr/local/nginx/conf/nginx.conf  编辑配置

user  www www;
worker_processes 3;
error_log  logs/error.log  notice;
pid        logs/nginx.pid;

worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include       mime.types;
default_type  application/octet-stream;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;

sendfile on;
tcp_nopush on;

keepalive_timeout 60;
tcp_nodelay on;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;

gzip on;
gzip_min_length  1k;
gzip_buffers     4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types       text/plain application/x-javascript text/css application/xml;
gzip_vary on;

#limit_zone  crawler  $binary_remote_addr  10m;
#log format

log_format  wwwlogs  '$remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for';

include vhost/*.conf;
}


mkdir /usr/local/nginx/conf/vhost

vi /usr/local/nginx/conf/vhost/default.conf

server
{
    listen       80;
    server_name localhost;
    index index.html index.htm default.html default.htm index.php default.php;
    root  /var/www/default;
    location ~ .*\.(php|php5)?$
    {
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    }
    location ~ .*\.(js|css)?$
    {
        expires      12h;
    }
    access_log  /var/www/wwwlogs/default.access.log;
}


/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf  启动nginx

修改配置后 重新加载配置
/usr/local/nginx/sbin/nginx -s reload

新建一个nginx管理脚本

vi /etc/init.d/nginx   然后输入下面的内容  注意目录是否和自己安装nginx的目录相符!!!

#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults'
4000
, or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx'
### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}
do_reload() {
kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0


chmod +x /etc/init.d/nginx

chkconfig --add nginxd

chkconfig --level 35 nginx on 

然后  启动nginx

service nginx start   启动nginx

service nginx restart 重启nginx

service nginx stop 停止nginx

测试nginx 是否成功运行

 vi /var/www/default/index.html

输入  nginx start!!!!

在本机上 浏览器打开你虚拟机中centos的ip  ,如果不知道就 输入 ifconfig 查看

======================nginx 安装完毕

tar zxvf libiconv-1.14.tar.gz 

cd libiconv-1.14

./configure --prefix=/usr/local

make 

make install

tar zxvf libmcrypt-2.5.8.tar.gz 

cd libmcrypt-2.5.8

./configure 

make 

make install

tar zxvf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9/

./configure

make

make install

 tar zxvf php-5.4.8.tar.gz 

ln -s /usr/lib/x86_64-linux-gnu/libssl.* /usr/lib/

ln -s /usr/local/lib/libmcrypt.* /usr/lib64/

ln -s /usr/local/lib/libmhash.*  /usr/lib64/

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

ln -sv /usr/lib64/libldap* /usr/lib/

cd php-5.4.8

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --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 --with-curlwrappers --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-zip --enable-soap


make ZEND_EXTRA_LIBS='-liconv'

make install

cp php.ini-production /usr/local/php/etc/php.ini

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm

chkconfig php-fpm on

cp /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf

vi /usr/local/php/etc/php-fpm.conf  修改其中配置

pid = run/php-fpm.pid
user = www
group = www


service php-fpm start  启动php

service php-fpm restart 重启php

service php-fpm stop 停止php

vi /var/www/default/index.php

<?php

phpinfo();

?>

保存 , 浏览器访问虚拟机ip




PHP Version 5.4.8

SystemLinux Z 2.6.32-279.14.1.el6.x86_64 #1 SMP Tue Nov 6 23:43:09 UTC 2012 x86_64
Build DateNov 20 2012 19:25:05
Configure Command'./configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--with-mysql=/usr/local/mysql' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-iconv-dir=/usr/local' '--with-freetype-dir' '--with-jpeg-dir' '--with-png-dir' '--with-zlib'
'--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-discard-path' '--enable-safe-mode' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl' '--with-curlwrappers' '--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-zip' '--enable-soap'
搞定php~   

=======================未完待续   还有 memcache   redis mongodb 什么的~ 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: