CentOS 7 下 JDK1.8+Maven+Nginx+MySql+Git+Redis环境安装

CentOS 7 下 JDK1.8 Maven Nginx MySql Git Redis环境安装

安装目录准备

  1. 新建data目录,用来放下载的软件
mkdir -p /data
  1. 切换到该data目录
cd /data

JDK1.8安装

  • JDK下载
  • 如果需要用户密码,注册一个即可
  • 用winSCP上传到服务器data目录下
  • 解压文件
tar -zxvf  jdk-8u211-linux-x64.tar.gz

Maven安装

  • maven下载
wget http://mirrors.gigenet.com/apache/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz
  • 解压maven
tar -zxvf apache-maven-3.6.1-bin.tar.gz

环境变量配置

vi /etc/profile
#找到最后一行,插入以下内容
JAVA_HOME=/data/jdk1.8.0_211
MAVEN_HOME=/data/apache-maven-3.6.1
PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
export PATH JAVA_HOME CLASSPATH
#wq!保存退出,并更新
source /etc/profile

Nginx下载安装

  1. 安装依赖
yum install -y gcc-c   pcre pcre-devel zlib zlib-devel openssl openssl-devel
  1. 下载nginx
wget http://nginx.org/download/nginx-1.12.2.tar.gz
  1. 解压
tar -zxvf  nginx-1.12.2.tar.gz
  1. 编译安装
cd nginx-1.12.2
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make && make install
  1. nginx启动
/usr/local/nginx/sbin/nginx
  1. 检查是否成功
打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功
  1. nginx常用命令
#校验Nginx配置文件是否正确
/usr/local/nginx/sbin/nginx -t
#开启Nginx
/usr/local/nginx/sbin/nginx
#重启Nginx
/usr/local/nginx/sbin/nginx -s reload
#停止Nginx
/usr/local/nginx/sbin/nginx -s stop
  1. nginx配置
cd /usr/local/nginx/conf
#新建自定义配置目录
mkdir conf.d
#备份nginx配置
cp  nginx.conf nginx.conf.bak
vi nginx.conf 
#在最后一行加入自定义配置目录
include /usr/local/nginx/conf/conf.d/*.conf;
#自定义配置
cd conf.d
vi sample.conf
内容示例如下:
server {
        # https 配置
        listen 443;
        server_name dev.xueshitang.cn;
        ssl on;
        #证书地址
        ssl_certificate  cert/2450982_dev.xueshitang.cn.pem;
        ssl_certificate_key cert/2450982_dev.xueshitang.cn.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        
        #小程序
        location /HtXLqKtu1d.txt {
                root   /usr/local/nginx/html;
         }

        error_page   500 502 503 504  /repaire.html;
        location = /repaire.html {
            root   /usr/local/nginx/html;
        }

        location / {
            proxy_set_header Host $host;
            proxy_set_header X-Real-Ip $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_pass http://127.0.0.1:8098/;
            root html;
            index index.html index.htm;
        }
}
  1. 证书放在cert目录下
  2. 重启nginx
/usr/local/nginx/sbin/nginx -s reload

mysql安装

  1. 查看有没有mysql
yum list installed | grep mysql
如果有,就先全部卸载,命令如下:
 yum -y remove mysql-community-client.x86_64
rpm -qa | grep -i mysql
find / -name mysql
rm -rf /var/lib/mysql /usr/share/mysql /usr/lib64/mysql /usr/bin/mysql /etc/logrotate.d/mysql /etc/selinux/targeted/active/modules/100/mysql /var/lib/mysql/mysql
  1. 下载mysql的repo源
wget http://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
  1. 安装mysql80-community-release-el7-3.noarch.rpm包
sudo rpm -ivh mysql80-community-release-el7-3.noarch.rpm
yum clean all
yum makecache
  1. 安装mysql
sudo yum install mysql-server
  1. 启动mysql
systemctl start mysqld.service
  1. 获取初始密码登录mysql
    mysql在安装后会创建一个root@locahost账户,并且把初始的密码放到了/var/log/mysqld.log文件中;
cat /var/log/mysqld.log | grep password
如果没有密码,则直接  mysql -u root 登录
  1. 修改root远程登录
use mysql;
update user set host = '%'  where user ='root';
FLUSH PRIVILEGES;
# navicat连接报错解决  Client does not support authentication protocol requested by server; consider upgrading MySQL client
alter user 'root'@'%' identified by 'password' password expire never;
alter user 'root'@'%' identified with mysql_native_password by 'passd';//passd是自己新修改的密码。
flush privileges;再次刷新一下权限配置。

阿里云swap分区,解决内存不足的问题

  1. 查看swap情况
cat /proc/swaps   
top
free -m
  1. 此文件的大小是count的大小乘以bs大小,下面命令的大小是8GB
dd if=/dev/zero of=/swap_file bs=1M count=8192
  1. 通过mkswap命令将上面新建出的文件做成swap分
mkswap /swap_file
  1. 启用交换分区,并使用命令查看内存占用情况
swapon /swap_file
free -m
  1. 设置开机自动挂载
 vi /etc/fstab
/swap_file swap swap defaults 0 0
  1. 查看内核参数vm.swappiness中的数值是否为0,如果为0则根据实际需要调整成30或者60
cat /proc/sys/vm/swappiness   
sysctl -a | grep swappiness    
sysctl -w vm.swappiness=50
  1. 关闭swap分区
swapoff /data/swap   
swapoff -a >/dev/null

git 安装

  1. 查询
rpm -qa|grep git
  1. 卸载之前的git
rpm -e --nodeps git
  1. 安装
yum install git

redis安装

  1. 下载
wget http://download.redis.io/releases/redis-4.0.6.tar.gz
  1. 解压
tar -zxvf redis-4.0.6.tar.gz
  1. 进入redis目录,编译安装
cd redis-4.0.6
make MALLOC=libc
cd src && make install
  1. 修改配置
mkdir -p /usr/local/redis/etc/
cd  redis-4.0.6
cp redis.conf /usr/local/redis/etc/
vi redis.conf
将 daemonize no 改成  daemonize yes
#设置密码授权
requirepass <设置密码>
  1. 启动
cd redis-4.0.6/src
./redis-server /usr/local/redis/etc/redis.conf

posted on 2019-09-04 09:01  架构设计之道  阅读(464)  评论(0编辑  收藏  举报

导航