1、先下载tomcat(apache-tomcat-8.5.31.tar.gz)和jdk(jdk-8u161-linux-x64.tar.gz)。
2、xshell连上服务器,输入
cd /usr
mkdir java
使用xftp分别将下载好的jdk和Tomcat包上传到服务器中的/usr/java目录下和/usr目录下。
3、先安装java
cd java
tar -xvzf jdk-8u161-linux-x64.tar.gz
ls
vim /etc/profile
在文末插入如下三行语句(注意jdk的版本是不是这个,不是的话要改版本号):
export JAVA_HOME=/usr/java/jdk1.8.0_161
export JRE_HOME=/$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
保存后,输入
source /etc/profile
java -version
4、下面开始Tomcat安装
回到usr目录(注意,之前已经将tomcat包上传到/usr目录下):
cd ..
tar -xvzf apache-tomcat-8.5.31.tar.gz
rm -r apache-tomcat-8.5.31.tar.gz
mv apache-tomcat-8.5.31 tomcat
/usr/tomcat/bin/startup.sh
此时,tomcat安装完毕,接下来打开端口:
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=22/tcp --permanent
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
至此,不出意外的话,就可以外网访问服务器ip:8080看到Tomcat初始界面了。
5、接下来,安装mysql:
cd ~
wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm
rpm -ivh mysql57-community-release-el7-7.noarch.rpm
yum install mysql-server
中间输入若干次y
yum install mysql-devel
中间输入若干次y
yum install mysql
检查一下MySQL:
rpm -qa|grep -i mysql
大概的显示如下:
mysql-community-libs-5.7.18-1.el7.x86_64
mysql-community-libs-compat-5.7.18-1.el7.x86_64
mysql57-community-release-el7-7.noarch
mysql-community-common-5.7.18-1.el7.x86_64
mysql-community-client-5.7.18-1.el7.x86_64
mysql-community-server-5.7.18-1.el7.x86_64
mysql-community-devel-5.7.18-1.el7.x86_64
service mysqld start
vim /etc/my.cnf
添加一条语句:
skip-grant-tables
保存退出。
service mysqld restart
mysql -u root
即可进入mysql
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update mysql.user set authentication_string=password(‘密码’) where user=’root’;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
Bye
vim /etc/my.cnf
删除掉刚才添加的那条语句,保存退出。
service mysqld restart
mysql -uroot -p
输入密码登录MySQL
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=10; (这里填你的密码长度)
Query OK, 0 rows affected (0.00 sec)
mysql> set PASSWORD = PASSWORD(‘密码’);
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> ALTER USER ‘root’@’localhost’ PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host=’%’ where user=’root’ and host=’localhost’;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
至此,MySQL也安装完毕!
注意:
(1)
mysql> use mysql;
mysql> GRANT ALL ON . TO admin@’%’ IDENTIFIED BY ‘密码’ WITH GRANT OPTION;
这句话的意思 ,允许任何IP地址(上面的 % 就是这个意思)的电脑 用admin帐户 和密码来访问这个MySQL Server
必须加类似这样的帐户,才可以远程登陆。 root帐户是无法远程登陆的,只可以本地登陆
这里根据自己的需要设置用户名和密码(我设成remoteu,密码自己记住)
(2)用navicat远程连接mysql报错:ERROR 2005 : Unknown MySQL server host ‘服务器ip’ (11001),但是命令行可以连接:可以在navicat改用ssh方法连接(需要服务器开启22号端口)
参考:
[1] 更详细的说明:https://blog.csdn.net/wxz_1997/article/details/76578449