centos7.3 64bit + nginx1.11.10 + mysql5.6.35 + php7.0.16 + tomcat6.0.39 + java 1.6.0环境搭建

规划:

软件版本:
centos 7.3 64bit
mysql 5.6.35
nginx 1.11.10 安装ngx_log_if-master ngx_http_substitutions_filter_module http_ssl_module等模块
php 7.0.16 安装php-fpm zend mcrypt openssl opcache gd等模块
java 1.6.0
tomcat 6.0.39

用户环境配置:

# hwclock --set --date="03/21/17 09:10:30" //更新时间
# hwclock --hctosys//把硬件时钟同步到系统时钟
# vi /etc/sysconfig/clock //更改时区,内容如下:

ZONE=Asia/Shanghai
UTC=false
ARC=false

# rm /etc/localtime
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# vi /etc/selinux/config 修改 SELINUX=enforcing
# reboot

# /usr/sbin/groupadd www
# /usr/sbin/useradd -g www www
# passwd www #修改密码为客户VPS的密码
# echo "AllowUsers www" >> /etc/ssh/sshd_config
# systemctl restart sshd.service
# /usr/sbin/groupadd mysql
# /usr/sbin/useradd -g mysql mysql
# mkdir -p /data/htdocs
# chcon -R -t usr_t /data/htdocs
# chown -R www:www /data/htdocs

# yum -y install yum-fastestmirror
# yum clean all
# yum list
# yum -y install wget vixie-cron crontabs
# systemctl start crond.service
# systemctl enable crond.service

安装mysql:

# rpm -qa | grep mysql //找到系统自带的包,用rpm -e全部删除
# rpm -e mysql-libs-5.1.73-3.el6_5.x86_64
# yum install perl libaio -y
# cd ~
# rpm -ivh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
# yum install mysql-server -y
# vi /etc/my.cnf添加如下内容:

[mysqld]
log-bin=mysql-bin
binlog_format=mixed
performance_schema_max_table_instances=6000
table_definition_cache=512
table_open_cache=512
slow_query_log
long_query_time = 2
#slow_query_log_file="/tmp/mysql_slow.log"
#log_slave_updates
#gtid-mode=ON
#enforce-gtid-consistency=ON
explicit_defaults_for_timestamp=true

# systemctl start mysqld.service
# systemctl enable mysqld.service

安装nginx:

# yum -y install wget zip unzip gcc make pcre-devel openssl-devel git
# cd ~
# wget -c http://nginx.org/download/nginx-1.11.10.tar.gz
# tar -zxf nginx-1.11.10.tar.gz
# mkdir -p /usr/local/nginx/
# cd /usr/local/nginx
# wget https://github.com/cfsego/ngx_log_if/archive/master.zip
# unzip master.zip
# git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
# cd ~/nginx-1.11.10
# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-pcre --with-http_realip_module --add-module=/usr/local/nginx/ngx_log_if-master --add-module=/usr/local/nginx/ngx_http_substitutions_filter_module
# make && make install
/**
# vi /etc/init.d/nginx //创建service服务脚本,可以去网上搜索内容,比如http://blog.csdn.net/baiquan17/article/details/53304456
# vi /usr/local/nginx/conf/nginx.conf //编辑nginx配置,内容可以到网上搜,比如http://www.cnblogs.com/chenjiahe/p/5956002.html,或者回复本文留下邮箱索取
**/

# mkdir -p /usr/local/nginx/conf/conf.d/
# chmod +x /etc/init.d/nginx
# chkconfig --add nginx
# chkconfig --level 2345 nginx on
# mkdir /var/log/nginx
# touch /var/log/nginx/error.log
# mv /usr/local/nginx/conf /etc/nginx
# ln -s /etc/nginx /usr/local/nginx/conf
# systemctl restart nginx.service

安装php:

# cd ~
# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# yum install php70w php70w-common php70w-opcache php70w-fpm php70w-gd php70w-mcrypt php70w-mysql php70w-mbstring -y
# rpm -qa | grep httpd
# yum remove httpd -y
# yum remove httpd-tools -y
# setsebool -P httpd_can_network_connect=1

# vi /etc/php.ini修改参数:default_charset = "gb2312"
# vi /etc/php-fpm.d/www.conf 修改以下参数:

user=www
group=www
request_terminate_timeout = 30s
pm.max_children = 50
pm.start_servers = 16
pm.min_spare_servers = 16
pm.max_spare_servers = 50

# vi /etc/php.d/opcache.ini 修改如下参数:

opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=2000
opcache.revalidate_freq=2
opcache.fast_shutdown=1

# systemctl restart php-fpm.service
# systemctl enable php-fpm.service

配置java和tomcat:

# yum list | grep openjdk //搜索到类似下边的安装包,然后安装,根据需求安装1.6.0
# yum install java-1.6.0-openjdk.x86_64 -y
# alternatives --config java //根据需求选择使用1.6.0这个java环境
# java -version //验证java环境生效

# cd ~;mkdir tools;cd tools
# wget http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.39/bin/apache-tomcat-6.0.39.tar.gz
# tar -xzf apache-tomcat-6.0.39.tar.gz;cd apache-tomcat-6.0.39/lib
# wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.44.zip
//解压后把mysql-connector-java-5.1.44-bin.jar放在tomcat lib目录下
# yum -y install apr apr-devel tomcat-native
# cd ~/tools/apache-tomcat-6.0.39/conf
# vi server.xml //在文件底部前加入网站配置代码

# ~/tools/apache-tomcat-6.0.39/bin/startup.sh

修改系统配置:

# systemctl stop firewalld.service
# systemctl disable firewalld.service
# service iptables stop
# iptables -L -n
# iptables -F
# iptables -X
# iptables -L -n
# iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
# iptables -A INPUT -p icmp -j ACCEPT
# iptables -A INPUT -i lo -p all -j ACCEPT
# iptables -P INPUT DROP
# iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited
# iptables -A FORWARD -j REJECT --reject-with icmp-host-prohibited
# iptables -L -n
# yum install iptables-services -y
# service iptables save
# systemctl restart iptables
# systemctl enable iptables
# echo "/bin/systemctl restart mysql.service" >> /etc/rc.local
# echo "/bin/systemctl restart php-fpm.service" >> /etc/rc.local
# echo "/bin/systemctl restart nginx.service" >> /etc/rc.local
# echo "/bin/systemctl restart iptables.service " >> /etc/rc.local
# echo “~/tools/apache-tomcat-6.0.39/bin/startup.sh” >> /etc/rc.local
# reboot