java 实现连接池(mysql中,linux里面修改)
2015-11-06 17:23
537 查看
在linux下修改mysql为连接池
1、找到tomcat中的context.xml文件
修改参数或者新增标签和参数<Resource />
<?xml version='1.0' encoding='utf-8'?>
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="项目名称" auth="Container"
type="javax.sql.DataSource" maxActive="300" maxIdle="10" maxWait="10000"
username="用户名(root)" password="密码(150021)" driverClassName="数据库驱动(com.mysql.jdbc.Driver)"
url="jdbc:mysql://localhost/数据库名(dg)?autoReconnect=true&user=用户名(root)&password=密码(150021)&useUnicode=true&characterEncoding=utf-8"
/>
</Context>
2、找到tomcat中的server.xml文件,进行修改记录日志的标签
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<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">
<!--必须设置编码格式,否则服务器与浏览器交互数据时将会出现中文乱码-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8"
/>
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!--注释这句话以后,tomcat将不会记录下每次访问的url地址-->
<!-- <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>
3、修改my.ini文件内容
windows系统:进入C:\Program Files (x86)\MySQL\MySQL Server 5.1目录,鼠标右键编辑my.ini,修改max_connections=300和
innodb_thread_concurrency=100,删除interactive_timeout=40和wait_timeout=40
linux系统:打开/etc/my.cnf 删除interactive_timeout=40和wait_timeout=40
操作步骤:在命令行窗口输入 vi /etc/my.cnf 进入文件浏览
找到指定行interactive_timeout=40和wait_timeout=40,按 i 进入编辑模式
删除指定行后,按 Esc 退出编辑模式
在按 :wq 保存退出
或者使用nano命令修改文件
4、修改完成后重启mysql服务和tomcat即可
1、找到tomcat中的context.xml文件
修改参数或者新增标签和参数<Resource />
<?xml version='1.0' encoding='utf-8'?>
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="项目名称" auth="Container"
type="javax.sql.DataSource" maxActive="300" maxIdle="10" maxWait="10000"
username="用户名(root)" password="密码(150021)" driverClassName="数据库驱动(com.mysql.jdbc.Driver)"
url="jdbc:mysql://localhost/数据库名(dg)?autoReconnect=true&user=用户名(root)&password=密码(150021)&useUnicode=true&characterEncoding=utf-8"
/>
</Context>
2、找到tomcat中的server.xml文件,进行修改记录日志的标签
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<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">
<!--必须设置编码格式,否则服务器与浏览器交互数据时将会出现中文乱码-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8"
/>
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!--注释这句话以后,tomcat将不会记录下每次访问的url地址-->
<!-- <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>
3、修改my.ini文件内容
windows系统:进入C:\Program Files (x86)\MySQL\MySQL Server 5.1目录,鼠标右键编辑my.ini,修改max_connections=300和
innodb_thread_concurrency=100,删除interactive_timeout=40和wait_timeout=40
linux系统:打开/etc/my.cnf 删除interactive_timeout=40和wait_timeout=40
操作步骤:在命令行窗口输入 vi /etc/my.cnf 进入文件浏览
找到指定行interactive_timeout=40和wait_timeout=40,按 i 进入编辑模式
删除指定行后,按 Esc 退出编辑模式
在按 :wq 保存退出
或者使用nano命令修改文件
4、修改完成后重启mysql服务和tomcat即可
相关文章推荐
- Linux下搭建iscsi
- Linux用户管理常用命令
- Linux下find的用法归纳
- Ubuntu下关于Linux学习环境的配置(一)
- Linux下用C开发PHP扩展
- Linux安装
- linux命令
- Linux必学的60个命令
- linux安装jdk
- 使用SecureCRT设置linux系统登录的ssh公钥认证
- 针对读写操作频繁的应用系统的LINUX调优设置
- Linux通过iptables实现转发
- Linux Shell 中的反引号,单引号,双引号
- linux 快捷键ctrl+r
- Linux 清除 root 账号的回收站
- linux服务器备份(python)
- linux读取hdd_temp硬盘温度
- linux-查看某文件夹大小:du -h --max-depth=1
- linux下更改ip地址方法
- Linux内核工程导论——用户空间进程使用内核资源