后端软件服务安装整理

160 阅读4分钟

新办了个服务器,一些软件安装过程记录在此

1.Redis

服务下载完成后移动到/usr/local/ 目录下

>> mv /root/work/netcode/redis-6.2.6 /usr/local/redis
>> cd  /usr/local/redis

编译

>> make

安装

>> make PREFIX=/usr/local/redis install

设置异步运行

>> vim redis.conf
daemonize=yes
...

设置开机自动启动

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

# !/bin/sh后面加上

# chkconfig: 2345 10 90
# description: Start and Stop redis
然后修改配置
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
#CONF="/etc/redis/${REDISPORT}.conf"
CONF="/usr/local/redis/redis.conf"

测一下

/etc/init.d/redis start

设置开机自动启动

chkconfig redis on

service redis start 
service redis stop

查看服务列表中是否有这个服务

systemctl list-unit-files --type=service

有的话执行 systemctl daemon-reload 即可

查看redis安装位置

[root@VM-8-17-centos etc]#  ps -ef | grep redis
root     29271     1  0 20:48 ?        00:00:00 /usr/local/redis/bin/redis-server 127.0.0.1:6379
root     32022  2127  0 21:07 pts/1    00:00:00 grep --color=auto redis

拿到上面进程号 4687、然后查询:

[root@iZ7xvg30tjzukritex8k2oZ ~]# ll -l /proc/4687/cwd
lrwxrwxrwx. 1 root root 0 Jan 5 01:59 /proc/4687/cwd -> /usr/local/redis/bin

2.nginx安装

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make 
make install 

[root@VM-8-17-centos nginx-1.22.1]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successfu

3.设置https、使用 Certbot 管理来自 Let’s Encrypt 的证书

官网教程链接:certbot.eff.org/instruction…

在 CentOS 7 中添加 EPEL

sudo yum install -y epel-release

sudo yum install -y snapd

systemctl enable --now snapd.socket

sudo ln -s /var/lib/snapd/snap /snap

sudo snap install --classic certbot

sudo ln -s /snap/bin/certbot /usr/bin/certbot

# 自动获取并安装您的证书
certbot --nginx

安装过程中如果出现重复选项的问题:

[root@VM-8-17-centos vhost]# certbot install --cert-name itech10.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Deploying certificate
Successfully deployed certificate for itech10.com to /etc/nginx/vhost/www.itech10.com_443.conf
We were unable to install your certificate, however, we successfully restored your server to its prior configuration.
nginx restart failed:
nginx: [emerg] a duplicate listen 0.0.0.0:443 in /etc/nginx/vhost/www.itech10.com_443.conf:58

原因是因为原来的nginx配置里面已经设置了listen 443 需要去掉

测试自动续订

certbot renew --dry-run

现在certbot自带了定时器更新证书,所以安装一次后续不需要在管更新证书的事。

4.Mysql

1.安装链接:downloads.mysql.com/archives/co… 自定义安装选择linux generic Linux下MySQL的配置文件(my.cnf)的存放路径 安装相关库

yum -y install numactl

2.建立用户和组

groupadd mysql
useradd -r -g mysql -s /bin/false mysql

3.创建相关目录

mkdir -p /data/mysql 
chown -R mysql:mysql /data 
chown -R mysql:mysql /usr/local/mysql 
chmod 750 /data

4.卸载## 自带mariadb和mysq rpm -qa | grep mysql rpm -qa | grep mariadb

[root@VM-8-17-centos logs]# locate my.cnf
/etc/my.cnf

5.mysql初始化

mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/

[root@VM-8-17-centos mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/
2022-10-30T14:39:28.231608Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.12) initializing of server in progress as process 9924
2022-10-30T14:39:30.142686Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: MFz1A&#r&AGy
2022-10-30T14:39:31.693516Z 0 [System] [MY-013170] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.12) initializing of server has completed

root用户初始密码:MFz1A&#r&AGy

6.配置my.cnf

[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
server_id=6
port=3306
socket=/tmp/mysql.sock
##客户端
[mysql]
socket=/tmp/mysql.sock

7.启动Mysql

/usr/local/mysql/support-files/mysql.server start

8.修改密码 mysqladmin -u root -p password '新密码' 回车输入旧密码

9.建立软连接

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

10.配置开机自启

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

查看默认读取Mysql的目录

[root@VM-8-17-centos logs]# mysql --help | grep 'my.cnf'
                      order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

[ERROR] Can't find messagefile '/usr/local/mysql/share/errmsg.sys' 清除数据存储目录,重新安装试试

=== mysql安装参考:cloud.tencent.com/developer/a…

5. 配置远程git仓库

服务器端: 1.安装git

yum install -y git

2.添加新用户

adduser git
passwd git

3.设置禁止shell登录 vim /etc/passwd

git:x:1002:1003::/home/git:/bin/bash
修改为
git:x:1002:1003::/home/git:/usr/bin/git-shell

4.创建客户端登录证书

cd /home/git
mkdir .ssh
cd .ssh
vim authorized_keys

创建客户端sh证书(忽略),将本地客户端的id.rsa_pub公钥写进文件authorized_keys,一行一个。添加了这个以后你连接中央仓库就不需要输入密码了,直接使用公钥和私钥的验证方式

5.新建目录

mkdir /data/git
cd /data/git
新建项目
mkdir toolsapi.git
cd toolsapi.git
初始化仓库
git init --bare toolsapi.git
赋予权限
chown git:git  toolsapi.git

6.本地客户端安装git后获取远程代码

git ip://data/git/toolsapi.git