腾讯云Centos7安装Apache +MySQL+PHP +JDK +Tomcat
安装防火墙
Centos7.0系统默认用firewall防火墙,先要停止firewall,然后安装iptables防火墙。注意在Centos7.0版本下,/etc/init.d/iptables restart 这样的命令是无效的,应该用systemctl命令。
先关闭firewall
[root@VM_45_237_centos ~]# systemctl stop firewalld.service
禁止firewall开机启动
[root@VM_45_237_centos ~]# systemctl disable firewalld.service
查看防火墙状态
[root@VM_45_237_centos ~]# firewall-cmd –state
结果显示:notrunning
安装iptables
[root@VM_45_237_centos ~]# yum install -y iptables1
安装iptables_services
[root@VM_45_237_centos ~]# yum install iptables-services
配置防火墙
[root@VM_45_237_centos ~]# vi /etc/sysconfig/iptables
允许80端口和3306通过防火墙
[root@VM_45_237_centos ~]# -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
[root@VM_45_237_centos ~]# -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
设置iptables开机启动
[root@VM_45_237_centos ~]# systemctl enable iptables.service
开启防火墙
[root@VM_45_237_centos ~]# systemctl start iptables.service
查看状态
[root@VM_45_237_centos ~]# systemctl status iptables.service
结果显示:Actice:active(exited)(高亮显示)
安装Apache
安装Apache
[root@VM_45_237_centos ~]# yum -y install httpd
用Web浏览器从客户端PC访问服务器,显示默认欢迎页面“Testing123..”
将Apache设置为开机启动
[root@VM_45_237_centos ~]# systemctl enable httpd.service
查看httpd的开机启动状态列表
[root@VM_45_237_centos ~]# systemctl list-unit-files
安装MySQL
Centos自带的repo不会自动更新每个软件的最新版本,所以无法用yum安装MySQL的高级版本(来源:>http://www.cnblogs.com/XBlack/p/5178758.html)
先安装带有可用的MySQL5系列社区版资源的rpm包
[root@VM_45_237_centos ~]# rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
查看当前可用的MySQL安装资源
[root@VM_45_237_centos ~]# yum repolist enabled|grep “mysql.*-community.*”
安装mysql
[root@VM_45_237_centos ~]# yum -y install mysql-community-server
MySQL的几个重要目录:
主配置文件:/etc/my.cnf
数据库文件:/var/lib/mysql
日志文件:/var/log
(my.cnf配置参考:>http://blog.csdn.net/l1028386804/article/details/50635169)
以下是我的my.cnf文件主要配置:
#[client]port = 3306socket = /usr/local/mysql/mysql.cock
character-set-server = utf8
[mysqld]port = 3306socket = /usr/local/mysql/mysql.sock
character-set-server=utf8basedir = /usr/local/mysqldataddir = /data/mysqldbpid_file = /data/mysql/mysql.pidserver_id = 1table_open_cache = 4096max_connection = 300max_connection_error = 100max_allowed_packet = 128Mlog_error = /data/mysql/mysql-error.loggeneral_log = ONgeneral_log_file = /usr/local/mysql/log/mysql.loginnodb_buffer_pool_size = 128Mexpire_logs_days = 30join_buffer_size = 128Msort_buffer_size = 2Mread_rnd_buffer_size = 2Msql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqldump]
quickmax_allowed_packet = 32M
[mysql]
no-auto-rehash
[myisamchk]key_buffer = 16Msort_buffer_size = 16Mread_buffer = 8Mwrite_buffer = 8M
[mysqld_safe]open_files_limit = 8192#
将MySQL加入开机启动
[root@VM_45_237_centos ~]# systemctl enable mysqld
启动MySQL
[root@VM_45_237_centos ~]# systemctl start mysqld
(重置密码,参考:>http://www.cnblogs.com/XBlack/p/5178758.html)
[root@VM_45_237_centos ~]# mysql_secure_installtion
安装PHP
安装PHP (参考:>http://www.jb51.net/article/97434.htm)
[root@VM_45_237_centos ~]# yum -y install php php-mbstring php-pear
打开PHP配置文件
[root@VM_45_237_centos ~]# vi /etc/php.ini
line 878 删除分号,设置时区
date.timezone = “Asia/Shanghai”
重启httpd
[root@VM_45_237_centos ~]# systemctl restart httpd
创建一个PHP测试页面
[root@VM_45_237_centos ~]# vi /var/www/html/index.php
显示当前日期:
安装JDK
安装JDK(参考:>http://www.linuxidc.com/Linux/2016-09/134941.htm)
查看yum库中的jdk版本
[root@VM_45_237_centos ~]# yum search java|grep jdk
电脑上装的是1.7.0版本,所以选择安装1.7.0版本
[root@VM_45_237_centos ~]# yum install java-1.7.0-openjdk
设置变量环境
[root@VM_45_237_centos java]# vi /etc/profile
在打开的profile文件中添加如下内容:
##set java environmentJAVA_HOME=/usr/java/jdk1.7.0_79
JRE_HOME=/usr/java/jdk1.7.0_79/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/binexport JAVA_HOME JRE_HOME CLASS_PATH PATH#
让修改立即生效
[root@VM_45_237_centos ~]# . /etc/profile
检查java当前版本
[root@VM_45_237_centos ~]# java -version javac
安装Tomcat
# [root@VM_45_237_centos ~]# wget http://apache.opencas.org/tomcat/tomcat-7/v7.0.73/bin/apache-tomcat-7.0.73.tar.gz
创建一个downloads目录,把压缩文件放里面
[root@VM_45_237_centos ~]# mkdir /usr/local/downloads
[root@VM_45_237_centos ~]# mv apache-tomcat-7.0.73.tar.gz /usr/local/downloads
解压缩到/usr/local下面
[root@VM_45_237_centos ~]# tar -C /usr/local/downloads -zxvf /usr/local/downloads/apache-tomcat-7.0.73.tar.gz
启动Tomcat
[root@VM_45_237_centos ~]# /usr/local/apache-tomcat-7.0.73/bin/startup.sh
结果显示:Tomcat started.