每次换服务器都要重新翻各种教程安装基本环境, 这次把自己的安装过程全部记录下来, 一篇文章搞定.我用的是华为云服务器, 发现很多工具都已经安装好了, 有些云服务器wget都要自己装.这次安装很顺利, 没有遇到报错, 如果有什么问题还是要自行百度解决.
JDK
通过yum安装
# 查看是否已安装
rpm -qa |grep java
rpm -qa |grep jdk
rpm -qa |grep gcj
# 查看可用的内容
yum list java-1.8*
# 安装
yum install -y java-1.8.0-openjdk-devel.x86_64
# 查看是否安装成功
java -version
openjdk version "1.8.0_392"
OpenJDK Runtime Environment (build 1.8.0_392-b08)
OpenJDK 64-Bit Server VM (build 25.392-b08, mixed mode)
docker
跟着官网一步步来就行:Install Docker Engine on CentOS | Docker Docs
yum install -y yum-utils
yum-config-manager --add-repo <https://download.docker.com/linux/centos/docker-ce.repo>
yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl start docker
docker run hello-world
mysql
# 检查是否已存在相关环境
# 好像centos比较低的版本里有mariadb这个东西
ps axj | grep mariadb
ps axj | grep mysql
在官网上有教程, 跟着做就好了:MySQL :: MySQL 8.2 Reference Manual :: 2.5.1 Installing MySQL on Linux Using the MySQL Yum Repository
1.首先下载好rpm包.
2.安装
[root@hecs-83810 datacenter]# yum localinstall mysql80-community-release-el7-11.noarch.rpm
[root@hecs-83810 datacenter]# yum repolist enabled | grep mysql.*-community
mysql-connectors-community/x86_64 MySQL Connectors Community 234
mysql-tools-community/x86_64 MySQL Tools Community 102
mysql80-community/x86_64 MySQL 8.0 Community Server 446
[root@hecs-83810 datacenter]# yum-config-manager --disable mysql80-community
[root@hecs-83810 datacenter]# yum-config-manager --enable mysql-innovation-community
[root@hecs-83810 datacenter]# systemctl start mysqld
[root@hecs-83810 datacenter]# systemctl status mysqld
# 查看临时密码 冒号后面的全是密码!
[root@hecs-83810 datacenter]# grep 'temporary password' /var/log/mysqld.log
2023-12-01T09:43:06.192455Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: +0Us5R?W-4x;
[root@hecs-83810 datacenter]# mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
更改权限 方便远程链接
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> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
4 rows in set (0.00 sec)
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
redis
这个官网真是垃圾 居然没有centos的安装教程 其他系统也就是一两句话
# 下载redis
wget <http://download.redis.io/releases/redis-7.0.14.tar.gz>
#解压
tar -zxvf redis-7.0.14.tar.gz -C /home/local/redis
#编译
make
# 附赠几个文件夹操作命令
# 移动文件夹
mv /home/local/redis/redis-7.0.14/ /home/local/redis-7.0.14
# 删除文件夹
rm -rf redis
修改配置文件
vim redis.conf
#后台启动
daemonize yes
# 开放所有ip
bind * -::*
# 设置密码
requirepass yourpassword
完成.要么只开放各别端口, 要么设置密码.否则会有服务器被黑的风险(亲身经历).
启动redis
# 这种方式ctrl c 就退出了
cd src
./redis-server
# 进入客户端
./redis-cli
# 退出客户端
exit
#关闭redis
shutdown
nginx
wget <https://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm>
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx
#安装完不知道去哪了...把找的命令也贴上来吧
[root@hecs-83810 /]# rpm -qa|grep nginx
nginx-release-centos-7-0.el7.ngx.noarch
nginx-1.24.0-1.el7.ngx.x86_64
[root@hecs-83810 /]# rpm -ql nginx-1.24.0-1.el7.ngx.x86_64
搞完这一通发现已经启动了, 不需要我手动启动服务.还是记下几个命令吧.
# 启动
./nginx
# 关闭
./nginx -s stop
# 重启
./nginx -s reload
# 查看进程
ps -ef | grep nginx
# 查看端口占用
netstat -ntlp|grep 80
# 版本查看
./nginx -V
配置成系统服务, 每次开机自启动(似乎不用额外配置什么东西)
[root@hecs-83810 sbin]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@hecs-83810 sbin]# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Docs: <http://nginx.org/en/docs/>
如果不行的话可能要自己新增配置文件.
vi /lib/systemd/system/nginx.service
#内容
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
在地址栏输入服务器ip, 看到以下页面说明安装成功