CentOS7 java服务器环境配置

/ java / 没有评论 / 416浏览

CENTOS7 服务器环境配置

JDK

jdk

rpm -qa | grep java
rpm -e --nodeps `rpm -qa | grep java`
mkdir app

upload

若后缀为.tar.gz,使用tar -xzvf filename   //安装到当前目录下
tar -zxvf filename -C /usr/local/java/   //安装到指定目录下
这里我输入:tar -xzvf jdk-8u171-linux-x64.tar.gz
mv jdk1.8.0_171/ jdk1.8/
vi /etc/profile
## JAVA
export JAVA_HOME=/root/app/jdk1.8
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
source /etc/profile
java -version

check

Mysql

下载并安装MySQL官方的 Yum Repository

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
yum -y localinstall mysql57-community-release-el7-11.noarch.rpm 
yum -y install mysql-community-server

mysql

MySQL数据库设置

systemctl start mysqld
systemctl enable mysqld
systemctl daemon-reload
systemctl status mysqld.service

running

grep "password" /var/log/mysqld.log

password

mysql -u root -p

输入临时密码 进入mysql命令行;

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Wingsky@0624';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Wingsky@0624' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> exit;
Bye
[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-ports

开放3306端口

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'

# vi /etc/my.cnf
systemctl restart mysqld

Tomcat设置

wget http://apache.fayea.com/tomcat/tomcat-8/v8.5.14/bin/apache-tomcat-8.5.14.tar.gz
tar -xzvf apache-tomcat-8.5.14.tar.gz
cd bin
./startup.sh
cd ../logs/
tail -f catalina.out
方式一:直接启动 ./startup.sh
方式二:作为服务启动 nohup ./startup.sh &
方式三:控制台动态输出方式启动 ./catalina.sh run 动态地显示tomcat后台的控制台输出信息,Ctrl+C后退出并关闭服务
解释:
通过方式一、方式三启动的tomcat有个弊端,当客户端连接断开的时候,tomcat服务也会立即停止,通过方式二可以作为linux服务一直运行
通过方式一、方式二方式启动的tomcat,其日志会写到相应的日志文件中,而不能动态地查看tomcat控制台的输出信息与错误情况,通过方式三可以以控制台模式启动tomcat服务,
直接看到程序运行时后台的控制台输出信息,不必每次都要很麻烦的打开catalina.out日志文件进行查看,这样便于跟踪查阅后台输出信息。tomcat控制台信息包括log4j和System.out.println()等输出的信息。
[root@VM_72_154_centos logs]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
success
[root@VM_72_154_centos logs]# firewall-cmd --reload
success

Redis设置

wget http://download.redis.io/releases/redis-4.0.10.tar.gz
tar -zxvf redis-4.0.10.tar.gz
yum install gcc
cd redis-4.0.6
make MALLOC=libc
cd src && make install

先切换到redis src目录下

cd src

直接启动redis

./redis-server
[root@iZwz991stxdwj560bfmadtZ src]# ./redis-server
18685:C 13 Dec 12:56:12.507 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
18685:C 13 Dec 12:56:12.507 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=18685, just started
18685:C 13 Dec 12:56:12.507 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
                _._                                                 
           _.-``__ ''-._                                            
      _.-``    `.  `_.  ''-._           Redis 4.0.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 18685
  `-._    `-._  `-./  _.-'    _.-'                                  
 |`-._`-._    `-.__.-'    _.-'_.-'|                                 
 |    `-._`-._        _.-'_.-'    |           http://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                  
 |`-._`-._    `-.__.-'    _.-'_.-'|                                 
 |    `-._`-._        _.-'_.-'    |                                 
  `-._    `-._`-.__.-'_.-'    _.-'                                  
      `-._    `-.__.-'    _.-'                                      
          `-._        _.-'                                          
              `-.__.-'                                              
 
18685:M 13 Dec 12:56:12.508 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
18685:M 13 Dec 12:56:12.508 # Server initialized
18685:M 13 Dec 12:56:12.508 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
18685:M 13 Dec 12:56:12.508 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
18685:M 13 Dec 12:56:12.508 * Ready to accept connections 

如上图:redis启动成功,但是这种启动方式需要一直打开窗口,不能进行其他操作,不太方便。

按 ctrl + c可以关闭窗口。

复制配置文件到/etc/目录:

cp redis.conf /etc/

修改redis.conf文件:

vi /etc/redis.conf

daemonize no 

修改为

daemonize yes
./redis-server /etc/redis.conf

首先使用ps -aux | grep redis查看redis进程

[root@iZwz991stxdwj560bfmadtZ src]# ps -aux | grep redis
root     18714  0.0  0.1 141752  2008 ?        Ssl  13:07   0:00 ./redis-server 127.0.0.1:6379
root     18719  0.0  0.0 112644   968 pts/0    R+   13:09   0:00 grep --color=auto redis

使用kill命令杀死进程

[root@iZwz991stxdwj560bfmadtZ src]# kill -9 18714

[root@VM_72_154_centos logs]# firewall-cmd --zone=public --add-port=6379/tcp --permanent
success
[root@VM_72_154_centos logs]# firewall-cmd --reload
success