1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Linux安装JDK MySQL Tomcat Redis等软件

Linux安装JDK MySQL Tomcat Redis等软件

时间:2023-11-12 13:03:16

相关推荐

Linux安装JDK MySQL Tomcat Redis等软件

添加微信号GO_HOME_一起探讨Java

Linux安装软件安装JDK第一步 查看系统中是否存在JDk第二步 安装JDK第三步 配置环境变量第四步 使配置的环境变量生效第五步 查看环境变量第六步 和JDK版本 安装MySQL第一步 解压MySQL压缩包并更名第二步 添加系统mysql组和mysql用户第三步 安装数据库第四步 复制启动程序第五步 启动MySQL服务第六步 建立软链接启动mysql第七步 重新启动 成功修改密码第八步 修改数据库的字符集第九步 设置MySQL自动启动第十步 MySQL授权允许远程连接 安装Tomcat第一步 解压tomcat第二步 启动tomcat 安装Redis第一步 将redis-409targz安装包复制到usrlocal目录第二步 解压压缩包第三步yum安装gcc依赖第四步跳转到redis解压目录下第五步编译安装第六步测试是否安装成功第七步 设置redis开机自启动第八步 修改Redis密码

Linux安装软件

Linux版本: CentOS 7.4 64位

- *.rpm形式的二进制软件包: RPM(RedHat Packge Manager)是RedHat公司出的软件包管理器,使用它可以很容易地对rpm形式的软件包进行安装、升级、卸载、验证、查询等操作,安装简单,而卸载时也可以将软件安装在多处目录中的文件删除干净,因此推荐初学者尽可能使用rpm形式的软件包。

-.tar.gz/.tgz、.bz2形式的 二进制软件包:.tar.gz/*.bz2形式的二进制软件包是用tar工具来打包、用gzip/bzip2压缩的,安装时直接解包即可。对于解压后只有单一目录的软件,

卸载时用命令“rm -rf 软件目录名”;如果解压后文件分散在多处目录中,则必须一一手动删除(稍麻烦),想知道解压时向系统中安装了哪些

文件,可以用命令“tar ztvf.tar.gz”/“tar ytvf.bz2”获取清单。

1. 安装JDK

JDK版本: jdk-8u161-linux-x64.rpmJDK下载地址: /technetwork/java/javase/downloads/jdk8-downloads-2133151.html

第一步: 查看系统中是否存在JDk

rpm -aq|grep -i jdk

[root@VM_46_94_centos local]# rpm -aq|grep -i jdk[root@VM_46_94_centos local]#

如果存在JDk则卸载JDK: rpm -ev jdk1.8-1.8.0_161-fcs.x86_64

如果有软件依赖jdk关系, 则需要卸载命令中添加–nodeps:

rpm -ev –nodeps jdk1.8-1.8.0_161-fcs.x86_64

第二步: 安装JDK

rpm -ivh jdk-8u161-linux-x64.rpm

默认安装在/usr/java目录下

[root@VM_46_94_centos local]# rpm -ivh jdk-8u161-linux-x64.rpmPreparing...################################# [100%]Updating / installing...1:jdk1.8-2000:1.8.0_161-fcs ################################# [100%]Unpacking JAR files...tools.jar...plugin.jar...javaws.jar...deploy.jar...rt.jar...jsse.jar...charsets.jar...localedata.jar...

查看JDk安装目录: updatedb locate jdk

[root@VM_46_94_centos ~]# updatedb[root@VM_46_94_centos ~]# locate jdk

第三步: 配置环境变量

vi /etc/profile

[root@VM_46_94_centos ~]# vim /etc/profile

在文件的最后添加这两行:

export JAVA_HOME=/usr/java/jdk1.8.0_161 export PATH=JAVAHOME/bin:PATH

unset iunset -f pathmungeexport JAVA_HOME=/usr/java/jdk1.8.0_161export PATH=$JAVA_HOME/bin:$PATH

第四步: 使配置的环境变量生效

source /etc/profile

[root@VM_46_94_centos ~]# source /etc/profile

第五步: 查看环境变量

env

[root@VM_46_94_centos ~]# envXDG_SESSION_ID=309HOSTNAME=VM_46_94_centosTERM=xtermSHELL=/bin/bashHISTSIZE=3000SSH_CLIENT=58.62.52.254 15346 22SSH_TTY=/dev/pts/1USER=rootLS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:MAIL=/var/spool/mail/rootPATH=/usr/java/jdk1.8.0_161/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/binPWD=/rootJAVA_HOME=/usr/java/jdk1.8.0_161LANG=en_US.utf8HISTCONTROL=ignoredupsSHLVL=1HOME=/rootLOGNAME=rootSSH_CONNECTION=58.62.52.254 15346 10.186.46.94 22LESSOPEN=||/usr/bin/lesspipe.sh %sPROMPT_COMMAND=history -a; printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"XDG_RUNTIME_DIR=/run/user/0HISTTIMEFORMAT=%F %T _=/usr/bin/env[root@VM_46_94_centos ~]#

第六步: 和JDK版本

java -version

[root@VM_46_94_centos ~]# java -versionjava version "1.8.0_161"Java(TM) SE Runtime Environment (build 1.8.0_161-b12)Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)[root@VM_46_94_centos ~]#

2. 安装MySQL

MySQL版本: mysql-5.5.59-linux-glibc2.12-x86_64.tar.gzMySQL下载: /downloads/mysql/

参考1

参考2

参考3

参考4

第一步: 解压MySQL压缩包并更名

tar -zxvf mysql-5.5.59-linux-glibc2.12-x86_64.tar.gz

[root@VM_46_94_centos local]# tar -zxvf mysql-5.5.59-linux-glibc2.12-x86_64.tar.gz

解压包更名: mv -i mysql-5.5.59-linux-glibc2.12-x86_64 mysql

[root@VM_46_94_centos local]# mv -i mysql-5.5.59-linux-glibc2.12-x86_64 mysql

第二步: 添加系统mysql组和mysql用户

执行命令:groupadd mysql 和 useradd -r -g mysql mysql

[root@VM_46_94_centos local]# groupadd mysql[root@VM_46_94_centos local]# useradd -r -g mysql mysql

第三步: 安装数据库

进入安装mysql软件目录:cd /usr/local/mysql

[root@VM_46_94_centos local]# cd /usr/local/mysql[root@VM_46_94_centos mysql]#

修改当前目录拥有者为mysql用户: chown -R mysql:mysql ./

[root@VM_46_94_centos mysql]# chown -R mysql:mysql ./

安装数据库: ./scripts/mysql_install_db –user=mysql

[root@VM_46_94_centos mysql]# ./scripts/mysql_install_db --user=mysqlInstalling MySQL system tables...180408 13:05:53 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.180408 13:05:53 [Note] ./bin/mysqld (mysqld 5.5.59) starting as process 7425 ...OKFilling help tables...180408 13:05:55 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.180408 13:05:55 [Note] ./bin/mysqld (mysqld 5.5.59) starting as process 7433 ...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:./bin/mysqladmin -u root password 'new-password'./bin/mysqladmin -u root -h VM_46_94_centos password 'new-password'Alternatively you can run:./bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd . ; ./bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd ./mysql-test ; perl mysql-test-run.plPlease report any problems at /[root@VM_46_94_centos mysql]#

修改当前目录拥有者为root用户: chown -R root:root ./

[root@VM_46_94_centos mysql]# chown -R root:root ./

第四步: 复制启动程序

cp support-files/mysql.server /etc/init.d/mysql.server

[root@VM_46_94_centos mysql]# cp support-files/mysql.server /etc/init.d/mysql.server

第五步: 启动MySQL服务

/etc/init.d/mysql.server start 报错

[root@VM_46_94_centos mysql]# cp support-files/mysql.server /etc/init.d/mysql.server[root@VM_46_94_centos mysql]# /etc/init.d/mysql.server startStarting MySQL.180408 13:10:40 mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.ERROR! The server quit without updating PID file (/var/lib/mysql/VM_46_94_centos.pid).[root@VM_46_94_centos mysql]#

解决:修改配置文件 vim /etc/f

[root@VM_46_94_centos ~]# vim /etc/f

配置相应地方修改为如下:

[mysqld_safe]log-error=/var/log/mysql/mariadb.logpid-file=/var/run/mysql/mariadb.pid

再启动:成功

[root@VM_46_94_centos ~]# /etc/init.d/mysql.server startStarting MySQL.Logging to '/var/log/mysql/mariadb.log'... SUCCESS! [root@VM_46_94_centos ~]#

查看进程: ps -ef |grep mysql

[root@VM_46_94_centos ~]# ps -ef |grep mysqlroot141361 0 13:41 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/VM_46_94_centos.pidmysql 14287 14136 0 13:41 pts/1 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysql/mariadb.log --pid-file=/var/lib/mysql/VM_46_94_centos.pid --socket=/var/lib/mysql/mysql.sockroot16490 4284 0 13:43 pts/1 00:00:00 grep --color=auto mysql[root@VM_46_94_centos ~]#

第六步: 建立软链接,启动mysql

ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

[root@VM_46_94_centos ~]# ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql[root@VM_46_94_centos ~]# cd /usr/local/bin

这里报错

[root@VM_46_94_centos bin]# mysqlERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

解决方案:先停止服务,然后修改配置

/etc/init.d/mysql.server stop

[root@VM_46_94_centos bin]# /etc/init.d/mysql.server stopERROR! MySQL server PID file could not be found![root@VM_46_94_centos bin]# vim /etc/f

[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock

将上面配置修改为:

[mysqld]datadir=/var/lib/mysqlsocket=/tmp/mysql.sock

第七步: 重新启动: 成功,修改密码

/etc/init.d/mysql.server

[root@VM_46_94_centos bin]# /etc/init.d/mysql.server startStarting MySQL.Logging to '/var/log/mysql/mariadb.log'.. SUCCESS! [root@VM_46_94_centos bin]#

初始登录

[root@VM_46_94_centos bin]# mysql -urootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.5.59 MySQL Community Server (GPL)Copyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

修改密码:

mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> update user set password=password("123456") where user='root';Query OK, 4 rows affected (0.00 sec)Rows matched: 4 Changed: 4 Warnings: 0mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql>

第八步: 修改数据库的字符集

//查看数据库的字符集情况mysql> show variables like 'char%';+--------------------------+----------------------------------+| Variable_name | Value |+--------------------------+----------------------------------+| character_set_client| utf8 || character_set_connection | utf8 || character_set_database | latin1 || character_set_filesystem | binary || character_set_results | utf8 || character_set_server| latin1 || character_set_system| utf8 || character_sets_dir | /usr/local/mysql/share/charsets/ |+--------------------------+----------------------------------+8 rows in set (0.00 sec)//修改数据库字符集,其他的格式相同。mysql> set character_set_database=utf8;Query OK, 0 rows affected (0.00 sec)mysql> show variables like 'char%'; +--------------------------+----------------------------------+| Variable_name | Value |+--------------------------+----------------------------------+| character_set_client| utf8 || character_set_connection | utf8 || character_set_database | utf8 || character_set_filesystem | binary || character_set_results | utf8 || character_set_server| latin1 || character_set_system| utf8 || character_sets_dir | /usr/local/mysql/share/charsets/ |+--------------------------+----------------------------------+8 rows in set (0.00 sec)mysql>

==注意==:重启后,字符集并不好用。

需要修改配置文件/etc/f

[root@VM_46_94_centos ~]# vim /etc/f//在[mysqld]下添加一段话,不能写错了,否则会启动不了//character-set-server=utf8[mysqld]character-set-server=utf8datadir=/var/lib/mysqlsocket=/tmp/mysql.sock

第九步: 设置MySQL自动启动

[root@VM_46_94_centos init.d]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld[root@VM_46_94_centos init.d]# lsDbSecuritySpt functions jexec mysqld mysql.server netconsole network README redisd selinux[root@VM_46_94_centos init.d]# chmod 755 /etc/init.d/mysqld[root@VM_46_94_centos init.d]# chkconfig --list mysqldNote: This output shows SysV services only and does not include nativesystemd services. SysV configuration data might be overridden by nativesystemd configuration.If you want to list systemd services use 'systemctl list-unit-files'.To see services enabled on particular target use'systemctl list-dependencies [target]'.service mysqld supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add mysqld')[root@VM_46_94_centos init.d]# chkconfig --add mysqld[root@VM_46_94_centos init.d]# chkconfig mysqld on[root@VM_46_94_centos init.d]# chkconfig --list mysqldNote: This output shows SysV services only and does not include nativesystemd services. SysV configuration data might be overridden by nativesystemd configuration.If you want to list systemd services use 'systemctl list-unit-files'.To see services enabled on particular target use'systemctl list-dependencies [target]'.mysqld0:off 1:off 2:on 3:on 4:on 5:on 6:off[root@VM_46_94_centos init.d]#

第十步: MySQL授权允许远程连接

grant all privileges on.to ‘root’@’%’ identified by ‘123456’;

mysql> grant all privileges on *.* to 'root'@'%' identified by '123456';Query OK, 0 rows affected (0.00 sec)mysql>

3. 安装Tomcat

Tomcat版本: apache-tomcat-8.5.29.tar.gz下载地址: /download-80.cgi#8.5.29

下载Core中的tar.gz版本tomcat是一个绿色软件,不用安装,直接使用. 但JAVA_HOME一定配置

第一步: 解压tomcat

tar -zxvf apache-tomcat-8.5.29.tar.gz

[root@VM_46_94_centos local]# tar -zxvf apache-tomcat-8.5.29.tar.gz

第二步: 启动tomcat

启动: ./startup.sh

关闭: ./shutdown.sh

[root@VM_46_94_centos apache-tomcat-8.5.29]# cd bin[root@VM_46_94_centos bin]# lsbootstrap.jar catalina-tasks.xml configtest.bat digest.bat setclasspath.sh startup.battomcat-native.tar.gz version.batcatalina.bat commons-daemon.jar configtest.sh digest.sh shutdown.batstartup.sh tool-wrapper.batversion.shcatalina.sh commons-daemon-native.tar.gz daemon.sh setclasspath.bat shutdown.shtomcat-juli.jar tool-wrapper.sh[root@VM_46_94_centos bin]# ./startup.sh Using CATALINA_BASE: /usr/local/apache-tomcat-8.5.29Using CATALINA_HOME: /usr/local/apache-tomcat-8.5.29Using CATALINA_TMPDIR: /usr/local/apache-tomcat-8.5.29/tempUsing JRE_HOME: /usr/java/jdk1.8.0_161Using CLASSPATH: /usr/local/apache-tomcat-8.5.29/bin/bootstrap.jar:/usr/local/apache-tomcat-8.5.29/bin/tomcat-juli.jarTomcat started.[root@VM_46_94_centos bin]#

4. 安装Redis

Redis版本: redis-4.0.9.tar.gzRedis中国站: /download.htmlRedis国外(需要翻墙): https://redis.io/

第一步: 将redis-4.0.9.tar.gz安装包复制到/usr/local目录

[root@VM_46_94_centos ~]# cp /usr/java/redis-4.0.9.tar.gz /usr/local

第二步: 解压压缩包

tar -zxvf redis-4.0.9.tar.gz

[root@VM_46_94_centos ~]# cd /usr/local[root@VM_46_94_centos local]# lsbin etc games include lib lib64 libexec qcloud redis-4.0.9.tar.gz sbin share src[root@VM_46_94_centos local]# tar -zxvf redis-4.0.9.tar.gz

第三步:yum安装gcc依赖

yum install gcc

[root@VM_46_94_centos local]# yum install gccTotal download size: 45 MIs this ok [y/d/N]: 遇到选择,输入y即可

第四步:跳转到redis解压目录下

cd redis-4.0.9

[root@VM_46_94_centos local]# cd redis-4.0.9/

第五步:编译安装

make MALLOC=libc

[root@VM_46_94_centos redis-4.0.9]# make MALLOC=libc CC siphash.o CC rax.o LINK redis-server INSTALL redis-sentinel CC redis-cli.o LINK redis-cli CC redis-benchmark.o LINK redis-benchmark INSTALL redis-check-rdb INSTALL redis-check-aofHint: It's a good idea to run 'make test' ;)make[1]: Leaving directory `/usr/local/redis-4.0.9/src'

将/usr/local/redis-4.0.9/src目录下的文件加到/usr/local/bin目录: cd src && make install

[root@VM_46_94_centos redis-4.0.9]# cd src && make installCC Makefile.depHint: It's a good idea to run 'make test' ;)INSTALL installINSTALL installINSTALL installINSTALL installINSTALL install[root@VM_46_94_centos src]#

第六步:测试是否安装成功

先切换到redis src目录下

[root@VM_46_94_centos redis-4.0.9]# cd src

直接启动redis:./redis-server

[root@VM_46_94_centos src]# ./redis-server3047:C 04 Apr 12:58:30.367 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo3047:C 04 Apr 12:58:30.367 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=3047, just started3047:C 04 Apr 12:58:30.367 # 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.9 (00000000/0) 64 bit.-`` .-```. ```\/ _.,_ ''-._( ', .-` | `, )Running in standalone mode|`-._`-...-` __...-.``-._|'` _.-'|Port: 6379| `-._ `._ /_.-' |PID: 3047`-._ `-._ `-./ _.-' _.-'|`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-'|`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-'`-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 3047:M 04 Apr 12:58:30.369 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.3047:M 04 Apr 12:58:30.369 # Server initialized3047:M 04 Apr 12:58:30.369 # 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.3047:M 04 Apr 12:58:30.369 # 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.3047:M 04 Apr 12:58:30.369 * Ready to accept connections

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

按 ctrl + c可以关闭窗口。

以后台进程方式启动redis(推荐)

第一步: 复制备份redis.conf文件

[root@VM_46_94_centos redis-4.0.9]# mkdir /usr/java/redis[root@VM_46_94_centos ~]# cp /usr/local/redis-4.0.9/redis.conf /usr/java/redis/

第二步: 修改redis.conf文件

set nu 可出现文件行 :wq保存退出 :q!退出不保存[root@VM_46_94_centos redis-4.0.9]# vim redis.conf

# 设置不仅限制本地访问 (69行)bind 127.0.0.1 改为 # bind 127.0.0.1# 禁用保护模式 (88行)protected-mode yes 改为 protected-mode no # 设置后台启动redis,修改如下,默认为no (136行)daemonize no 改为 daemonize yes

注意:如果在编辑时意外退出,可删除临时文件

[root@VM_46_94_centos redis-4.0.9]# rm .redis.conf.swprm: remove regular file ‘.redis.conf.swp’? y

第三步:指定redis.conf文件启动: ./redis-server /usr/local/redis-4.0.9/redis.conf

[root@VM_46_94_centos src]# ./redis-server /usr/local/redis-4.0.9/redis.conf3721:C 04 Apr 13:11:05.472 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo3721:C 04 Apr 13:11:05.472 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=3721, just started3721:C 04 Apr 13:11:05.472 # Configuration loaded

第四步:关闭redis进程:首先使用ps -aux | grep redis查看redis进程

[root@VM_46_94_centos src]# ps -aux | grep redisroot3543 0.0 0.2 151368 5092 pts/1 T 13:07 0:00 vim redis.confroot3722 0.0 0.1 141784 1988 ? Ssl 13:11 0:00 ./redis-server *:6379root3799 0.0 0.0 112660 972 pts/1 R+ 13:12 0:00 grep --color=auto redis

使用kill命令杀死进程

[root@VM_46_94_centos src]# kill -9 3722

第七步 : 设置redis开机自启动

在/etc目录下新建redis目录

[root@VM_46_94_centos src]# mkdir /etc/redis

将/usr/local/redis-4.0.9/redis.conf 文件复制一份到/etc/redis目录下,并命名为6379.conf

[root@VM_46_94_centos redis]# cp /usr/local/redis-4.0.9/redis.conf /etc/redis/6379.conf

将redis的启动脚本复制一份放到/etc/init.d目录下

[root@VM_46_94_centos redis]# cp /usr/local/redis-4.0.9/utils/redis_init_script /etc/init.d/redisd

设置redis开机自启动, 先切换到/etc/init.d目录下, 然后执行自启命令

[root@VM_46_94_centos init.d]# chkconfig redisd onservice redisd does not support chkconfig

看结果是redisd不支持chkconfig

解决方法:

使用vim编辑redisd文件,在第一行加入如下两行注释,保存退出

[root@VM_46_94_centos init.d]# vim redisd#!/bin/sh# chkconfig: 2345 90 10# description: Redis is a persistent key-value database## Simple Redis init.d script conceived to work on Linux systems# as it does use of the /proc filesystem.

注释的意思是,redis服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的优先级是10。

再次执行开机自启命令,成功

[root@VM_46_94_centos init.d]# chkconfig redisd on

现在可以直接已服务的形式启动和关闭redis了

关闭:

service redisd stop

[root@VM_46_94_centos ~]# service redisd stopStopping ...Could not connect to Redis at 127.0.0.1:6379: Connection refusedRedis stopped

启动:service redisd start

如果出现如下问题:

[root@VM_46_94_centos ~]# service redisd start/var/run/redis_6379.pid exists, process is already running or crashed

1:可用安装文件启动redis-server/etc/redis/6379.conf2:shutdown -r now 软重启让系统自动恢复下就行了

[root@VM_46_94_centos ~]# redis-server /etc/redis/6379.conf4571:C 04 Apr 13:26:34.675 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo4571:C 04 Apr 13:26:34.675 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=4571, just started4571:C 04 Apr 13:26:34.675 # Configuration loaded

第八步: 修改Redis密码

修改/etc/redis/6379.conf, /usr/local/redis-4.0.9/redis.conf

# 设置Redis登录密码(500行)# requirepass foobared 改为 requirepass 123456

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。