编译支持WebP模块的iMagick需要有libwebp的支持。
apt-get install libwebp-dev -y
然后进入 ~/oneinstack/include文件夹,编辑ImageMagick.sh文件:
cd ~/oneinstack/include
vi ImageMagick.sh
在带有 ./configure的两行后面添加 --with-webp=yes,修改后的效果:
./configure --prefix=${imagick_install_dir} --enable-shared --enable-static --with-webp=yes
如果已经安装有iMagick,先运行卸载命令,然后再重新编译安装:
~/oneinstack/uninstall.sh --php_extensions imagick #卸载
~/oneinstack/install.sh --php_extensions imagick #安装
This script is written using the shell, in order to quickly deploy LEMP
/LAMP
/LNMP
/LNMPA
/LTMP
(Linux, Nginx/Tengine/OpenResty, MySQL in a production environment/MariaDB/Percona, PHP, JAVA), applicable to RHEL 7, 8, 9(including CentOS,RedHat,AlmaLinux,Rocky), Debian 9, 10, 11, 12, Ubuntu 16, 18, 20, 22 and Fedora 27+ of 64.
Script properties:
- Continually updated, Provide Shell Interaction and Autoinstall
- Source compiler installation, most stable source is the latest version, and download from the official site
- Some security optimization
- Providing a plurality of database versions (MySQL-8.0, MySQL-5.7, MySQL-5.6, MySQL-5.5, MariaDB-10.11, MariaDB-10.5, MariaDB-10.4, MariaDB-5.5, Percona-8.0, Percona-5.7, Percona-5.6, Percona-5.5, PostgreSQL, MongoDB)
- Providing multiple PHP versions (PHP-8.3, PHP-8.2, PHP-8.1, PHP-8.0, PHP-7.4, PHP-7.3, PHP-7.2, PHP-7.1, PHP-7.0, PHP-5.6, PHP-5.5, PHP-5.4, PHP-5.3)
- Provide Nginx, Tengine, OpenResty, Apache and ngx_lua_waf
- Providing a plurality of Tomcat version (Tomcat-10, Tomcat-9, Tomcat-8, Tomcat-7)
- Providing a plurality of JDK version (OpenJDK-8, OpenJDK-11, OpenJDK-17)
- According to their needs to install PHP Cache Accelerator provides ZendOPcache, xcache, apcu, eAccelerator. And php extensions,include ZendGuardLoader,ionCube,SourceGuardian,imagick,gmagick,fileinfo,imap,ldap,calendar,phalcon,yaf,yar,redis,memcached,memcache,mongodb,swoole,xdebug
- Installation Nodejs, Pureftpd, phpMyAdmin according to their needs
- Install memcached, redis according to their needs
- Jemalloc optimize MySQL, Nginx
- Providing add a virtual host script, include Let's Encrypt SSL certificate
- Provide Nginx/Tengine/OpenResty/Apache/Tomcat, MySQL/MariaDB/Percona, PHP, Redis, Memcached, phpMyAdmin upgrade script
- Provide local,remote(rsync between servers),Aliyun OSS,Qcloud COS,UPYUN,QINIU,Amazon S3,Google Drive and Dropbox backup script
Install the dependencies for your distro, download the source and run the installation script.
yum -y install wget screen
apt-get -y install wget screen
wget http://mirrors.linuxeye.com/oneinstack-full.tar.gz
tar xzf oneinstack-full.tar.gz
cd oneinstack
If you disconnect during installation, you can execute the command screen -r oneinstack
to reconnect to the install window
screen -S oneinstack
If you need to modify the directory (installation, data storage, Nginx logs), modify options.conf
file before running install.sh
./install.sh
~/oneinstack/install.sh --mphp_ver 54
~/oneinstack/addons.sh
~/oneinstack/vhost.sh
~/oneinstack/vhost.sh --del
~/oneinstack/pureftpd_vhost.sh
~/oneinstack/backup_setup.sh // Backup parameters
~/oneinstack/backup.sh // Perform the backup immediately
crontab -l // Can be added to scheduled tasks, such as automatic backups every day 1:00
0 1 * * * cd ~/oneinstack/backup.sh > /dev/null 2>&1 &
Nginx/Tengine/OpenResty:
systemctl {start|stop|status|restart|reload} nginx
MySQL/MariaDB/Percona:
systemctl {start|stop|restart|reload|status} mysqld
PostgreSQL:
systemctl {start|stop|restart|status} postgresql
MongoDB:
systemctl {start|stop|status|restart|reload} mongod
PHP:
systemctl {start|stop|restart|reload|status} php-fpm
Apache:
systemctl {start|restart|stop} httpd
Tomcat:
systemctl {start|stop|status|restart} tomcat
Pure-FTPd:
systemctl {start|stop|restart|status} pureftpd
Redis:
systemctl {start|stop|status|restart|reload} redis-server
Memcached:
systemctl {start|stop|status|restart|reload} memcached
~/oneinstack/upgrade.sh
~/oneinstack/uninstall.sh
caddy和php容器不同时需要分别设置root路径,参考以下caddyfile文件。
mysite.com {
// 这是caddy容器下的laravel目录
root * /srv/mysite.com/public
encode zstd gzip
file_server
try_files {path} /index.php?{query}
php_fastcgi * php_docker:9000 {
// 这是php容器下的laravel目录
root /var/www/html/mysite.com/public
}
log {
output file /data/caddy.log
}
}
RUN apt-get install -y zip libzip-dev && docker-php-ext-install zip
首先,安装libzip库,然后就是docker-php-ext-install来安装zip扩展即可。
错误信息:
docker.errors.DockerException: Error while fetching server API version: HTTPConnection.request() got an unexpected keyword argument 'chunked'
解决方案:
这是因urllib3的新版本导致的问题。需要降低urllib3的版本。首先,pip删除urllib3,然后安装2.0以下的版本,如下
pip install urllib3==1.26.8 -i https://pypi.tuna.tsinghua.edu.cn/simple
以下是PHP版实现,重点是,checkSessionKey接口要求加密的内容是空的,不能给空数组,需要对空字符串加密。(不包含openid,accesstoken,sig_method等)
hash_hmac加密时,key是用户的sessionKey。
private function signature(array &$data, string $openid): string
{
$sessionKey = $this->getSessionKey($openid);
$s = empty($data) ? "" : json_encode($data);
return hash_hmac('sha256', $s, $sessionKey);
}
private function sign(array &$data, string $openid): array
{
$data['signature'] = $this->sign($data, $openid);
$data['sig_method'] = 'hmac_sha256'; // 固定参数
$data['access_token'] = "后端保存的access_token";
$data['openid'] = $openid;// 用户openid
return $data;
}
$data = [];
$this->sign($data, $openid);
// 以下是laravel的http客户端请求方法,重点是签名完的数据用http_build_query拼接成query,并发送get请求。
$response = Http::acceptJson()->get('https://api.weixin.qq.com/wxa/checksession', http_build_query($data));
version: '3.8'
services:
cache:
image: redis:6.2-alpine
restart: always
ports:
- '6379:6379'
command: redis-server --save 20 1 --loglevel warning --requirepass this_is_password
volumes:
- cache:/data
volumes:
cache:
driver: local
以上是redis在docker下运行时的docker.yml文件示例。
PUA:Win32/Packunwan是一种臭名昭著的Windows恶意软件。
PUA:Win32/Packunwan这个病毒软件会通过各种方式欺骗用户点击从而进行传播,比如伪装成美女聊天工具图标,诱惑用户点击,从而窃取用户隐私,危害用户信息安全。
如果电脑中了PUA:Win32/Packunwan病毒,可以使用win10系统自带的杀毒软件查杀,或者下载使用卡巴杀毒来查杀1。如果不能彻底清除的话,可以格式化硬盘后重新安装系统来解决。
发生这种情况可能有多种原因,例如:
- 一个goroutine正在等待一个通道接收数据,但没有其他 goroutine 向该通道发送数据。
- 一个goroutine正在等待获取锁,但另一个 goroutine 正在持有锁。
- goroutine正在等待满足条件,但条件永远不会满足。
当两个或多个goroutines 正在等待彼此完成,并且它们都无法继续时,就会发生死锁。使用频道和同步时可能会发生这种情况。互斥或同步。导致循环依赖关系的等待组。
下面是死锁情况的示例。
package main
import (
"fmt"
"sync"
"time"
)
func main() {
wg := new(sync.WaitGroup)
messages := make(chan string)
for x := 1; x <= 4; x++ {
wg.Add(1)
go messageReceiever(x, wg, &messages)
}
for msg := range messages {
fmt.Println(msg)
}
wg.Wait()
close(messages)
}
func messageReceiever(count int, wg *sync.WaitGroup, messages *chan string) {
defer wg.Done()
time.Sleep(time.Millisecond * time.Duration(1000))
*messages <- fmt.Sprintf("John Wick: %d", count)
}
输出
John Wick: 1
John Wick: 4
John Wick: 2
John Wick: 3
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan receive]:
上面代码中的问题是我们使用了一个带有范围的 for 循环从消息通道读取,但直到循环之后我们才关闭通道。这会导致循环无限期地等待更多消息,从而造成死锁。
要修复致命错误,您可以移动wg.Wait()在for循环之前,并在所有其他 goroutines 完成后使用单独的goroutine关闭消息通道。
下面是修复后的示例代码:
package main
import (
"fmt"
"sync"
"time"
)
func main() {
wg := new(sync.WaitGroup)
messages := make(chan string)
// 启动goroutines
for x := 1; x <= 4; x++ {
wg.Add(1)
go messageReceiever(x, wg, messages)
}
// 单独启动一个goroutine等待所有goroutine结束并关闭channel
go func() {
wg.Wait()
close(messages)
}()
// 从channel读取
for msg := range messages {
fmt.Println(msg)
}
}
func messageReceiever(count int, wg *sync.WaitGroup, messages chan string) {
defer wg.Done()
time.Sleep(time.Millisecond * time.Duration(1000))
messages <- fmt.Sprintf("John Wick: %d", count)
}
输出
John Wick: 3
John Wick: 4
John Wick: 1
John Wick: 2
在这个固定版本中,我们创建了一个新的goroutine,等待其他goroutines完成使用wg.Wait(),然后关闭消息通道。一旦消息关闭,带有范围的 for 循环现在将退出,从而避免死锁。
以下是避免 Go 中死锁的一些提示:
使用通道在 goroutines 之间进行通信。
使用锁保护共享资源。
使用条件等待事件发生。
使用同步包来帮助您管理 goroutines 和共享资源。
在 Docker Compose 的yaml文件中,可以通过指定每个服务的内存限制来限制容器的内存。具体的做法是使用mem_limit字段来指定内存限制,单位可以是字节 (b) 或者是常用单位(例如 k 表示 KB,m 表示 MB,g 表示 GB)。
以下是示例代码:
yamlversion: '3'
services:
myservice:
image: myimage
mem_limit: 512m # 限制内存为 512 MB
我发现了在docker容器中安装snapd的问题:目前不支持以这种方式运行snapd。
这个问题已经在snapcraft论坛上被问到了。snapd的依赖项之一是systemd,如果不重新启动或重新登录,snapd服务就无法正确初始化。根据所有发行版的文档,这是必需的程序,但显然在docker中不是一个选项。
在docker主机上安装snapd,在运行时将snapd套接字装入已安装snapd的容器中。
这里是官方回复:无法在 docker 映像(ubuntu:19.10)中安装 snapcraft snap) - snapcraft - snapcraft.io
在Docker中,--rm选项用于在容器退出时自动删除容器所创建的镜像。
默认情况下,当容器退出时,Docker会保留该容器的镜像,以供后续使用。但是,如果你使用了--rm选项,Docker将会删除该容器的镜像。
这个选项非常有用,特别是当你只需要临时运行一个容器,而不需要保留其镜像时。使用--rm选项可以确保容器的镜像不会被保留,从而节省磁盘空间。
在Docker中,-m或--memory参数用于限制容器的最大内存使用量。
例如,docker run -m 1g [镜像名],表示运行一个容器,并限制其最大内存使用量为1GB。这种设置可以避免某个容器占用过多内存而导致整个主机的性能问题.
默认的背包安装不附带文件管理组件。因为大多数项目都不需要它。用以下命令可以快速添加文件管理服务,将elFinder的强大功能带到您的Laravel项目中。
# require the package
composer require backpack/filemanager
# then run the installation process
php artisan backpack:filemanager:install
如果您选择安装背包/文件管理器,您将把elFinder集成到:
- TinyMCE(作为“tinymce”字段类型)
- CKEditor(作为“ckeditor”字段类型)
- CRUD(作为“浏览”和“browse_multiple”字段类型)
- 独立,在 /admin/elfinder 路由;
默认使用barryvdh/laravel-elfinder。
这是ImageMagic中有权限配置文件,需要修改PDF相关的读写权限。
# 打开policy.xml文件
sudo nano /etc/ImageMagick-6/policy.xml
# 修改PDF相关权限,由none改为read|write
<policy domain="coder" rights="none" pattern="PDF" />
# 改为
<policy domain="coder" rights="read|write" pattern="PDF" />
错误原因是imagick通过ghostscript解读pdf文件,所以系统中需要安装postscript
官网:Ghostscript
windows系统下,安装完后,通过命令行测试是否能识别gs命令,因为imagick使用gs命令解析pdf文件,
如果无法解析gs命令,在ghostscript安装目录中,把原来的gswin64.exe改为gs.exe即可。
安装目录示例:C:\Program Files\gs\gs10.01.2\bin
linux系列系统正常都能识别gs命令。
报错信息:checking ImageMagick MagickWand API configuration program... configure: error: not found. Please provide a path to MagickWand-config or Wand-config program.
ERROR: `/tmp/pear/temp/imagick/configure --with-imagick' failed
sudo apt-get install libmagickwand-dev libmagickcore-dev
在ubuntu上或docker上安装方法类似,以下是具体步骤。
一般都会先运行pecl
pecl install imagick
但大部分情况下此时会报错:configure: error: not found.
解决:安装imageMagick软件
sudo apt install imagemagick
再次运行,pecl install imagick时,还是有错误提示,不过跟之前不同,
报错信息:checking ImageMagick MagickWand API configuration program... configure: error: not found. Please provide a path to MagickWand-config or Wand-config program.
ERROR: `/tmp/pear/temp/imagick/configure --with-imagick' failed
解决:需要额外安装以下软件
sudo apt-get install libmagickwand-dev libmagickcore-dev
现在运行pecl install imagick,顺利完成。
接下来,如果是docker安装,额外执行以下命令。
docker-php-ext-enable imagick
重启phpdocker即可。
ImageMagick是一个用来创建、编辑、合成图片的软件。
ImageMagick可以读取、转换、写入多种格式的图片,图片切割、颜色替换、各种效果的应用,图片的旋转、组合,文本,直线,多边形,椭圆,曲线等都可以用ImageMagick实现。同时,ImageMagick提供了一个高质量的2D工具包,部分支持SVG。ImageMagick是一套稳定的工具集和开发包,遵守GPL许可协议。