用阿里云或腾讯云搭建Web服务器
转载:大佬写的第一篇博客,要我给评论和点赞,哈哈哈(本来他写了三小时一保存草稿,截的图都不见了,哈哈哈,被csdn坑了)
https://blog.csdn.net/qq_37809499/article/details/80002236
一、什么是主机、服务器、云服务器
主机:电脑的主机
服务器:是一种高性能的计算机
云服务器:是一组集群服务器虚拟出类似独立服务器的部分,集群中每个服务器都有云服务器的一个镜像,从而大大提高了云服务器的稳定性。
以前都是传统服务器搭建Web运行环境形成Web服务器,现在大多数都用云服务器搭建Web运行环境形成Web服务器,因为云服务器具有高可靠性、高稳定性、高灵活性、高安全性 、高性能,使用了云计算技术。
二、步骤
1、在阿里云或腾讯云买一个Linux系统的云服务器
2、在Windows上安装Xshell软件进行远程控制
3、在Linux服务器中安装jdk1.8
4、在Linux服务器中安装tomcat7.0
5、在Linux服务器中安装mysql
6、在Linux服务器中安装redis
三、过程
1、在阿里云或腾讯云买一个Linux系统的云服务器
2、在Windows上安装Xshell软件进行远程控制
3、在Linux服务器中安装jdk1.8
(1)Xshell实现Windows上传文件到Linux服务器
[html] view plain copy
- [root@localhost ~]# yum install lrzsz
rz:上传文件
sz 文件名:下载文件
(2)在Windows下载Linux版本的jdk1.8上传到Linux服务器
[html] view plain copy
- [root@localhost ~]# rz
(3)在Linux服务器中安装jdk1.8,并配置环境变量
①解压安装包,到指定目录
[html] view plain copy
- [root@localhost ~]# ls
[html] view plain copy
- [root@localhost ~]# tar -zxvf jdk-8u171-linux-x64.tar.gz -C /usr/local/
②进入指定目录,更改文件名
[html] view plain copy
- [root@localhost ~]# cd /usr/local
[html] view plain copy
- [root@localhost local]# ls
[html] view plain copy
- [root@localhost local]# mv jdk1.8.0_171 jdk1.8
[html] view plain copy
- [root@localhost local]# ls
③配置环境变量
[html] view plain copy
- [root@localhost local]# vim /etc/profile
[html] view plain copy
- export JAVA_HOME=/usr/local/jdk1.8
- export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
- export PATH=$JAVA_HOME/bin:$PATH
[html] view plain copy
- [root@localhost local]# source /etc/profile
[html] view plain copy
- [root@localhost local]# java -version
4、在Linux服务器中安装tomcat7.0
(1)在Windows下载tomcat7.0上传到Linux服务器
[html] view plain copy
- [root@localhost local]# cd ~
[html] view plain copy
- [root@localhost ~]# rz
(2)在Linux服务器安装tomcat7.0
①解压安装包,到指定目录
[html] view plain copy
- [root@localhost ~]# ls
[html] view plain copy
- [root@localhost ~]# tar -zxvf apache-tomcat-7.0.86.tar.gz -C /usr/local/
②进入指定目录,更改文件名
[html] view plain copy
- [root@localhost ~]# cd /usr/local
[html] view plain copy
- [root@localhost local]# ls
[html] view plain copy
- [root@localhost local]# mv apache-tomcat-7.0.86 tomcat
[html] view plain copy
- [root@localhost local]# ls
③ 启动tomcat和检查是否启动
[html] view plain copy
- [root@localhost local]# cd tomcat/bin
[html] view plain copy
- [root@localhost bin]# ./startup.sh
[html] view plain copy
- [root@localhost bin]# ps -aux | grep tomcat
④关闭tomcat和检查是否关闭
[html] view plain copy
- [root@localhost bin]# ./shutdown.sh
关闭tomcat时,产生了上面图片异常,解决如下:
[html] view plain copy
- [root@localhost bin]# ps -aux | grep tomcat
[html] view plain copy
- [root@localhost bin]# kill 2243
[html] view plain copy
- [root@localhost bin]# ps -aux | grep tomcat
[html] view plain copy
- [root@localhost bin]# vim $JAVA_HOME/jre/lib/security/java.security
把securerandom.source=file:/dev/random改为securerandom.source=file:/dev/urandom
[html] view plain copy
- [root@localhost bin]# ./startup.sh
[html] view plain copy
- [root@localhost bin]# ./shutdown.sh
5、在Linux服务器中安装mysql
(1)在Linux服务器使用wget命令下载mysql
[html] view plain copy
- [root@localhost bin]# cd ~
[html] view plain copy
- [root@localhost ~]# wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
(2)在Linux服务器安装mysql
①解压安装包,到指定目录
[html] view plain copy
- [root@localhost ~]# ls
[html] view plain copy
- [root@localhost ~]# tar -zxvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
②进入指定目录,更改文件名
[html] view plain copy
- [root@localhost ~]# cd /usr/local
[html] view plain copy
- [root@localhost local]# ls
[html] view plain copy
- [root@localhost local]# mv mysql-5.7.17-linux-glibc2.5-x86_64 mysql
[html] view plain copy
- [root@localhost local]# ls
③创建一个用户组和用户,因为mysql必须运行在mysql用户组和mysql用户下,不能运行在root下。
[html] view plain copy
- [root@localhost local]# groupadd mysql
[html] view plain copy
- [root@localhost local]# useradd -r -g mysql mysql
查看用户组和用户
[html] view plain copy
- [root@localhost local]# cat /etc/group
[html] view plain copy
- [root@localhost local]# cat /etc/shadow
④修改mysql所属用户组和用户
[html] view plain copy
- [root@localhost local]# cd mysql
[html] view plain copy
- [root@localhost mysql]# chgrp -R mysql .
[html] view plain copy
- [root@localhost mysql]# chown -R mysql .
⑤使mysqld启动时自动读取my.cnf文件
[html] view plain copy
- [root@localhost mysql]# ls
[html] view plain copy
- [root@localhost mysql]# cd support-files
[html] view plain copy
- [root@localhost support-files]# ls
[html] view plain copy
- [root@localhost support-files]# cp my-default.cnf /etc/my.cnf
阿里云或腾讯云的Linux系统中可能有默认mysql,终端会提示你是否覆盖,输入y即可
⑥初始化mysql数据库
[html] view plain copy
- [root@localhost support-files]# cd ../
[html] view plain copy
- [root@localhost mysql]# cd bin
[html] view plain copy
- [root@localhost bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[html] view plain copy
- [root@localhost bin]# cd ../
[html] view plain copy
- [root@localhost mysql]# ls
若生成data目录表示mysql数据库初始化成功,并且mysql的root用户会产生一个随机密码:gjqR7Ptt1)dk
注意:运行该命令报错如:error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory 是因为无该链接库文件,使用命令,yum install libaio-devel.x86_64
⑦给数据加密
[html] view plain copy
- [root@localhost mysql]# cd bin
[html] view plain copy
- [root@localhost bin]# ./mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data
⑧启动mysql和检查是否启动mysql
[html] view plain copy
- [root@localhost bin]# ./mysqld_safe --user=mysql&
[html] view plain copy
- [root@localhost bin]# ps -ef | grep mysql
⑨修改data的所属用户
[html] view plain copy
- [root@localhost bin]# cd ../
[html] view plain copy
- [root@localhost mysql]# chown -R mysql data
⑩把mysql设置开机自动启动
[html] view plain copy
- [root@localhost mysql]# cd support-files
[html] view plain copy
- [root@localhost support-files]# cp mysql.server /etc/init.d/mysql.server
[html] view plain copy
- [root@localhost support-files]# vim /etc/init.d/mysql.server
找的basedir和datadir进行添加路径
[html] view plain copy
- basedir=/usr/local/mysql
- datadir=/usr/local/mysql/data
[html] view plain copy
- [root@localhost support-files]# /etc/init.d/mysql.server stop
[html] view plain copy
- [root@localhost support-files]# /etc/init.d/mysql.server start
[html] view plain copy
- [root@localhost support-files]# chkconfig --add mysql.server
[html] view plain copy
- [root@localhost support-files]# chkconfig --list | grep mysql
(3) 登录mysql(root和临时密码),并修改mysql的用户root的密码
[html] view plain copy
- [root@localhost support-files]# cd ../
[html] view plain copy
- [root@localhost mysql]# cd bin
[html] view plain copy
- [root@localhost bin]# ./mysql -uroot -p
[html] view plain copy
- mysql> set password=password('123456');
(4)利用Windows的Navicat for MySQL进行远程管理Linux服务器的mysql
①在Linux服务器关闭防火墙和授权
[html] view plain copy
- mysql> exit
[html] view plain copy
- [root@localhost bin]# systemctl stop firewalld.service
[html] view plain copy
- [root@localhost bin]# ./mysql -uroot -p
[html] view plain copy
- mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';
[html] view plain copy
- mysql> use mysql
[html] view plain copy
- mysql> select user,host from user;
[html] view plain copy
- mysql> flush privileges;
②在Windows利用Navicat for MySQL进行远程连接
利用Navicat for MySQL连接阿里云的Linux服务器的mysql时会产生如下异常:
解决方法:阿里云的控制台——云服务器ECS——网络和安全——安全组——配置规则
配置完成,就可以远程控制了
6. 安装redis
先 cd ~ 返回目录
cd ~回到用户家目录,这得看你是用什么用户登录了,如果是以root身份登录,执行此命令后,回到/root/目录下,如果是以其他用户等录得话,则是回到/home/目录下!!
再执行下面命令进行下载:
wget http://download.redis.io/releases/redis-2.8.17.tar.gz
://download.redis.io/releases/redis-2.8.17.tar.gz
解压并转移到/usr/local/ (看个人安排)
tar zxvf redis-2.8.17.tar.gz -C /usr/local/
cd /usr/local/
ls
mv redis-2.8.17 redis
开始进行安装
前提条件,如果没先安装gcc编译器,肯定无法安装成功
用gcc -v查看是否有该版本的信息,没请先安装
安装gcc
命令如下:yum install gcc
3、进入目录
cd redis
4、编译
make
5、安装
make install
6、设置配置文件路径
mkdir -p /etc/redis
cp redis.conf /etc/redis
7、修改配置文件
vi /etc/redis/redis.conf
仅修改: daemonize yes
8、启动(在bin目录下输入该命令)
/usr/local/bin/redis-server /etc/redis/redis.conf
9、查看启动
ps -ef | grep redis
10、使用客户端
redis-cli
>set name hello
OK
>get name
"hello"