概述
为了减少开发者查询资料时间,特此记录基于cetos8的常用测试服务器环境的安装过程,内容包括JDK、Nginx、Mysql8、Redis、Mongodb等,希望对大家有用!
JDK
- 下载
镜像下载:https://repo.huaweicloud.com/java/jdk/
- 安装步骤
cp jdk-8u171-linux-x64.tar.gz /usr/java
tar -zxvf jdk-8u171-linux-x64.tar.gz
-
vim /etc/profile
JAVA_HOME=/usr/java/jdk1.8.0_171 JRE_HOME=$JAVA_HOME/jre PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib export JAVA_HOME JRE_HOME PATH CLASSPATH
source /etc/profile
java -version
Nginx
yum install –y gcc gcc-c++
yum -y install pcre pcre-devel
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel
./configure --prefix=/usr/local/nginx --with-pcre --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-stream
make & make install
cd /lib/systemd/system/
-
vim 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
systemctl enable nginx.service
Mysql
- 安装
- wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm
- rpm -ivh mysql80-community-release-el8-1.noarch.rpm
- yum install mysql-server
- systemctl enable mysqld.service
- systemctl start mysqld.service
-
修改root密码
mysql -u root
mysql> use mysql;
mysql> alter user 'root'@'localhost' identified by '123456';
mysql> flush privileges; -
授权外网访问
mysql -u root -p
mysql> update user set host='%' where user='root' and host='localhost';
mysql> exit;
service mysqld restart; -
修改参数
端口号:10001
Redis
- 下载
- wget http://download.redis.io/releases/redis-5.0.5.tar.gz
- tar -xzvf redis-5.0.5.tar.gz
- 编译
- cd redis-5.0.5
- make
- cd src
- make install PREFIX=/usr/local/redis
- 配置
mkdir /usr/local/redis/etc
cp redis.conf /usr/local/redis/etc
-
vim /usr/local/redis/etc/redis.conf
# 非本机可访问 # bind 127.0.0.1 # 设置密码 requirepass 123456
- 开机自启动
cd /lib/systemd/system/
-
vim redis.service
[Unit] Description=redis After=network.target [Service] type=forking PIDFile=/var/run/redis_6379.pid ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable redis
systemctl start redis
Mongodb
- 下载及安装
- https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.0.tgz
- tar -zxvf mongodb-linux-x86_64-4.0.0.tgz
- mv mongodb-linux-x86_64-4.0.0 /usr/local/mongodb
- 配置
-
vim /etc/profile
export PATH=/usr/local/mongodb/bin:$PATH
source /etc/profile
cd /usr/local/mongodb
mkdir data logs
-
touch mongodb.conf
port=27017 #端口 dbpath= /usr/local/mongodb/data #数据库存文件存放目录 logpath= /usr/local/mongodb/logs/mongodb.log #日志文件存放路径 logappend=true #使用追加的方式写日志 fork=true #以守护进程的方式运行,创建服务器进程 journal=true #每次写入会记录一条操作日志(通过journal可以重新构造出写入的数据)。#即使宕机,启动时wiredtiger会先将数据恢复到最近一次的checkpoint点,然后重放后续的journal日志来恢复。 quiet=false #这个选项可以过滤掉一些无用的日志信息,若需要调试使用请设置为false bind_ip = 0.0.0.0 #外部访问 auth=false #admin账户创建完成后再开启认证
-
启动服务
mongod -config /usr/local/mongodb/mongodb.conf
创建admin
- mongo
- > use admin
- > db.createUser({user:'admin',pwd:'admin',roles:[{role:'dbAdminAnyDatabase',db:'admin'}]})
备注:添加第一个管理用户前先不要启用auth配置
- 创建普通用户:
- > use message
- > db.createUser({user: 'message',pwd: '123456', roles:[{role:'dbOwner',db:'message'}]})