codepush安装

https://github.com/lisong/code-push-server/blob/master/docs/README.md
=====> 安装mysql
下载mysql yum repository 安装
https://dev.mysql.com/downloads/repo/yum/
yum install mysql80-community-release-el7-3.noarch.rpm
yum repolist enabled | grep "mysql.*-community.*"
yum -y install yum-utils
yum-config-manager --enable mysql80-community
yum install mysql-community-server
systemctl start mysqld

# 取消密码强度验证 修改 /etc/my.cnf
plugin-load=validate_password.so
validate-password=OFF

# 第一次登录获取临时密码
grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p

ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
SHOW VARIABLES LIKE 'validate_password%';
set global validate_password.policy=0;
set global validate_password.length=1;

# 创建用户并授权
create user 'codepush'@'localhost' IDENTIFIED BY 'NUU02uxK9j^#7LvAOUa^Ewqdivc-N#@G';
grant all privileges on *.* to 'codepush'@'localhost';
ALTER USER 'codepush'@'localhost' IDENTIFIED WITH mysql_native_password BY 'NUU02uxK9j7LvAOUaEwqdivc@';
flush privileges;



=====> 安装redis
cd /opt/
wget http://download.redis.io/releases/redis-4.0.0.tar.gz
tar xzf redis-4.0.0.tar.gz
cd redis-4.0.0
make && make install PREFIX=/data/apps/redis
cd /data/apps/redis
mkdir conf
cp /opt/redis-4.0.0/redis.conf ./conf

sed -i 's/daemonize no/daemonize yes/' conf/redis.conf
sed -i 's/protected-mode yes/protected-mode no/' conf/redis.conf
#sed -i 's/bind 127.0.0.1/bind 0.0.0.0/' conf/redis.conf
echo 'requirepass jumpserver@admin.' >> conf/redis.conf


useradd -M redis
chown -R redis.redis /data/apps/redis


cat <<EOF > /usr/lib/systemd/system/redis.service

[Unit]
Description=Redis Server Manager
After=syslog.target
After=network.target

[Service]
Type=simple
User=redis
Group=redis
PIDFile=/var/run/redis_6379.pid
ExecStart=/data/apps/redis/bin/redis-server /data/apps/redis/conf/redis.conf
ExecStop=/data/apps/redis/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl start redis
systemctl enable redis

# 解决You need tcl 8.5 or newer in order to run the Redis test
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/
cd /usr/local/tcl8.6.1/unix/
./configure
make
make install
make PREFIX=/redis-4.0.10 install (指定安装redis位置)


# 设置开机启动的另外一种方式
复制redis安装文件夹中的启动脚本到/etc/init.d
cp /redis-4.0.10/utils/redis_init_script /etc/init.d/redis
修改脚本
vi /etc/init.d/redis
将如下两行 = 号后面换成安装目录中对应的启动文件
EXEC=/data/apps/redis/bin/redis-server
CLIEXEC=/data/apps/redis/bin/redis-cli
CONF="/opt/software/redis-4.0.14/redis.conf"
修改权限
chmod +x /etc/init.d/redis
添加redis服务:
chkconfig --add redis
设为开机启动:
chkconfig redis on
redis启动关闭等命令
service redis start
service redis stop
ps -ef | grep redis


=====> 安装Nginx
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel autoconf automake make
wget https://nginx.org/download/nginx-1.16.0.tar.gz
tar -xf nginx-1.16.0.tar.gz
cd nginx-1.16.0
useradd -M -s /sbin/nologin nginx
./configure --prefix=/data/apps/nginx --user=nginx --group=nginx --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-stream
make && make install

# 配置环境变量
echo "export PATH=/data/apps/nginx/sbin:$PATH" > /etc/profile.d/nginx.sh
source /etc/profile

 

=====> 安装codepush
cd /data/apps/
# INSTALL NODE AND NPM
yum -y install npm
# INSTALL PM2
npm i -g pm2
# GET code-push-server FROM NPM
npm install code-push-server@latest -g
# GET code-push-server FROM SOURCE CODE
git clone https://github.com/lisong/code-push-server.git
cd code-push-server
npm install
# INIT DATABASE
code-push-server-db init --dbhost localhost --dbport 3306 --dbuser "codepush" --dbpassword "codePush@365"
# ./bin/db init --dbhost localhost --dbport 3306 --dbuser "codepush" --dbpassword 'codePush@365'
# 修改配置文件
sed -i 's/null/password/' bin/db
# 修改 config.js (在config/config.js下)
qiniu: {
accessKey: "63o7v6hB_2MsY0cl9YC8eg3Gor9ytnliQV4BTacP",
secretKey: "fRWTWY7T361WiArdHuCzBVoPvu8nUCyz-U_sOKjF",
bucketName: "dxsp",
downloadUrl: "http://test.dianyi125.com" // Binary files download host address.
},
// 去https://www.grc.com/passwords.htm获取63 random alpha-numeric characters (a-z, A-Z, 0-9):的密钥
jwt: {
// Recommended: 63 random alpha-numeric characters
// Generate using: https://www.grc.com/passwords.htm
//tokenSecret: process.env.TOKEN_SECRET ||'INSERT_RANDOM_TOKEN_KEY'
tokenSecret: process.env.TOKEN_SECRET || '3UqxPvyAZjRXbsLuP0Hr2dcyNdaF5wTkJox3P6ogUBmCIbfoBFiUuqHsCxDm1Jl'
},

# 使用pm2管理 修改 ./docs/process.json
{
"apps" : [
{
"name" : "code-push-server",
"max_memory_restart" : "300M",
"script" : "../bin/www",
"instances" : "max", //开启实例数量,max为cpu核数
"exec_mode" : "cluster", //集群模式,最大提升网站并发
"env" : {
"NODE_ENV" : "production",
"PORT" : 80,
"CONFIG_FILE" : "../config/config.js"
}
]
}

$ pm2 start process.json

 

 

 

 

 


// 更多 pm2 命令
$ pm2 stop [options] <id|name|all|json|stdin...> 关闭服务
$ pm2 list 查看所有
$ pm2 show <id> 查看某个服务的信息
# 普通启动
./bin/www

# CHECK SERVICE IS OK
curl -I http://103.219.30.6
# UPGRADE
npm install -g code-push-server@latest
code-push-server-db upgrade --dbhost "your mysql host" --dbport "your mysql port" --dbuser "your mysql user" --dbpassword "your mysql password" # upgrade codepush database
pm2 restart code-push-server # restart service
# view pm2 logs
pm2 ls
pm2 show code-push-server
tail -f "output file path"

# mysqldump -uroot codepush > codepush.sql
create database codepush default character set utf8mb4 collate utf8mb4_unicode_ci;
# mysql -u root -p codepush < codepush.sql

posted @ 2019-09-19 13:21  Ray_chen  阅读(1002)  评论(0编辑  收藏  举报