自己买了服务器,记录部署环境过程
安装jdk,mysql,Nginx ,Redis
在home下创建java文件夹上传jdk
解压
tar -zxvf jdk-11.0.1_linux-x64_bin.tar.gz
重命名文件夹
mv jdk-11.0.1 jdk
编辑配置文件,配置环境变量
vim /etc/profile
添加如下内容:JAVA_HOME根据实际目录来
JAVA_HOME=/home/java/jdk
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH
重启机器或执行命令
sudo shutdown -r now
查看安装情况
java -version
出现如下结果 表明成功
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
在根目录下创建文件夹software和数据库数据文件/data
下载安装包解压到/software/mysql 更改解压缩后的文件夹名称
mkdir /software/
mkdir /data
tar -zxvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
mv /software/mysql-5.7.21-linux-glibc2.12-x86_64/ /software/mysql
创建mysql用户组和mysql用户
groupadd mysql
useradd -r -g mysql mysql
关联myql用户到mysql用户组中
chown -R mysql:mysql /software/mysql/
chown -R mysql:mysql /data/mysql/
chown -R mysql /software/mysql/
chown -R mysql /data/mysql
更改mysql安装文件夹mysql/的权限
chmod -R 755 /software/mysql/
安装libaio依赖包
查询是否暗转libaio依赖包
yum search libaio
如果没安装,可以用下面命令安装
yum install libaio
初始化mysql命令
cd /software/mysql/bin
./mysqld --user=mysql --basedir=/software/mysql --datadir=/data/mysql --initialize
初始化后会生成临时密码 很重要
修改Mysql配置文件
修改前
if test -z "$basedir"
then
basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
if test -z "$datadir"
then
datadir=/usr/local/mysql/data
fi
sbindir=/usr/local/mysql/bin
libexecdir=/usr/local/mysql/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
修改后
if test -z "$basedir"
then
basedir=/software/mysql
bindir=/software/mysql/bin
if test -z "$datadir"
then
datadir=/data/mysql
fi
sbindir=/software/mysql/bin
libexecdir=/software/mysql/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
保存退出
#cp /software/mysql/support-files/mysql.server /etc/init.d/mysqld
#chmod 755 /etc/init.d/mysqld
修改my.cnf文件
vi /etc/my.cnf
将下面内容复制替换当前的my.cnf文件中的内容
[client]
no-beep
socket =/software/mysql/mysql.sock
# pipe
# socket=0.0
port=3306
[mysql]
default-character-set=utf8
[mysqld]
basedir=/software/mysql
datadir=/data/mysql
port=3306
pid-file=/software/mysql/mysqld.pid
#skip-grant-tables
skip-name-resolve
socket = /software/mysql/mysql.sock
character-set-server=utf8
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
# Server Id.
server-id=1
max_connections=2000
query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300
#限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
innodb_data_home_dir = /data/mysql
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=128M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=80
flush_time=0
join_buffer_size=128M
max_allowed_packet=1024M
max_connect_errors=2000
open_files_limit=4161
query_cache_type=0
sort_buffer_size=32M
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
#批量插入数据缓存大小,可以有效提高插入效率,默认为8M
bulk_insert_buffer_size = 64M
interactive_timeout = 120
wait_timeout = 120
log-bin-trust-function-creators=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
保存退出
启动mysql
/etc/init.d/mysqld start
新版本的安装包会报错,错误内容如下:
Starting MySQL.Logging to '/data/mysql/SZY.err'.
2018-07-02T10:09:03.779928Z mysqld_safe The file /usr/local/mysql/bin/mysqld
does not exist or is not executable. Please cd to the mysql installation
directory and restart this script from there as follows:
./bin/mysqld_safe&
See http://dev.mysql.com/doc/mysql/en/mysqld-safe.html for more information
ERROR! The server quit without updating PID file (/software/mysql/mysqld.pid).
因为新版本的mysql安全启动安装包只认/usr/local/mysql这个路径。
解决办法:
方法1、建立软连接
例 #cd /usr/local/mysql
#ln -s /sofware/mysql/bin/myslqd mysqld
方法2、修改mysqld_safe文件(有强迫症的同学建议这种,我用的这种)
# vim /software/mysql/bin/mysqld_safe
将所有的/usr/local/mysql改为/software/mysql
保存退出。(可以将这个文件拷出来再修改然后替换)
登录mysql
/software/mysql/bin/mysql -u root -p7kAkookkoS*r
修改mysql的登录密码
>mysql set password=password('root');
>mysql grant all privileges on *.* to root@'%' identified by 'root';
>mysql flush privileges;
最后登录
/software/mysql/bin/mysql -u root -proot
安装依赖
//一条命令安装四个依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
下载nginx的tar包
//创建一个文件夹
cd /usr/local
mkdir nginx
cd nginx
//下载tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -xvf nginx-1.13.7.tar.gz
安装nginx
//进入nginx目录
cd /usr/local/nginx
//执行命令
./configure
//执行make命令
make
//执行make install命令
make install
Nginx虚拟域名配置及测试验证
//编辑nginx.conf
sudo vim /usr/local/nginx/conf/nginx.conf
//增加行 注意分号
include vhost/*.conf;
//保存退出
//在/usr/local/nginx/conf目录新建vhost文件夹
mkdir vhost
//创建每个域名的配置
sudo vim jijl.conf
//节点中增加入响应的配置 端口转发 或者访问文件系统
我的配置 jijl.conf(供参考)
server {
listen 80;
server_name myweb.jijl.cn;
access_log logs/host.access.log;
location / {
proxy_pass http://localhost:9002;
proxy_cookie_path /home/mywebproject/project / ;
proxy_set_header Host $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
index index.html;
}
location /uploads {
alias /home/mywebproject/project/uploads/;
}
location ~* \.(jpg|jpeg|png|gif|ico|css|js|txt|html)$ {
root /home/mywebproject/project/back;
if (!-f $request_filename){
rewrite ^/(.*) /$1 break;
proxy_pass http://localhost:9002;
expires off;
}
expires 1M;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Nginx启动
//进入nginx安装目录
cd sbin
sudo ./nginx
访问
Nginx常用命令
//测试配置文件
安装路径下的/nginx/sbin/nginx -t
//启动命令
安装路径下的/nginx/sbin/nginx
//停止命令
安装路径下的/nginx/sbin/nginx -s stop
或者 : nginx -s quit
//重启命令
安装路径下的/nginx/sbin/nginx -s reload
//查看进程命令
ps -ef | grep nginx
//平滑重启
kill -HUP Nginx主进程号
下载redis
wget http://download.redis.io/releases/redis-4.0.8.tar.gz
tar xzvf redis-4.0.8.tar.gz
安装
cd redis-4.0.8
make
cd src
make install PREFIX=/usr/local/redis
移动配置文件到安装目录下
cd ../
mkdir /usr/local/redis/etc
mv redis.conf /usr/local/redis/etc
配置redis为后台启动
vim /usr/local/redis/etc/redis.conf //将daemonize no 改成daemonize yes
将redis加入到开机启动
vi /etc/rc.local //在里面添加内容:/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf (意思就开机调用这段开启redis的命令
开启redis
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
进入redis安装目录src 目录测试
./redis-cli