centos7初始化

编程

服务器初始化

ssh 免密码

参考一

# 服务器生成 ssh

> ssh-keygen -t rsa

> cd ~/.ssh

# 复制本机 id_rsa.pub 到 服务器 ~/.ssh/authorized_keys 中

> service sshd restart

## 方法2,本机执行

## cat ~/.ssh/id_rsa.pub | ssh -p 22 user@host ‘cat >> ~/.ssh/authorized_keys’

jdk

jdk1.8 下载地址

# [卸载自带jdk](https://blog.csdn.net/hellocsz/article/details/82708733)

> scp ~/Download/jdk-8u201-linux-x64.tar.gz root@IP:/home/Download

> cd ~/Download

> gunzip jdk-8u201-linux-x64.tar.gz

> tar xvf jdk-8u201-linux-x64.tar

> mv jdk1.8.0_201/ /usr/local/

> cd /usr/local

> ln -s jdk1.8.0_201/ jdk

> vi /etc/profile

# export JAVA_HOME=/usr/local/jdk

# export JRE_HOME=$JAVA_HOME/jre

# export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib

# export PATH=$PATH:$JAVA_HOME/bin

> source /etc/profile

maven

下载地址

> cd /home/Download

> wget http://mirrors.hust.edu.cn/apache/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz

> gunzip apache-maven-3.5.4-bin.tar.gz

> tar xvf apache-maven-3.5.4-bin.tar

> mv apache-maven-3.5.4/ /usr/local

> cd /usr/local

> ln -s apache-maven-3.5.4 maven

> vi /etc/profile

# export MAVEN_HOME=/usr/local/maven

# PATH 加入 $MAVEN_HOME/bin

> source /etc/profile

redis

参考一

开启远程链接

密码登录

> cd /home/Download

> wget http://download.redis.io/releases/redis-4.0.2.tar.gz

> tar xvf redis-4.0.2.tar.gz

> cd redis-4.0.2

> make

> make install

# 配置初始化脚本

> cp /usr/local/redis/utils/redis_init_script /etc/init.d

> cd /etc/init.d

> mv redis_init_script redis_6379

# 创建文件夹

# 存放redis配置文件

> mkdir /etc/redis

# 存放redis持久化文件

> mkdir /var/redis/6379

# 修改配置文件

> cp /usr/local/redis/redis.conf /etc/redis

> cd /etc/redis

> mv redis.conf 6379.conf

> vi 6379.conf

# daemonize yes #使Redis以守护进程模式运行

# pidfile /var/run/redis_6379.pid #设置Redis的PID文件位置

# port 6379 #设置Redis监听的端口号

# dir /var/redis/6379 #设置持久化文件存放位置

# 设置开机启动

> vim /etc/init.d/redis_6379

# 第四行加入以下内容

# chkconfig: 2345 90 10

# description: Redis is a persistent key-value database

> cd /etc/init.d/

> chkconfig redis_6379 on

# 启动/停止

> service redis_6379 start

> redis-cli SHUTDOWN

mysql

参考一

参考二

# 查看系统是否安装了mysql软件

> rpm -qa | grep -i mysql

# 将已经安装过的软件卸载掉

> yum remove "软件名"

# 下载安装mysql的repo源

> wget http://repo.mysql.com//mysql57-community-release-el7-7.noarch.rpm

# 安装mysql的repo源,安装之后会获得/etc/yum.repos.d/mysql-community.repo和/etc/yum.repos.d/mysql-community-source.repo两个源

> rpm -ivh mysql57-community-release-el7-7.noarch.rpm

# 开始安装

> yum install mysql-server

> yum install mysql-devel

> yum install mysql

> rpm -qa | grep -i mysql

# 启动/停止

> service mysqld status

> service mysqld start

> service mysqld stop

> service mysqld restart

# 开机启动

> systemctl enable mysqld

# 查看初始密码

> sudo grep "temporary password" /var/log/mysqld.log

# 设置密码

> mysql -u root -p 原始密码

> set password for "root"@"localhost" = password("密码");

# 开启远程登录

> GRANT ALL PRIVILEGES ON *.* TO "root"@"%" IDENTIFIED BY "密码" WITH GRANT OPTION;

> flush privileges;

# 修改默认端口

> vi /etc/my.cnf

# 加入 port=3480

> service mysqld restart

端口处理

参考一

# 开启防火墙

> systemctl start firewalld

# 禁用防火墙

> systemctl stop firewalld

# 设置开机启动

> systemctl enable firewalld

# 停止并禁用开机启动

> systemctl disable firewalld

# 重启防火墙

> firewall-cmd --reload

# 查询端口

> firewall-cmd --query-port=3306/tcp

# 开启端口

> firewall-cmd --add-port=33.6/tcp (永久生效再加上 --permanent)

nginx

参考一

# 环境准备

> yum install -y pcre pcre-devel

> yum install -y zlib zlib-devel

> yum install gcc-c++

> yum install -y openssl openssl-devel

# 下载

> wget -c https://nginx.org/download/nginx-1.14.0.tar.gz

> tar -zxvf nginx-1.14.0.tar.gz

> cd nginx-1.14.0

# 使用默认配置

> ./configure

# 编译安装

> make

> make install

# 查找安装路径 /usr/local/nginx

> whereis nginx

# 配置环境变量

# 命令

> nginx -s stop

> nginx -s reload

# 日志

> nginx -V

# 开机启动

> vi /etc/rc.local

> chmod 755 /etc/rc.local

以上是 centos7初始化 的全部内容, 来源链接: utcz.com/z/511491.html

回到顶部