lnmp 环境安装

1)修改更新源
升级系统更新 yum update

安装nginx版本为0.8.36

一。下载nginx

下载地址:http://www.nginx.org/

选择nginx-0.8.36

将该下载包拷贝到/usr/local/下(随意了,找个地方就好)

二。安装

cd /usr/local/

tar zxvf nginx-0.8.36.tar.gz

cd nginx-0.8.36

按照一些网络资料的介绍,执行如下命令即可完成安装

./configure

make

make install

但在实际安装过程中会,执行./configure时,根据系统的配置不同会有不同的错误提示,这里不罗嗦了,安装nginx需要安装openssl和 pcre,

openssl在linux下svn的安装中有过介绍,这里不再赘述,下面只介绍一下pcre的安装,如下:

下载pcre:http://sourceforge.net/projects/pcre/files/ ,选择pcre-8.02.tar.gz,拷贝到/usr/local/下

tar -zxvf pcre-8.02.tar.gz

cd pcre-8.02

./configure --prefix=/usr/local/pcre

make

make install

ok,pcre安装完成

接着我们安装nginx,

cd /usr/local/nginx-0.8.36

./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre-8.02 --with-http_ssl_module --with-openssl=/usr/local/openssl-0.9.8o

make

make install

ok,nginx安装完成。

三。配置

修改 /usr/local/pcre/conf/nginx.conf 来满足自己的需求,下面给一个负载的小实例
Java代码 复制代码 收藏代码

user nginx;#确保存在这个用户
worker_processes 2;

error_log /var/log/nginx/error.log info;#确保路径存在

pid logs/nginx.pid;


events {
worker_connections 1024;
multi_accept on;
use epoll;
}


http {
include mime.types;
default_type application/octet-stream;

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

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 30;

#gzip on;

server_names_hash_bucket_size 128;
upstream tomcats {
server 192.168.0.104:8888 weight=3;
server 192.168.2.94:8888 weight=2;
ip_hash;

}

server {
listen 80;

charset gb2312;
add_header test private;

location / {
root /usr/local/test/boss/test;
index index.html index.htm index.jsp;

proxy_pass http://tomcats;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout 10;
proxy_send_timeout 15;
proxy_read_timeout 15;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

}

}

注意,这里nginx监听80端口,所以要在iptables里打开80端口。

启动nqinx:

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

接着访问这台机器的80的端口,如果请求成功,则说明配置成功。

为了操作方便,可以自己写一个nginx命令脚本,放到/etc/init.d下,并赋予其执行权限即可,详见附件,执行方法如下:

启动:service nginx start

停止:service nginx stop

重启:service nginx reconfigure

查看状态:service nginx status


安装mysql-5.6.12

2)安装一些mysql需要的依赖包
#yum install -y wget gcc-c++ ncurses-devel cmake make perl

wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.12.tar.gz

mv /etc/my.cnf /etc/mysql.cof.back

groupadd mysql
useradd -g mysql mysql

mkdir -p /usr/local/web/mysql 程序目录
mkdir /home/mysql/data 数据目录

tar -zxvf mysql-5.6.12.tar.gz

cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/web/mysql
-DMYSQL_UNIX_ADDR=/usr/local/web/mysql/mysql.sock
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_MEMORY_STORAGE_ENGINE=1
-DWITH_READLINE=1
-DENABLED_LOCAL_INFILE=1
-DMYSQL_DATADIR=/home/mysql/data
-DMYSQL_USER=mysql
-DMYSQL_TCP_PORT=3306

make
make install

修改目录权限
chown -R mysql:mysql /usr/local/web/mysql/
chown -R mysql:mysql /home/mysql/data/

加入环境变量
vi /etc/profile
加入一下两句
PATH=$PATH:/usr/local/web/mysql/bin:/usr/local/web/mysql/lib/
export PATH
保存推出,让其立即生效
source /etc/profile

执行初始化配置脚本,创建系统自带的数据库和表。
/usr/local/web/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/web/mysql --datadir=/home/mysql/data

复制服务启动脚本
cp /usr/local/web/mysql/support-files/mysql.server /etc/init.d/mysqld

启动
service mysqld start

设置开机启动
chkconfig --level 35 mysqld on

修改root密码
mysqladmin -u root password 'new-password'


3)php安装

yum -y install libmcrypt-devel mhash-devel libxslt-devel
libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel
zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel
ncurses curl curl-devel e2fsprogs e2fsprogs-devel
krb5 krb5-devel libidn libidn-devel openssl openssl-devel

安装libmcrypt
wget http://www.51osos.com/uploads/soft/libmcrypt-2.5.8.tar.gz
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt
make && make install


下载php 5.4.16
wget http://www.php.net/get/php-5.4.16.tar.gz/from/this/mirror
http://www.php.net/get/php-5.4.23.tar.gz/from/this/mirror

tar -zxvf php-5.4.16.tar.gz
cd php-5.4.16


./configure --prefix=/usr/local/web/php --with-config-file-path=/usr/local/web/php/etc --enable-fpm --enable-safe-mode --enable-inline-optimization
--with-mysql=mysqlnd --with-mysqli=mysqlnd -enable-pdo --with-pdo-mysql
--disable-debug --disable-rpath
--enable-mbstring --with-curl --with-curlwrappers --with-bz2 --with-zlib --enable-zip
--with-jpeg-dir --with-png-dir --with-gd --with-freetype-dir --enable-gd-native-ttf
--enable-sockets --enable-soap
--enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex
--with-mhash --with-pcre-regex --with-mcrypt=/usr/local/libmcrypt
--with-iconv --with-libxml-dir=/usr --enable-xml --enable-bcmath --with-openssl

make && make install

cp php.ini-production /usr/local/web/php/etc/php.ini
cd /usr/local/web/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf

user = www
group = www
pm.start_servers = 200
pm.min_spare_servers = 50
pm.max_spare_servers = 350

创建用户
groupadd www
useradd -g www www

INT, TERM 立刻终止
QUIT 平滑终止
USR1 重新打开日志文件
USR2 平滑重载所有worker进程并重新载入配置和二进制模块

php-fpm 启动
/usr/local/web/php/sbin/php-fpm
php-fpm 关闭:
kill -INT `cat /usr/local/web/php/var/run/php-fpm.pid`
php-fpm 重启:
kill -USR2 `cat /usr/local/web/php/var/run/php-fpm.pid`
查看php-fpm进程数:
ps aux | grep -c php-fpm

4)Nginx
安装如果报错为Nginx: error while loading shared libraries: libpcre.so.1
具体网站可参考http://www.2cto.com/os/201304/199770.html
找到libpcre.so.1文件路径
ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1
ln -s /usr/local/lib/libpcre.so.1 /lib64/


关闭Nginx
ps -ef | grep nginx
kill -quit 进程号
启动Nginx
./nginx -c /usr/local/web/nginx/conf/nginx.conf

./nginx -s reload

Nginx.conf文件重要修改

location ~ ^/feedback/.+.php$ {
root /home/web/yqbb/bgskk/app/htdocs;
rewrite /feedback/(.*.php?) /$1 break;
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

5)SVN
安装SNV
yum install subversion

建立SVN库
mkdir /home/svn/p2p
svnadmin create /home/svn/p2p

配置SNV
cd /home/svn/p2p/conf

修改passwd 添加SVN用户名和密码
[users]
yangjia=123456
用户名=密码

修改authz 修改用户文件使用权限
[/]
yangjia=rw

修改snvserv.conf 配置SVN服务
anon-access = none # 使非授权用户无法访问
auth-access = write # 使授权用户有写权限
password-db = password
authz-db = authz # 访问控制文件
realm = /home/svn/p2p # 认证命名空间,subversion会在认证提示里显示,并且作为凭证缓存的关键字。

启动SVN
svnserve -d -r /home/svn/p2p

停止SVN
ps -aux | grep svnserve
kill -quit 进程号

设置SVN钩子脚本

进入版本库下的hooks目录
cd /home/svn/p2p/hooks/

将post-commit.tmpl 复制为 post-commit
cp post-commit.tmpl post-commit

给post-commit可执行权限
chmod 0777 post-commit


修改文件
给mailer加上注释,具体语言有en_US.UTF-8、zh_CN.UTF-8、zh_CN.GB2312。
svn name处改成一个有参与权限的svn账号,后面的svn pass是密码

vi post-commit

#mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf
export LANG=en_US.UTF-8
SVN=/usr/bin/svn
STATIC_DIR=/home/www/p2p
${SVN} update ${STATIC_DIR} --username "svn name" --password "svn pass"

Linux 设置最大文件打开数

1)ulimit -n 65536

2)通过VI打开/etc/security/limits.conf
加入* - nofile 65536

VI打开/etc/sysctl.conf
加入fs.file-max = 65536

原文地址:https://www.cnblogs.com/yangchunlong/p/8303362.html