引言
因为要在内网搭建模拟测试环境,所以这里记录一下吧,以后也方便.所谓的LNRP即Ubuntu + Nginx + Redis + PHP + Mysql
配置ssh
这里使用的是openssh,这里的配置是为了尽可能的提高安全性
禁止root用户登陆
PermitRootLogin no
只允许公私钥认证的方式登陆,防止口令暴力破解
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
PasswordAuthentication no
修改密钥长度
ServerKeyBits 2048
搭建redis
ubuntu10.04自带源上的redis版本太旧,需要从ppa安装
安装ppa工具
sudo apt-get install python-software-properties
添加ppa源
sudo add-apt-repository ppa:schwuk/redis
安装redis
sudo apt-get install redis-server
修改redis配置文件
sudo vim /etc/redis/redis.conf
(ps:可指定访问密码和修改bind的ip地址)
安装php&&php扩展
预安装软件
apt-get install make gcc g++ automake libtool libmysqlclient16 libxml2-dev libexpat1-dev mysql-client
安装php和fpm
添加ppa源
sudo add-apt-repository ppa:yola/php5
安装php5-fpm
sudo apt-get install php5 php5-fpm
安装pecl
sudo apt-get install php5-dev php-pear
安装curl扩展
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
安装memcache扩展
sudo apt-get install php5-memcache php5-memcached
安装mysql扩展
sudo apt-get install php5-mysql
安装http扩展
sudo apt-get install libcurl4-openssl-dev
sudo apt-get install libmagic-dev
sudo pecl install pecl_http
安装oauth扩展
sudo apt-get install libpcre3-dev
sudo pecl install oauth (需要perl-compatible regular expression library)
安装gd扩展
sudo apt-get install php5-gd
搭建nginx虚拟主机
共享一下我的nginx.conf配置文件
user www-data;
worker_processes 4;
worker_cpu_affinity 1000 0100 0010 0001;
worker_rlimit_nofile 65535;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 768;
multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 60;
server_names_hash_bucket_size 64;
client_header_buffer_size 2k;
large_client_header_buffers 4 4k;
#通过nginx上传文件的大小
client_max_body_size 8m;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$server_name|$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;
error_log /var/log/nginx/error.log;
open_file_cache max=204800 inactive=20s;
open_file_cache_min_uses 1;
open_file_cache_valid 30s;
gzip on;
include /etc/nginx/conf.d/*.conf;
}
根据需要搭建虚拟主机
这里由于隐私大家网上搜一下就行,而且我之前有文章写过搭建nginx+fpm虚拟主机的方法
修改/etc/hosts文件
修改/etc/hosts文件,保持通信双方的相同测试环境,具体见链接:
Linux修改/etc/hosts
部署nginx&&fpm按天分割脚本
Nginx日志按天分割,之前写的一篇博客,crontab定时运行即可
搭建mysql
安装mysql
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导出指定数据库上传到指定服务器的脚本
#!/bin/bash -
#1.数据库备份参数配置
mysqlhost="your_mysql_ip"
mysqluser="****"
mysqlpasswd="****"
mysqldb="db_name"
tablenames=("table_name1")
dbtime=`date -d '+0 days' +%Y%m%d`
export_directory="/home/user/sql/$dbtime"
remote_dir="/home/user/sql/back/"
ip_array=("192.168.1.***")
#定义数据备份目录
if [ ! -d $export_directory ]
then
mkdir -p $export_directory
fi
cd $export_directory
#2.mysqldump备份数据库数据
for tablename in ${tablenames[*]}
do
#定义数据备份文件名
dbfile="$tablename-$dbtime.sql"
#导出mysql数据
mysqldump -h$mysqlhost -u$mysqluser -p$mysqlpasswd $mysqldb $tablename >$dbfile
#采用tar压缩备份存储的sql文件
tar -zcPpf $tablename-$dbtime.tar.gz $dbfile
#删除大容量文件
if [ $? = 0 ]
then
rm $dbfile
fi
#同步数据库备份到指定服务器
for ip in ${ip_array[*]}
do
port="your_port"
scp -P $port $tablename-$dbtime.tar.gz username@$ip:$remote_dir
done
done
搭建coreseek全文搜索引擎
参考官方文档搭建即可,
http://www.coreseek.cn/products-install/install_on_macosx/