Fork me on GitHub

服务器Centos7环境配置

配置MySQL5.7

安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// 添加 MySQL YUM 源
# wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm'

// 通过 rpm -Uvh 安装
# rpm -Uvh mysql57-community-release-el7-11.noarch.rpm

// 查看是否安装成功
# yum repolist all | grep mysql

// 我的显示结果
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 95
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 84
mysql-tools-community-source MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 327
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server disabled
mysql80-community-source MySQL 8.0 Community Server - disabled

// 安装最新版本MySQL
# yum install mysql-community-server

// 如果要自定义版本,修改该配置文件中enabled属性值,哪个版本值为1安装哪个版本,再使用上条命令安装
# vim /etc/yum.repos.d/mysql-community.repo

// 查看当前版本
# mysql -V
或者
mysql> select version();

// 查看已安装的MySQL软件包
# yum list installed | grep MySQL

// 删除软件包
# yum -y remove ...

参考链接:https://www.jianshu.com/p/7cccdaa2d177

密码设置

  • root密码为空,直接mysql -u root就可以登录
  • root密码是系统自动生成的,被记录在mysql日志中,可以通过cat /var/log/mysqld.log | grep “password”来获取,会看到日志中有一条temporary password,是一个随机串,然后使用mysql -u root -p,copy这个密码登录

修改密码(不修改不能使用,会报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.):

  • ALTER USER ‘root‘@’localhost’ IDENTIFIED BY ‘new_password’;

如果密码过于简单,会报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,可以修改MySQL中两个全局设置字段来更改:

  • set global validate_password_policy=0; 设置密码安全级别为LOW
  • set global validate_password_length=6; 设置密码最短长度为6

远程连接

  1. 开放防火墙3306端口
  2. GRANT ALL PRIVILEGES ON . TO ‘root‘@’%’ IDENTIFIED BY ‘password’ WITH GRANT OPTION;意思是任何IP地址可以通过root为用户名,password为密码连接上该服务器MySQL并拥有全部权限
  3. 本地用Navicat连接测试,成功

参考链接:http://xjin.wang/2017/09/26/CentOS-7%E9%83%A8%E7%BD%B2MySQL%E7%BA%BF%E4%B8%8A%E7%8E%AF%E5%A2%83%E7%9A%84%E5%AE%8C%E6%95%B4%E6%96%B9%E6%A1%88/

配置MySQL8.0

1
2
3
4
5
// 前三步安装同上
# vim /etc/yum.repos.d/mysql-community.repo
// 修改enabled属性值,将8.0版本的enabled设置为1,默认版本设置为0,保存并退出
# yum install mysql
//修改密码方式同上

执行命令时,如果报错ERROR 1449 (HY000): The user specified as a definer (‘mysql.infoschema‘@’localhost’) does not exist解决办法:

1
2
mysql> SET GLOBAL innodb_fast_shutdown = 1;
# mysql_upgrade -u root -p;

参考链接:https://www.shiqidu.com/d/358

https://stackoverflow.com/questions/49992868/mysql-errorthe-user-specified-as-a-definer-mysql-infoschemalocalhost-doe/50117262

配置Redis

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// 下载redis最新版
# wget http://download.redis.io/releases/redis-5.0.4.tar.gz

// 解压
# tar -zxvf redis-5.0.4.tar.gz

// 移动到合适的位置并重命名(似乎可以放一起???)
# mv redis-5.0.4 /usr/local/
# cd /usr/local
# mv redis-5.0.4 redis

//安装gcc依赖(不知道需要安装几个,排坑途中全安装了)
# yum install gcc
# yum install gcc-c++
// 可以用# yum upgrade 更新一下

// 进入文件夹并安装
# cd redis
# make

// 创建链接(使redis-server与redis-cli成为命令)
# ln -s /usr/local/redis/src/redis-cli /usr/bin/redis-cli
# ln -s /usr/local/redis/src/redis-server /usr/bin/redis-server

// 修改配置文件(可以将不同端口redis的配置文件用端口号命名)
# mkdir /etc/redis
# cp /usr/local/redis/redis.conf /etc/redis/6379.conf
# vim /etc/redis/6379.conf
// 将bind 127.0.0.1改为bind 0.0.0.0意为可以远程访问
// 将daemonize no改为yes意为守护进程方式运行
// vim在normal模式下按下 / 即进入查找模式,查找requirepass,按n查找下一个,按N查找上一个,修改requirepass后的字符串,即为密码

// 用配置文件方式启动redis-server
# redis-server /etc/redis/6379.conf

// 启动redis-cli
# redis-cli -a 000326

将redis-server设置为守护进程方式运行后,关闭ssh连接redis-server不会关闭,下次打开直接使用redis-cli即可

如果要远程连接一定要将服务器防火墙打开!!!

远程连接可能报错connection reset,第二天就好了,暂不知道原因

参考链接:https://blog.csdn.net/xiaojianhx/article/details/83352333

https://blog.csdn.net/m0_37202351/article/details/83825524

配置Oracle-JDK11

  • 官网下载安装包并上传(可以用wget直接下载),.rpm和.tar.gz都行

  • rpm -ivh jdk-11.0.3_linux-x64_bin.rpm解压(解压默认解压到/usr/java,可以自己移动,但要配置环境变量(不移动不配置环境变量似乎也可行?))

  • vim /etc/profile并在最后面添加下列两行(我移动位置并改文件夹名了)(jdk11配置环境变量更简单)

    1
    2
    - export JAVA_HOME=/usr/local/java
    - export PATH=PATH:JAVA_HOME/bin
  • source /etc/profile

  • java -version验证是否成功

参考链接:https://www.jianshu.com/p/b3c0c160c8bf

配置Nginx

三种方式:

1、直接sudo yum install nginx 下载的是老版本

2、手动安装,参考链接 https://my.oschina.net/u/2534824/blog/2986878
https://blog.csdn.net/qq_32828933/article/details/82715798

两者区别:https://blog.51cto.com/11728495/2094703

手动安装找不到conf.d目录,暂不知道咋解决

3、sudo vim /etc/yum.repos.d/nginx.repo

新增内容:

1
2
3
4
5
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1

再执行sudo yum install nginx,下载的是nginx最新版本,我的是1.15.12

-------------本文结束感谢您的阅读-------------
undefined