CentOS开发环境配置

CentOS + JDK、Nexus、Redis、Nginx、MySql

JDK

1. 官网下载 [JDK](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)
2. 解压到 /usr/local
tar -zxvf jdk-8u181-linux-x64.tar.gz
3. 设置别名:
ln -s jdk1.8.0_181/ jdk
4. 设置环境变量
vi /etc/profile

JAVA_HOME=/usr/local/jdk
JRE_HOME=/usr/local/jdk/jre
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin:$ANT_HOME/bin:$NEXUS_HOME/bin
export PATH JAVA_HOME CLASSPATH M2_HOME ANT_HOME NEXUS_HOME

5. source /etc/profile
6. java -version

Nexus

# 官网下载:https://help.sonatype.com/repomanager3/download
tar -zxvf nexus-3.13.0-01-unix.tar.gz
ln -s nexus-3.13.0-01 nexus

# nexus 官网建议不要使用 root 帐户启动应用,所以创建一个 nexus 用户
useradd nexus

# 修改 nexus 配置,使用 nexus 作为应用启动的帐户
vi nexus/bin/nexus.rc
将内容修改为
run_as_user="nexus"

# 修改 nexus 的目录权限
chown nexus nexus

# 使用
Usage: /usr/local/nexus/bin/nexus {start|stop|run|run-redirect|status|restart|force-reload}

# 访问
http://ip:8081/nexus/

Redis

# 下载最新稳定版:http://download.redis.io/releases/
wget [http://download.redis.io/releases/redis-4.0.11.tar.gz](http://download.redis.io/releases/redis-4.0.11.tar.gz)
cd /usr/local/
tar zxvf redis-4.0.11.tar.gz
cd redis-4.0.11
ln -s redis-4.0.11 redis
make
make install
cd src/
make install
make test
yum install tcl
make test

# 常用命令
/usr/local/redis/src/redis-server &
/usr/local/redis/src/redis-cli

# 设置登录密码
vi /usr/local/redis/redis.conf
去掉行前的注释,并修改密码,保存文件
requirepass xxx

# 使用密码登录
/usr/local/redis/src/redis-cli -h 127.0.0.1 -p 6379 -a xxx

# 多端口多实例配置
cd /usr/local/redis
cp redis.conf redis6380.conf
vi redis6380.conf
// 主要修改下面几个配置项就可以了
pidfile /var/run/redis_6380.pid
port 6380
dbfilename dump6380.rdb
appendfilename "appendonly6380.aof"
// 启动
/usr/local/redis/src/redis-server redis6380.conf &
// 查看
ps -ef | grep redis

# 数据备份、恢复与持久化
[初识Redis(三):Redis数据备份、恢复与持久化 - 简书](https://www.jianshu.com/p/e04a9e80a998)
[redis备份和恢复的方式 - 简书](https://www.jianshu.com/p/09710f6ad75a)

# 开放外部访问
vi /usr/local/redis/redis.conf
找到bind 127.0.0.1将其编辑为bind 0.0.0.0
然后以redis.conf运行
redis-server redis.conf

CentOS 7 手动安装 Nginx-1.9.9

  • 当时最新的版本
nginx-1.9.9.tar.gz
openssl-1.0.2o.tar.gz // nginx-1.9.9需使用openssl-1.0.2,最新版本1.1.0会报错
pcre-8.42.tar.gz
zlib-1.2.11.tar.gz
  1. 安装gcc gcc-c++
yum install -y gcc gcc-c++
  1. 安装PCRE库
$ cd /usr/local/
$ wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz
$ tar -zxvf pcre-8.42.tar.gz
$ cd pcre-8.42
$ ./configure
$ make && make install
  1. 安装SSL库
$ cd /usr/local/
$ wget http://www.openssl.org/source/openssl-1.0.2o.tar.gz
$ tar -zxvf openssl-1.0.1j.tar.gz
$ cd openssl-1.0.2o
$ ./config
$ make && make install
  1. 安装zlib库存
$ cd /usr/local/
$ wget http://zlib.net/zlib-1.2.11.tar.gz
$ tar -zxvf zlib-1.2.11.tar.gz
$ cd zlib-1.2.11
$ ./configure
$ make && make install
  1. 安装Nginx
# 解压
$ cd /usr/local/
$ wget http://nginx.org/download/nginx-1.9.9.tar.gz
$ tar -zxvf nginx-1.9.9.tar.gz
$ cd nginx-1.9.9

# 配置,注意下面的zlib,pcre,openssl 和你下载的版本号要对应上
./configure —prefix=/usr/local/nginx \
—user=www \
—group=www \
—sbin-path=/usr/local/nginx/sbin/nginx \
—conf-path=/usr/local/nginx/conf/nginx.conf \
—error-log-path=/home/www/log/error.log \
—http-log-path=/home/www/log/access.log \
—pid-path=/home/www/pid/nginx.pid \
—lock-path=/home/www/pid/nginx.lock \
—with-mail \
—with-file-aio \
—with-http_ssl_module \
—with-http_flv_module \
—with-http_dav_module \
—with-http_sub_module \
—with-http_v2_module \
—with-http_realip_module \
—with-http_addition_module \
—with-http_gunzip_module \
—with-http_gzip_static_module \
—with-http_stub_status_module \
—with-zlib=/usr/local/zlib-1.2.11 \
—with-pcre=/usr/local/pcre-8.42 \
—with-openssl=/usr/local/openssl-1.0.2o \
—without-select_module \
—without-poll_module \
—http-client-body-temp-path=/tmp/clientbody \
—http-proxy-temp-path=/tmp/proxy \
—http-fastcgi-temp-path=/tmp/fastcgi \
—http-uwsgi-temp-path=/tmp/uwsgi \
—http-scgi-temp-path=/tmp/scgi


# make
make && make install

# 启动

/usr/local/nginx/sbin/nginx # 启动Nginx
/usr/local/nginx/sbin/nginx -t # 测试配置文件是否有错误
/usr/local/nginx/sbin/nginx -v # 查看Nginx版本
/usr/local/nginx/sbin/nginx -V # 查看Nginx版本和编译安装时的编译参数
/usr/local/nginx/sbin/nginx -s stop # 强制停止Nginx服务
/usr/local/nginx/sbin/nginx -s quit # 优雅地停止Nginx服务(即处理完所有请求后再停止服务)
/usr/local/nginx/sbin/nginx -s reload # 重新加载Nginx配置文件,然后以优雅的方式重启Nginx


# 可能遇到的报错解决:nginx: [emerg] getpwnam(“www”) failed,错误的原因是没有创建www这个用户,应该在服务器系统中添加www用户组和用户www,如下命令:

/usr/sbin/groupadd -f www
/usr/sbin/useradd -g www www

MySql

安装说明

官文足矣,MySQL :: A Quick Guide to Using the MySQL Yum Repository

1. Go to the download page for MySQL Yum repository at http://dev.mysql.com/downloads/repo/yum/.  下载rpm文件
2. sudo rpm -Uvh mysql80-community-release-el7-1.noarch.rpm 下载的rpm包
3. yum repolist all | grep mysql 检查安装版本,看看enabled的是不是你想要安装的版本
4. sudo yum install mysql-community-server 安装完成了!
5. sudo service mysqld start 启动
6. sudo grep 'temporary password' /var/log/mysqld.log 查看root原始密码
7. mysql -uroot -p 输入上面的密码
8. ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!’ 最后修改密码

运行

sudo service mysqld start
sudo service mysqld stop
sudo service mysqld status

目录

config=/etc/my.cnf
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

MySql 8 远程连接

  1. 使用工具连接时,多半会遇到如下错误:MySQL said: Authentication plugin 'caching_sha2_password' cannot be loaded
    参考:MySQL 8.0报错:error 2059: Authentication plugin ‘caching_sha2_password’ cannot be loaded
    # 只需运行此句,注意user要对上,默认是‘root’@‘localhost’
    ALTER USER ‘root’@‘%’ IDENTIFIED WITH mysql_native_password BY ‘yourpassword’;
  2. Sequel Pro Test Builds,目前只有build版本才能连接MySql 8