CentOS7搭建Java环境(JDK、MySQL和Tomcat)
安装jdk
准备
- jdk的tar.gz包(本文准备的版本是jdk-8u212-linux-x64.tar.gz)
- 通过xftp上传到/opt/software下
jdk环境配置流程
- 解压到/opt/modules目录下
tar -zxvf jdk-8u212-linux-x64.tar.gz -C /opt/modules
- 进入解压目录下并打印路径
cd /opt/modules/jdk1.8.0_212
pwd
- 修改环境变量
sudo vim /etc/profile
或使用root账户
在文件末尾添加环境变量JAVA_HOME=/opt/modules/jdk1.8.0_212 PATH=$JAVA_HOME/bin:$PATH export JAVA_HOME PATH
- 配置文件立即生效
安装MySQL 5.6
准备
- mysql的源码tar.gz包(本文准备的版本是mysql-5.6.44.tar.gz)
- 通过xftp上传到/opt/software下
MySQL安装流程
- 解压到modules目录下
tar -zxvf mysql-5.6.44.tar.gz -C /opt/modules/
- 卸载旧版本
rpm -qa | grep mysql
rpm -e mysql_libs
(普通删除)或rpm -e --nodeps mysql_libs
(强力删除) - 安装编译代码需要的包
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
- 编译源码包(这是一条命令)
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -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
- 编译并安装
make && make install
- 新建mysql用户组和用户
groupadd mysql
useradd -g mysql mysql
- 修改/usr/local/mysql权限
chown -R mysql:mysql /usr/local/mysql
- 初始化配置
进入安装路径,执行初始化配置脚本,创建系统自带的数据库和表cd /usr/local/mysql
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
- 添加服务,拷贝服务脚本到init.d目录,并设置开机启动
在/usr/local/mysql下执行cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
service mysql start
- 修改root密码
cd /usr/local/mysql/bin
./mysql -uroot
SET PASSWORD = PASSWORD(\'密码\');
- 允许远程连接
update user set host = \'%\' where user = \'root\';
- 开发端口
- 查看已开放端口
firewall-cmd --zone=public --list-ports
- 开放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
- 关闭端口
firewall-cmd --zone=public --remove-port=3306/tcp --permanent
- 重启防火墙
firewall-cmd --reload
- 查看已开放端口
安装Tomcat 7
准备
- tomcat的tar.gz包(本文准备的版本是apache-tomcat-7.0.93.tar.gz)
- 通过xftp上传到/opt/software下
Tomcat安装流程
- 解压到modules目录下
tar -zxvf apache-tomcat-7.0.93.tar.gz -C /opt/modules/
- 进入conf目录修改配置
cd /opt/modules/apache-tomcat-7.0.93/conf
- 初始化管理员账号
<?xml version=\'1.0\' encoding=\'utf-8\'?> <tomcat-users> <role rolename="manager-gui"/> <role rolename="manager-script" /> <user username="daye" password="luyuhao2010" roles="manager-gui, manager-script"/> </tomcat-users>
- 优化tomcat配置
具体配置参数链接1<?xml version=\'1.0\' encoding=\'utf-8\'?> <Server port="8006" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <Listener className="org.apache.catalina.core.JasperListener" /> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <GlobalNamingResources> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> </GlobalNamingResources> <Service name="Catalina"> <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="500" minSpareThreads="30" maxQueueSize="100" maxIdleTime="60000" prestartminSpareThreads = "true"/> <Connector port="8081" protocol="org.apache.coyote.http11.Http11NioProtocol" executor="tomcatThreadPool" connectionTimeout="60000" maxConnections="10000" enableLookups="false" acceptCount="100" maxPostSize="10485760" redirectPort="8443" maxHttpHeaderSize="8192" compression="on" disableUploadTimeout="true" compressionMinSize="2048" acceptorThreadCount="2" compressableMimeType="text/html,text/plain,text/css,application/javascript,application/json,application/x-font-ttf,application/x-font-otf,image/svg+xml,image/jpeg,image/png,image/gif,audio/mpeg,video/mp4" URIEncoding="utf-8" processorCache="20000" tcpNoDelay="true" connectionLinger="5" server="Server Version 11.0" /> <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> </Engine> </Service> </Server>
- 初始化管理员账号
- tomcat启动/关闭
cd /opt/modules/apache-tomcat-7.0.93/bin
- 启动:
./startup.sh
- 关闭:
./shutdown.sh
参考链接
版权声明:本文为darren1112原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。