CentOS 7安装mysql+JDK+Tomcat完成流程
一.安装mysql
即使是新的linux服务器,也要先验证是否有mysql已经安装,如果有进行卸载原版本,一定要确认是否mysql已不再使用
原安装情况(直接执行命令即可)
whereis mysql
rpm -qa | grep -i mysql
rpm -e perl-DBD-MySQL-4.013-3.el6.x86_64
service mysqld status
mysqld: unrecognized service
service mysql status
mysql: unrecognized service
生成文件目录
find / -name mysql
rm -rf
rm -rf /usr/share/mysql
rm -rf /usr/lib64/mysql
rm -rf /usr/lib64/perl5/DBD/mysql
rm -rf /usr/lib64/perl5/auto/DBD/mysql
rm -rf /usr/bin/mysql
创建目录 /usr/local/yx
cd /usr/local/yx
复制安装文件到此目录
linux系统是不是64位
getconf LONG_BIT
mysql 安装
解压安装包:
进入安装包所在目录,执行命令:
tar -zxvf mysql-5.5.50-linux2.6-x86_64.tar.gz
复制解压后的mysql目录到系统的本地软件目录:执行命令:
cp mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql -r
添加系统mysql组和mysql用户:执行命令:
groupadd mysql
useradd -r -g mysql mysql
安装数据库:
进入安装mysql软件目录:执行命令
cd /usr/local/mysql
修改当前目录拥有者为mysql用户:执行命令
chown -R mysql:mysql ./
安装数据库:执行命令
./scripts/mysql_install_db --user=mysql
修改当前目录拥有者为root用户:执行命令
chown -R root:root ./
修改当前data目录拥有者为mysql用户:执行命令
chown -R mysql:mysql data
到此数据库安装完毕
启动mysql服务和添加开机启动mysql服务:
添加开机启动:执行命令
cp support-files/mysql.server /etc/init.d/mysql
chkconfig --add mysql
chkconfig mysql on
把启动脚本放到开机初始化目录
启动mysql服务:执行命令
service mysql start
ps -ef|grep mysqld
把mysql客户端放到默认路径:
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
修改mysql的root用户密码,root初始密码为空的:
执行命令:./bin/mysqladmin -u root password 'root'
如果报错
问题提示:
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
####执行:#ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
编辑/etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
# socket=/var/lib/mysql/mysql.sock
socket=/tmp/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_allowed_packet=10G
character-set-server=utf8
lower_case_table_names=1
delayed_insert_limit=1000
delayed_insert_timeout=300
delayed_queue_size=5000
max_connections=400
thread_cache=8
innodb_buffer_pool_size=1073741824
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
或者
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_allowed_packet=10G
character-set-server=utf8
lower_case_table_names=1
delayed_insert_limit=1000
delayed_insert_timeout=300
delayed_queue_size=5000
max_connections=5000
thread_cache=8
innodb_buffer_pool_size=1073741824
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
###重新启动数据库
service mysql restart
mysql -uroot -proot
select * from mysql.user;
UPDATE mysql.user SET Password=PASSWORD('root') where USER='**';
##所有权限
GRANT ALL PRIVILEGES ON *.* TO '**'@'%' IDENTIFIED BY '**' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO '**'@'localhost' IDENTIFIED BY '**' WITH GRANT OPTION;
##查询权限
GRANT SELECT ON *.* TO '**'@'%' IDENTIFIED BY 'query' WITH GRANT OPTION;
set global interactive_timeout = 2880000
set global max_allowed_packet = 904857600
FLUSH PRIVILEGES;
quit
二、JDK安装
cd /usr/local/yx
tar -zxvf jdk-7u79-linux-x64.tar.gz
mv jdk1.7.0_79/ /usr/local/jdk7/
vi /etc/profile
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "${-#*i}" != "$-" ]; then
. "$i"
else
. "$i" >/dev/null 2>&1
fi
fi
done
JAVA_HOME=/usr/local/jdk7
JRE_HOME=/usr/local/jdk7/jre
PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export JAVA_HOME JRE_HOME PATH CLASSPATH
unset i
unset -f pathmunge
source /etc/profile
echo 1 > /proc/sys/vm/drop_caches
三、Tomcat安装
tar -zxvf apache-tomcat-7.0.65.tar.gz
启动命令
/usr/local/yx/apache-tomcat-7.0.65/bin/startup.sh
停止命令
/usr/local/yx/apache-tomcat-7.0.65/bin/shutdown.sh
编辑server.xml 设置tomcat编码
redirectPort="8443" URIEncoding="UTF-8" />
开机自启动Tomcat:
每次开机都要启动tomcat,网上看了好多都是用shell脚本来实现tomcat开机自启动,后来看到一种方法,直接修改系统文件来实现,已经实践过,方法有效。
1.修改脚本文件rc.local:vim /etc/rc.d/rc.local
这个脚本是使用者自定的开机启动程序,可以在里面添加想在系统启动之后执行的脚本或者脚本执行命令
2.添加如下内容:
export JAVA_HOME=/opt/jdk1.8.0_65
/opt/tomcat包名/bin/startup.sh start
3.esc 退出编辑,:wq 保存修改
4.将rc.local修改为可执行
chmod 777 /etc/rc.d/rc.local
//查看主机名称
hostname
/etc/sysconfig/network
//修改为
NETWORKING=yes
HOSTNAME=localhost.localdomain
//最后重启服务器生效
reboot