LNMP环境的搭建

来源:互联网 发布:淘宝旺旺铃声 编辑:程序博客网 时间:2024/05/14 11:06


目录

引言

因为要在内网搭建模拟测试环境,所以这里记录一下吧,以后也方便.所谓的LNRP即Ubuntu + Nginx + Redis + PHP + Mysql

配置ssh

这里使用的是openssh,这里的配置是为了尽可能的提高安全性

禁止root用户登陆

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. PermitRootLogin no  

只允许公私钥认证的方式登陆,防止口令暴力破解

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. RSAAuthentication yes  
  2. PubkeyAuthentication yes  
  3. AuthorizedKeysFile      %h/.ssh/authorized_keys  
  4. PasswordAuthentication no  

修改密钥长度

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. ServerKeyBits 2048  


搭建redis

ubuntu10.04自带源上的redis版本太旧,需要从ppa安装

安装ppa工具

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install python-software-properties  

添加ppa源

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. sudo add-apt-repository ppa:schwuk/redis  

安装redis

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install redis-server  

修改redis配置文件

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. sudo vim /etc/redis/redis.conf  
  2. (ps:可指定访问密码和修改bind的ip地址)  


安装php&&php扩展


预安装软件

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. apt-get install make gcc g++ automake libtool libmysqlclient16 libxml2-dev libexpat1-dev mysql-client  

安装php和fpm


添加ppa源
[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. sudo add-apt-repository ppa:yola/php5  


安装php5-fpm
[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install php5 php5-fpm  

安装pecl

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install php5-dev php-pear  

安装redis扩展

安装git工具

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install git-core  

参考链接:https://github.com/nicolasff/phpredis

安装curl扩展

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install curl libcurl3 libcurl3-dev php5-curl  

安装memcache扩展

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install php5-memcache php5-memcached  

安装mysql扩展

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install php5-mysql  

安装http扩展

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install libcurl4-openssl-dev  
  2. sudo apt-get install libmagic-dev  
  3. sudo pecl install pecl_http  


具体使用见之前文章

安装oauth扩展

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install libpcre3-dev  
  2. sudo pecl install oauth  (需要perl-compatible regular expression library)  

安装gd扩展

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install php5-gd  


搭建nginx虚拟主机

共享一下我的nginx.conf配置文件


[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. user www-data;  
  2.   
  3. worker_processes 4;  
  4. worker_cpu_affinity 1000 0100 0010 0001;  
  5.   
  6. worker_rlimit_nofile    65535;  
  7.   
  8. pid /var/run/nginx.pid;  
  9.   
  10. events {  
  11.     use epoll;  
  12.     worker_connections 768;  
  13.     multi_accept on;  
  14. }  
  15.   
  16. http {  
  17.     sendfile on;  
  18.     tcp_nopush on;  
  19.     tcp_nodelay on;  
  20.   
  21.     keepalive_timeout 60;  
  22.   
  23.     server_names_hash_bucket_size 64;  
  24.     client_header_buffer_size 2k;  
  25.     large_client_header_buffers 4 4k;  
  26.     #通过nginx上传文件的大小  
  27.     client_max_body_size 8m;  
  28.   
  29.     include /etc/nginx/mime.types;  
  30.     default_type application/octet-stream;  
  31.   
  32.     log_format  main  '$server_name|$remote_addr|$remote_user[$time_local]|"$request"'  
  33.                       '$status$body_bytes_sent"|$http_referer"'  
  34.                       '"$http_user_agent"|"$http_x_forwarded_for"';  
  35.   
  36.     access_log /var/log/nginx/access.log    main;  
  37.     error_log /var/log/nginx/error.log;  
  38.   
  39.     open_file_cache max=204800 inactive=20s;  
  40.     open_file_cache_min_uses 1;  
  41.     open_file_cache_valid 30s;  
  42.   
  43.     gzip on;  
  44.   
  45.     include /etc/nginx/conf.d/*.conf;  
  46. }  


根据需要搭建虚拟主机


这里由于隐私大家网上搜一下就行,而且我之前有文章写过搭建nginx+fpm虚拟主机的方法

修改/etc/hosts文件


修改/etc/hosts文件,保持通信双方的相同测试环境,具体见链接:Linux修改/etc/hosts

部署nginx&&fpm按天分割脚本

Nginx日志按天分割,之前写的一篇博客,crontab定时运行即可



搭建mysql


安装mysql

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. sudo apt-get install  mysql-server  


配置mysql默认编码

http://blog.csdn.net/zinss26914/article/details/8035902

mysql远程连接

  • 修改bind-address = server_ip
  • 授权远程访问 grant all privileges on  *.* to 'user'@'remote_ip'  identified by 'password';
  • 刷新权限使生效 flush privileges

共享mysql导出指定数据库上传到指定服务器的脚本

[plain] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #!/bin/bash -   
  2. #1.数据库备份参数配置  
  3. mysqlhost="your_mysql_ip"  
  4. mysqluser="****"  
  5. mysqlpasswd="****"  
  6. mysqldb="db_name"  
  7. tablenames=("table_name1")  
  8. dbtime=`date -d '+0 days' +%Y%m%d`  
  9. export_directory="/home/user/sql/$dbtime"  
  10. remote_dir="/home/user/sql/back/"  
  11. ip_array=("192.168.1.***")  
  12. #定义数据备份目录  
  13. if [ ! -d $export_directory ]  
  14. then  
  15.     mkdir -p $export_directory  
  16. fi  
  17. cd $export_directory  
  18.   
  19.   
  20. #2.mysqldump备份数据库数据  
  21. for tablename in ${tablenames[*]}  
  22. do  
  23.     #定义数据备份文件名  
  24.     dbfile="$tablename-$dbtime.sql"  
  25.     #导出mysql数据  
  26.     mysqldump -h$mysqlhost -u$mysqluser -p$mysqlpasswd $mysqldb $tablename >$dbfile  
  27.     #采用tar压缩备份存储的sql文件  
  28.     tar -zcPpf $tablename-$dbtime.tar.gz  $dbfile  
  29.     #删除大容量文件  
  30.     if [ $? = 0 ]  
  31.     then  
  32.         rm $dbfile  
  33.     fi  
  34.     #同步数据库备份到指定服务器  
  35.     for ip in ${ip_array[*]}  
  36.     do  
  37.         port="your_port"  
  38.         scp -P $port $tablename-$dbtime.tar.gz username@$ip:$remote_dir  
  39.     done  
  40. done  


搭建coreseek全文搜索引擎

参考官方文档搭建即可,http://www.coreseek.cn/products-install/install_on_macosx/


0 0
原创粉丝点击