PHP技能总结

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

2017-12-14  本文已影响426人  极客小寨
未标题-1.jpg

这一次,好久没有写博客了。工作真是太忙了!新项目,使用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

如果你有更好的心得和建议,欢迎拍砖一起探讨。

欢迎加入【编程技术微分享】,加入(596888158)请留言,或联系QQ:Mr.Chen(1182929304)。

上一篇下一篇

猜你喜欢

热点阅读