飞嗨,欢迎您的光临,本博所发布之文章皆为作者亲测通过,如有错误,欢迎通过各种方式指正。(本博已于2015.12.6升级到php7,运行环境php7 php-fpm + nginx1.8.0)

服务器环境搭建nginx前置机+apache内网+mysql+redis

Linux lf 2766℃ 0评论

这一次,好久没有写博客了。工作真是太忙了!新项目,使用yii2的框架,基于oauth2.0的授权模式,给app提供接口。服务器做的集群配置,前置机nginx负载后边的apache webserver,redis缓存。搭服务器环境就够忙了,优化配置,测试QPS…忙忙忙,,,真是苦逼的人。

今天,先把搭建服务器的过程写下来…

一.服务器安全设置(修改linux欢迎信息+不允许root登陆+使用公钥登陆+修改ssh默认端口+设置sudo组)

1. vim /etc/motd 修改欢迎信息
2. useradd boysp
3. passwd boysp Boysp2015***
4. vim /etc/ssh/sshd_config PermitRootLogin no PasswordAuthentication no Port 60412
6. su boysp
7. cd && mkdir .ssh && cd .ssh
8. vim authorized_keys 增加keys 非root用户.ssh的权限700 登陆日志/var/log/secure
9.chmod u+w /etc/sudoers boysp ALL=(ALL) ALL chmod u-w /etc/sudoers

二.安装基础依赖

yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel apr apr-devel apr-util apr-util-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel curl curl-devel freetype freetype-devel libmcrypt libmcrypt-devel cmake gcc-c++ ncurses-devel perl-Data-Dumper autoconf

三.安装nginx最新稳定版

1. cd /usr/src
2. wget http://nginx.org/download/nginx-1.8.0.tar.gz 1.8.0为最新stable版本
3. cd nginx-1.8.0
4. ./configure --sbin-path=/usr/local/nginx --conf-path=/etc/nginx.conf --pid-path=/var/run/nginx.pid
5. /usr/local/nginx
6.配置轮询
upstream boyspServer{
   server 127.0.0.1:8080;
}
server {
   listen 80;
   server_name localhost;

   #charset koi8-r;

   #access_log logs/host.access.log main;

   location / {

      proxy_pass http://boyspServer;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   }
}


7.重启 /usr/local/nginx/nginx -s reload


四.安装apache最新稳定版

wget http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.16.tar.gz
tar -xvf httpd-2.4.16.tar.gz && cd httpd-2.4.16
./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --enable-so --enable-cgi --enable-ssl --enable-rewrite --with-ssl --with-pcre --with-z --with-ssl --enable-modules=most --enable-mpms-shared=all --enable-dav
make && make install
cp /usr/local/apache2/bin/apachectl /etc/init.d/
vim /etc/httpd/httpd.conf Listen 8080
service apachectl start

五.安装php最新稳定版

wget http://cn2.php.net/get/php-5.6.11.tar.gz/from/this/mirror
tar -xvf mirror ; cd php-5.6.11
./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-soap --enable-mbstring=all --enable-sockets --enable-fpm --with-apxs2=/usr/local/apache2/bin/apxs --with-gd --with-freetype-dir=/usr/include/freetype2/freetype --with-jpeg-dir=/usr/lib64 --with-zlib --with-iconv --enable-libxml --enable-xml --with-curl --with-mcrypt --with-openssl -with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-intl
make && make install
vim /etc/httpd/httpd.conf AddType application/x-httpd-php .php
六.安装mysql最新稳定版
wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.25.tar.gz
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql
mv /etc/my.cnf /etc/my.cnf.bak
mysql
create database boysp;
create database oauth;
create user 'boysp'@'%' identified by 'password';
grant all privileges on oauth.* to 'boysp'@'%';
grant all privileges on boysp.* to 'boysp'@'%';
flush privileges;

七.安装redis

wget http://pecl.php.net/get/igbinary-1.2.1.tgz
wget https://github.com/phpredis/phpredis/archive/develop.zip
./configure --with-php-config=/usr/local/php/bin/php-config --enable-redis-igbinary

八.使用git

ssh-keygen -t rsa -C "boysp"
HostKey /etc/ssh/ssh_host_rsa_key
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

转载请注明:飞嗨 » 服务器环境搭建nginx前置机+apache内网+mysql+redis

喜欢 (6)or分享 (0)
发表我的评论
取消评论
表情
(5)个小伙伴在吐槽
  1. dsfsdfds
    匿名2018-06-09 14:40 回复
  2. 安德森
    匿名2017-12-11 17:35 回复
    • 欢迎光临
      lf2017-12-12 11:30 回复
  3. 博主,安装php时报configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works. 安装yum install libicu-devel 后解决 重新编译后OK
    匿名2015-09-03 10:04 回复
    • 嗯,是的,每个机器的环境不一样,php依赖的,有的机器已经装上了,有的没装上,所以安装php时,提示缺少哪样依赖,就yum install装上好了
      lf2015-10-10 18:12 回复
粤ICP备15018643号-1