以下内容均在阿里云 CentOS 7.0 64 位环境下运行
用 Nodejs 提供服务
$ yum update # 最好更新,否则过程中有可能会出问题
$ useradd -m username
$ passwd username
$ usermod -a -G wheel username # 为用户添加 sudo 权限
# install nginx
$ sudo yum install -y nginx
# start nginx
$ sudo systemctl start nginx.service
# Optional, auto run when power on
$ sudo systemctl enable nginx.service
将 nginx 证书文件(一个 .key 一个 .pem 文件)上传到服务器 /etc/nginx/cert/
目录下(如没有,要手动创建)。以下代码不具有适用性,如果看不懂,就手动自己实现上面的操作。
# server_ip 为服务器 ip
# local_cert_fold 为本地证书存放文件夹
# 留意,此处要输入两遍密码
$ ssh root@server_ip \
"[ -d /etc/nginx/cert/ ] && echo ok || mkdir -p /etc/nginx/cert/" && \
scp /local_cert_fold/* root@server_ip:/etc/nginx/cert/
修改 /etc/nginx/nginx.conf
中的配置,my_ssl_cert
替换为自己的文件名
ssl_certificate "cert/my_ssl_cert.pem";
ssl_certificate_key "cert/my_ssl_cert.key";
重启 nginx
$ sudo systemctl restart nginx.service
安装 nvm,方便 nodejs 的版本管理。若安装后出现 nvm: command not found
,新打开个 terminal 或重新登录即可,详见 nvm github
$ wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
安装 nodejs
$ nvm install --lts
安装 cnpm(可选)
$ npm i -g cnpm --registry=https://registry.npm.taobao.org
安装 pm2
$ cnpm i -g pm2
详见 Get Docker Engine - Community for CentOS
$ sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# Install required packages.
# yum-utils provides the yum-config-manager utility,
# and device-mapper-persistent-data
# and lvm2 are required by the devicemapper storage driver.
$ sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
# 此处用了国内镜像
# 原镜像为 https://download.docker.com/linux/centos/docker-ce.repo
$ sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#Install the latest version of Docker Engine - Community and containerd
$ sudo yum -y install docker-ce docker-ce-cli containerd.io
# Start Docker
$ sudo systemctl start docker.service
# Optional, set docker auto run when power on
$ sudo systemctl enable docker.service
此处选择的 docker 模式,所以要先完成 docker 的安装,详见 安装Jenkins
$ docker run \
-u root \
--name="jenkins" \
--rm \
-d \
-p 8080:8080 \
-p 50000:50000 \
-v jenkins-data:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
jenkinsci/blueocean
http://server_ip:8080
完成后续步骤,详见 安装后设置向导,需要输入 admin password 的见下文$ docker logs jenkins # 查看 admin password
# OR
$ docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
$ yum install -y mariadb-server
$ systemctl start mariadb.service
找个目录,新建两个文件,详见 nginx-proxy-manager
config.json
{
"database": {
"engine": "mysql",
"host": "db",
"name": "npm",
"user": "npm",
"password": "npm",
"port": 3306
}
}
docker-compose.yml
version: "3"
services:
app:
image: jc21/nginx-proxy-manager:latest
restart: always
ports:
- 80:80
- 81:81
- 443:443
volumes:
- ./config.json:/app/config/production.json
- ./data:/data
- ./letsencrypt:/etc/letsencrypt
depends_on:
- db
environment:
# if you want pretty colors in your docker logs:
- FORCE_COLOR=1
db:
image: mariadb:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: "npm"
MYSQL_DATABASE: "npm"
MYSQL_USER: "npm"
MYSQL_PASSWORD: "npm"
volumes:
- ./data/mysql:/var/lib/mysql
在此目录下运行 docker-compose up -d
后,访问 http://server_ip:81
即可
详见 Install MongoDB Community Edition
$ vim /etc/yum.repos.d/mongodb-org-4.2.repo # 粘贴入以下内容
[mongodb-org-4.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
$ yum install -y mongodb-org
$ systemctl start mongod.service